1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 /* Missing glibc definitions to access certain kernel APIs */
6 #if 0 /// UNNEEDED by elogind
10 static inline int missing_pivot_root(const char *new_root, const char *put_old) {
11 return syscall(__NR_pivot_root, new_root, put_old);
14 # define pivot_root missing_pivot_root
18 /* ======================================================================= */
20 #if !HAVE_MEMFD_CREATE
21 # ifndef __NR_memfd_create
22 # if defined __x86_64__
23 # define __NR_memfd_create 319
24 # elif defined __arm__
25 # define __NR_memfd_create 385
26 # elif defined __aarch64__
27 # define __NR_memfd_create 279
28 # elif defined __s390__
29 # define __NR_memfd_create 350
30 # elif defined _MIPS_SIM
31 # if _MIPS_SIM == _MIPS_SIM_ABI32
32 # define __NR_memfd_create 4354
34 # if _MIPS_SIM == _MIPS_SIM_NABI32
35 # define __NR_memfd_create 6318
37 # if _MIPS_SIM == _MIPS_SIM_ABI64
38 # define __NR_memfd_create 5314
40 # elif defined __i386__
41 # define __NR_memfd_create 356
42 # elif defined __arc__
43 # define __NR_memfd_create 279
45 # warning "__NR_memfd_create unknown for your architecture"
49 static inline int missing_memfd_create(const char *name, unsigned int flags) {
50 # ifdef __NR_memfd_create
51 return syscall(__NR_memfd_create, name, flags);
58 # define memfd_create missing_memfd_create
61 /* ======================================================================= */
64 # ifndef __NR_getrandom
65 # if defined __x86_64__
66 # define __NR_getrandom 318
67 # elif defined(__i386__)
68 # define __NR_getrandom 355
69 # elif defined(__arm__)
70 # define __NR_getrandom 384
71 # elif defined(__aarch64__)
72 # define __NR_getrandom 278
73 # elif defined(__ia64__)
74 # define __NR_getrandom 1339
75 # elif defined(__m68k__)
76 # define __NR_getrandom 352
77 # elif defined(__s390x__)
78 # define __NR_getrandom 349
79 # elif defined(__powerpc__)
80 # define __NR_getrandom 359
81 # elif defined _MIPS_SIM
82 # if _MIPS_SIM == _MIPS_SIM_ABI32
83 # define __NR_getrandom 4353
85 # if _MIPS_SIM == _MIPS_SIM_NABI32
86 # define __NR_getrandom 6317
88 # if _MIPS_SIM == _MIPS_SIM_ABI64
89 # define __NR_getrandom 5313
91 # elif defined(__arc__)
92 # define __NR_getrandom 278
94 # warning "__NR_getrandom unknown for your architecture"
98 static inline int missing_getrandom(void *buffer, size_t count, unsigned flags) {
99 # ifdef __NR_getrandom
100 return syscall(__NR_getrandom, buffer, count, flags);
107 # define getrandom missing_getrandom
110 /* ======================================================================= */
113 static inline pid_t missing_gettid(void) {
114 return (pid_t) syscall(__NR_gettid);
117 # define gettid missing_gettid
120 /* ======================================================================= */
122 #if !HAVE_NAME_TO_HANDLE_AT
123 # ifndef __NR_name_to_handle_at
124 # if defined(__x86_64__)
125 # define __NR_name_to_handle_at 303
126 # elif defined(__i386__)
127 # define __NR_name_to_handle_at 341
128 # elif defined(__arm__)
129 # define __NR_name_to_handle_at 370
130 # elif defined(__powerpc__)
131 # define __NR_name_to_handle_at 345
132 # elif defined(__arc__)
133 # define __NR_name_to_handle_at 264
135 # error "__NR_name_to_handle_at is not defined"
140 unsigned int handle_bytes;
142 unsigned char f_handle[0];
145 static inline int missing_name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
146 # ifdef __NR_name_to_handle_at
147 return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
154 # define name_to_handle_at missing_name_to_handle_at
157 /* ======================================================================= */
161 # if defined(__x86_64__)
162 # define __NR_setns 308
163 # elif defined(__i386__)
164 # define __NR_setns 346
165 # elif defined(__arc__)
166 # define __NR_setns 268
168 # error "__NR_setns is not defined"
172 static inline int missing_setns(int fd, int nstype) {
174 return syscall(__NR_setns, fd, nstype);
181 # define setns missing_setns
184 /* ======================================================================= */
186 static inline pid_t raw_getpid(void) {
187 #if defined(__alpha__)
188 return (pid_t) syscall(__NR_getxpid);
190 return (pid_t) syscall(__NR_getpid);
194 /* ======================================================================= */
197 # ifndef __NR_renameat2
198 # if defined __x86_64__
199 # define __NR_renameat2 316
200 # elif defined __arm__
201 # define __NR_renameat2 382
202 # elif defined __aarch64__
203 # define __NR_renameat2 276
204 # elif defined _MIPS_SIM
205 # if _MIPS_SIM == _MIPS_SIM_ABI32
206 # define __NR_renameat2 4351
208 # if _MIPS_SIM == _MIPS_SIM_NABI32
209 # define __NR_renameat2 6315
211 # if _MIPS_SIM == _MIPS_SIM_ABI64
212 # define __NR_renameat2 5311
214 # elif defined __i386__
215 # define __NR_renameat2 353
216 # elif defined __powerpc64__
217 # define __NR_renameat2 357
218 # elif defined __s390__ || defined __s390x__
219 # define __NR_renameat2 347
220 # elif defined __arc__
221 # define __NR_renameat2 276
223 # warning "__NR_renameat2 unknown for your architecture"
227 static inline int missing_renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
228 # ifdef __NR_renameat2
229 return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
236 # define renameat2 missing_renameat2
239 /* ======================================================================= */
242 static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
244 return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
251 # define kcmp missing_kcmp
254 /* ======================================================================= */
257 static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4,unsigned long arg5) {
259 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
265 # define keyctl missing_keyctl
268 static inline key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
270 return syscall(__NR_add_key, type, description, payload, plen, ringid);
276 # define add_key missing_add_key
279 static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
280 # ifdef __NR_request_key
281 return syscall(__NR_request_key, type, description, callout_info, destringid);
287 # define request_key missing_request_key
291 /* ======================================================================= */
293 #if !HAVE_COPY_FILE_RANGE
294 # ifndef __NR_copy_file_range
295 # if defined(__x86_64__)
296 # define __NR_copy_file_range 326
297 # elif defined(__i386__)
298 # define __NR_copy_file_range 377
299 # elif defined __s390__
300 # define __NR_copy_file_range 375
301 # elif defined __arm__
302 # define __NR_copy_file_range 391
303 # elif defined __aarch64__
304 # define __NR_copy_file_range 285
305 # elif defined __powerpc__
306 # define __NR_copy_file_range 379
307 # elif defined __arc__
308 # define __NR_copy_file_range 285
310 # warning "__NR_copy_file_range not defined for your architecture"
314 static inline ssize_t missing_copy_file_range(int fd_in, loff_t *off_in,
315 int fd_out, loff_t *off_out,
317 unsigned int flags) {
318 # ifdef __NR_copy_file_range
319 return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags);
326 # define copy_file_range missing_copy_file_range
329 /* ======================================================================= */
333 # if defined __i386__
334 # define __NR_bpf 357
335 # elif defined __x86_64__
336 # define __NR_bpf 321
337 # elif defined __aarch64__
338 # define __NR_bpf 280
339 # elif defined __arm__
340 # define __NR_bpf 386
341 # elif defined __sparc__
342 # define __NR_bpf 349
343 # elif defined __s390__
344 # define __NR_bpf 351
345 # elif defined __tilegx__
346 # define __NR_bpf 280
348 # warning "__NR_bpf not defined for your architecture"
354 static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) {
356 return (int) syscall(__NR_bpf, cmd, attr, size);
363 # define bpf missing_bpf
366 /* ======================================================================= */
368 #ifndef __IGNORE_pkey_mprotect
369 # ifndef __NR_pkey_mprotect
370 # if defined __i386__
371 # define __NR_pkey_mprotect 380
372 # elif defined __x86_64__
373 # define __NR_pkey_mprotect 329
374 # elif defined __arm__
375 # define __NR_pkey_mprotect 394
376 # elif defined __aarch64__
377 # define __NR_pkey_mprotect 394
378 # elif defined __powerpc__
379 # define __NR_pkey_mprotect 386
380 # elif defined _MIPS_SIM
381 # if _MIPS_SIM == _MIPS_SIM_ABI32
382 # define __NR_pkey_mprotect 4363
384 # if _MIPS_SIM == _MIPS_SIM_NABI32
385 # define __NR_pkey_mprotect 6327
387 # if _MIPS_SIM == _MIPS_SIM_ABI64
388 # define __NR_pkey_mprotect 5323
391 # warning "__NR_pkey_mprotect not defined for your architecture"
396 /* ======================================================================= */
400 # if defined __aarch64__ || defined __arm__
401 # define __NR_statx 397
402 # elif defined __alpha__
403 # define __NR_statx 522
404 # elif defined __i386__ || defined __powerpc64__
405 # define __NR_statx 383
406 # elif defined __sparc__
407 # define __NR_statx 360
408 # elif defined __x86_64__
409 # define __NR_statx 332
411 # warning "__NR_statx not defined for your architecture"
418 /* This typedef is supposed to be always defined. */
419 typedef struct statx struct_statx;
422 static inline ssize_t missing_statx(int dfd, const char *filename, unsigned flags, unsigned int mask, struct statx *buffer) {
424 return syscall(__NR_statx, dfd, filename, flags, mask, buffer);
431 # define statx missing_statx