]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/missing_syscall.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 /* Missing glibc definitions to access certain kernel APIs */
9 #include <sys/syscall.h>
10 #include <sys/types.h>
15 #include <asm/sgidefs.h>
18 #include "missing_keyctl.h"
19 #include "missing_stat.h"
22 #ifndef KCMP_FILE /* 3f4994cfc15f38a3159c6e3a4b3ab2e1481a6b02 (3.19) */
27 static inline int missing_pivot_root(const char *new_root
, const char *put_old
) {
28 return syscall(__NR_pivot_root
, new_root
, put_old
);
31 # define pivot_root missing_pivot_root
34 /* ======================================================================= */
36 #if !HAVE_MEMFD_CREATE
37 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
38 # if ! (defined __NR_memfd_create && __NR_memfd_create >= 0)
39 # if defined __NR_memfd_create
40 # undef __NR_memfd_create
42 # if defined __x86_64__
43 # define __NR_memfd_create 319
44 # elif defined __arm__
45 # define __NR_memfd_create 385
46 # elif defined __aarch64__
47 # define __NR_memfd_create 279
48 # elif defined __s390__
49 # define __NR_memfd_create 350
50 # elif defined _MIPS_SIM
51 # if _MIPS_SIM == _MIPS_SIM_ABI32
52 # define __NR_memfd_create 4354
54 # if _MIPS_SIM == _MIPS_SIM_NABI32
55 # define __NR_memfd_create 6318
57 # if _MIPS_SIM == _MIPS_SIM_ABI64
58 # define __NR_memfd_create 5314
60 # elif defined __i386__
61 # define __NR_memfd_create 356
62 # elif defined __arc__
63 # define __NR_memfd_create 279
65 # warning "__NR_memfd_create unknown for your architecture"
69 static inline int missing_memfd_create(const char *name
, unsigned int flags
) {
70 # ifdef __NR_memfd_create
71 return syscall(__NR_memfd_create
, name
, flags
);
78 # define memfd_create missing_memfd_create
81 /* ======================================================================= */
84 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
85 # if ! (defined __NR_getrandom && __NR_getrandom >= 0)
86 # if defined __NR_getrandom
87 # undef __NR_getrandom
89 # if defined __x86_64__
90 # define __NR_getrandom 318
91 # elif defined(__i386__)
92 # define __NR_getrandom 355
93 # elif defined(__arm__)
94 # define __NR_getrandom 384
95 # elif defined(__aarch64__)
96 # define __NR_getrandom 278
97 # elif defined(__ia64__)
98 # define __NR_getrandom 1339
99 # elif defined(__m68k__)
100 # define __NR_getrandom 352
101 # elif defined(__s390x__)
102 # define __NR_getrandom 349
103 # elif defined(__powerpc__)
104 # define __NR_getrandom 359
105 # elif defined _MIPS_SIM
106 # if _MIPS_SIM == _MIPS_SIM_ABI32
107 # define __NR_getrandom 4353
109 # if _MIPS_SIM == _MIPS_SIM_NABI32
110 # define __NR_getrandom 6317
112 # if _MIPS_SIM == _MIPS_SIM_ABI64
113 # define __NR_getrandom 5313
115 # elif defined(__arc__)
116 # define __NR_getrandom 278
118 # warning "__NR_getrandom unknown for your architecture"
122 static inline int missing_getrandom(void *buffer
, size_t count
, unsigned flags
) {
123 # ifdef __NR_getrandom
124 return syscall(__NR_getrandom
, buffer
, count
, flags
);
131 # define getrandom missing_getrandom
134 /* ======================================================================= */
137 static inline pid_t
missing_gettid(void) {
138 return (pid_t
) syscall(__NR_gettid
);
141 # define gettid missing_gettid
144 /* ======================================================================= */
146 #if !HAVE_NAME_TO_HANDLE_AT
147 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
148 # if ! (defined __NR_name_to_handle_at && __NR_name_to_handle_at >= 0)
149 # if defined __NR_name_to_handle_at
150 # undef __NR_name_to_handle_at
152 # if defined(__x86_64__)
153 # define __NR_name_to_handle_at 303
154 # elif defined(__i386__)
155 # define __NR_name_to_handle_at 341
156 # elif defined(__arm__)
157 # define __NR_name_to_handle_at 370
158 # elif defined(__powerpc__)
159 # define __NR_name_to_handle_at 345
160 # elif defined(__arc__)
161 # define __NR_name_to_handle_at 264
163 # error "__NR_name_to_handle_at is not defined"
168 unsigned int handle_bytes
;
170 unsigned char f_handle
[0];
173 static inline int missing_name_to_handle_at(int fd
, const char *name
, struct file_handle
*handle
, int *mnt_id
, int flags
) {
174 # ifdef __NR_name_to_handle_at
175 return syscall(__NR_name_to_handle_at
, fd
, name
, handle
, mnt_id
, flags
);
182 # define name_to_handle_at missing_name_to_handle_at
185 /* ======================================================================= */
188 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
189 # if ! (defined __NR_setns && __NR_setns >= 0)
190 # if defined __NR_setns
193 # if defined(__x86_64__)
194 # define __NR_setns 308
195 # elif defined(__i386__)
196 # define __NR_setns 346
197 # elif defined(__arc__)
198 # define __NR_setns 268
200 # error "__NR_setns is not defined"
204 static inline int missing_setns(int fd
, int nstype
) {
206 return syscall(__NR_setns
, fd
, nstype
);
213 # define setns missing_setns
216 /* ======================================================================= */
218 static inline pid_t
raw_getpid(void) {
219 #if defined(__alpha__)
220 return (pid_t
) syscall(__NR_getxpid
);
222 return (pid_t
) syscall(__NR_getpid
);
226 /* ======================================================================= */
229 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
230 # if ! (defined __NR_renameat2 && __NR_renameat2 >= 0)
231 # if defined __NR_renameat2
232 # undef __NR_renameat2
234 # if defined __x86_64__
235 # define __NR_renameat2 316
236 # elif defined __arm__
237 # define __NR_renameat2 382
238 # elif defined __aarch64__
239 # define __NR_renameat2 276
240 # elif defined _MIPS_SIM
241 # if _MIPS_SIM == _MIPS_SIM_ABI32
242 # define __NR_renameat2 4351
244 # if _MIPS_SIM == _MIPS_SIM_NABI32
245 # define __NR_renameat2 6315
247 # if _MIPS_SIM == _MIPS_SIM_ABI64
248 # define __NR_renameat2 5311
250 # elif defined __i386__
251 # define __NR_renameat2 353
252 # elif defined __powerpc64__
253 # define __NR_renameat2 357
254 # elif defined __s390__ || defined __s390x__
255 # define __NR_renameat2 347
256 # elif defined __arc__
257 # define __NR_renameat2 276
259 # warning "__NR_renameat2 unknown for your architecture"
263 static inline int missing_renameat2(int oldfd
, const char *oldname
, int newfd
, const char *newname
, unsigned flags
) {
264 # ifdef __NR_renameat2
265 return syscall(__NR_renameat2
, oldfd
, oldname
, newfd
, newname
, flags
);
272 # define renameat2 missing_renameat2
275 /* ======================================================================= */
278 static inline int missing_kcmp(pid_t pid1
, pid_t pid2
, int type
, unsigned long idx1
, unsigned long idx2
) {
279 # if defined __NR_kcmp && __NR_kcmp >= 0
280 return syscall(__NR_kcmp
, pid1
, pid2
, type
, idx1
, idx2
);
287 # define kcmp missing_kcmp
290 /* ======================================================================= */
293 static inline long missing_keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
, unsigned long arg4
, unsigned long arg5
) {
294 # if defined __NR_keyctl && __NR_keyctl >= 0
295 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
301 # define keyctl missing_keyctl
304 static inline key_serial_t
missing_add_key(const char *type
, const char *description
, const void *payload
, size_t plen
, key_serial_t ringid
) {
305 # if defined __NR_add_key && __NR_add_key >= 0
306 return syscall(__NR_add_key
, type
, description
, payload
, plen
, ringid
);
312 # define add_key missing_add_key
315 static inline key_serial_t
missing_request_key(const char *type
, const char *description
, const char * callout_info
, key_serial_t destringid
) {
316 # if defined __NR_request_key && __NR_request_key >= 0
317 return syscall(__NR_request_key
, type
, description
, callout_info
, destringid
);
323 # define request_key missing_request_key
327 /* ======================================================================= */
329 #if !HAVE_COPY_FILE_RANGE
330 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
331 # if ! (defined __NR_copy_file_range && __NR_copy_file_range >= 0)
332 # if defined __NR_copy_file_range
333 # undef __NR_copy_file_range
335 # if defined(__x86_64__)
336 # define __NR_copy_file_range 326
337 # elif defined(__i386__)
338 # define __NR_copy_file_range 377
339 # elif defined __s390__
340 # define __NR_copy_file_range 375
341 # elif defined __arm__
342 # define __NR_copy_file_range 391
343 # elif defined __aarch64__
344 # define __NR_copy_file_range 285
345 # elif defined __powerpc__
346 # define __NR_copy_file_range 379
347 # elif defined __arc__
348 # define __NR_copy_file_range 285
350 # warning "__NR_copy_file_range not defined for your architecture"
354 static inline ssize_t
missing_copy_file_range(int fd_in
, loff_t
*off_in
,
355 int fd_out
, loff_t
*off_out
,
357 unsigned int flags
) {
358 # ifdef __NR_copy_file_range
359 return syscall(__NR_copy_file_range
, fd_in
, off_in
, fd_out
, off_out
, len
, flags
);
366 # define copy_file_range missing_copy_file_range
369 /* ======================================================================= */
372 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
373 # if ! (defined __NR_bpf && __NR_bpf >= 0)
374 # if defined __NR_bpf
377 # if defined __i386__
378 # define __NR_bpf 357
379 # elif defined __x86_64__
380 # define __NR_bpf 321
381 # elif defined __aarch64__
382 # define __NR_bpf 280
383 # elif defined __arm__
384 # define __NR_bpf 386
385 # elif defined __sparc__
386 # define __NR_bpf 349
387 # elif defined __s390__
388 # define __NR_bpf 351
389 # elif defined __tilegx__
390 # define __NR_bpf 280
392 # warning "__NR_bpf not defined for your architecture"
398 static inline int missing_bpf(int cmd
, union bpf_attr
*attr
, size_t size
) {
400 return (int) syscall(__NR_bpf
, cmd
, attr
, size
);
407 # define bpf missing_bpf
410 /* ======================================================================= */
412 #ifndef __IGNORE_pkey_mprotect
413 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
414 # if ! (defined __NR_pkey_mprotect && __NR_pkey_mprotect >= 0)
415 # if defined __NR_pkey_mprotect
416 # undef __NR_pkey_mprotect
418 # if defined __i386__
419 # define __NR_pkey_mprotect 380
420 # elif defined __x86_64__
421 # define __NR_pkey_mprotect 329
422 # elif defined __arm__
423 # define __NR_pkey_mprotect 394
424 # elif defined __aarch64__
425 # define __NR_pkey_mprotect 394
426 # elif defined __powerpc__
427 # define __NR_pkey_mprotect 386
428 # elif defined __s390__
429 # define __NR_pkey_mprotect 384
430 # elif defined _MIPS_SIM
431 # if _MIPS_SIM == _MIPS_SIM_ABI32
432 # define __NR_pkey_mprotect 4363
434 # if _MIPS_SIM == _MIPS_SIM_NABI32
435 # define __NR_pkey_mprotect 6327
437 # if _MIPS_SIM == _MIPS_SIM_ABI64
438 # define __NR_pkey_mprotect 5323
441 # warning "__NR_pkey_mprotect not defined for your architecture"
446 /* ======================================================================= */
449 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
450 # if ! (defined __NR_statx && __NR_statx >= 0)
451 # if defined __NR_statx
454 # if defined __aarch64__ || defined __arm__
455 # define __NR_statx 397
456 # elif defined __alpha__
457 # define __NR_statx 522
458 # elif defined __i386__ || defined __powerpc64__
459 # define __NR_statx 383
460 # elif defined __sparc__
461 # define __NR_statx 360
462 # elif defined __x86_64__
463 # define __NR_statx 332
465 # warning "__NR_statx not defined for your architecture"
472 /* This typedef is supposed to be always defined. */
473 typedef struct statx struct_statx
;
476 static inline ssize_t
missing_statx(int dfd
, const char *filename
, unsigned flags
, unsigned int mask
, struct statx
*buffer
) {
478 return syscall(__NR_statx
, dfd
, filename
, flags
, mask
, buffer
);
485 # define statx missing_statx
488 #if !HAVE_SET_MEMPOLICY
498 static inline long missing_set_mempolicy(int mode
, const unsigned long *nodemask
,
499 unsigned long maxnode
) {
501 # if defined __NR_set_mempolicy && __NR_set_mempolicy >= 0
502 i
= syscall(__NR_set_mempolicy
, mode
, nodemask
, maxnode
);
510 # define set_mempolicy missing_set_mempolicy
513 #if !HAVE_GET_MEMPOLICY
514 static inline long missing_get_mempolicy(int *mode
, unsigned long *nodemask
,
515 unsigned long maxnode
, void *addr
,
516 unsigned long flags
) {
518 # ifdef __NR_get_mempolicy
519 i
= syscall(__NR_get_mempolicy
, mode
, nodemask
, maxnode
, addr
, flags
);
527 #define get_mempolicy missing_get_mempolicy
531 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
532 # if ! (defined __NR_pidfd_open && __NR_pidfd_open >= 0)
533 # if defined __NR_pidfd_open
534 # undef __NR_pidfd_open
536 # define __NR_pidfd_open 434
538 static inline int pidfd_open(pid_t pid
, unsigned flags
) {
539 #ifdef __NR_pidfd_open
540 return syscall(__NR_pidfd_open
, pid
, flags
);
548 #if !HAVE_PIDFD_SEND_SIGNAL
549 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
550 # if ! (defined __NR_pidfd_send_signal && __NR_pidfd_send_signal >= 0)
551 # if defined __NR_pidfd_send_signal
552 # undef __NR_pidfd_send_signal
554 # define __NR_pidfd_send_signal 424
556 static inline int pidfd_send_signal(int fd
, int sig
, siginfo_t
*info
, unsigned flags
) {
557 #ifdef __NR_pidfd_open
558 return syscall(__NR_pidfd_send_signal
, fd
, sig
, info
, flags
);
566 #if !HAVE_RT_SIGQUEUEINFO
567 static inline int rt_sigqueueinfo(pid_t tgid
, int sig
, siginfo_t
*info
) {
568 return syscall(__NR_rt_sigqueueinfo
, tgid
, sig
, info
);