]>
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 */
8 #include <sys/syscall.h>
13 #include <asm/sgidefs.h>
16 #include "missing_keyctl.h"
17 #include "missing_stat.h"
20 #ifndef KCMP_FILE /* 3f4994cfc15f38a3159c6e3a4b3ab2e1481a6b02 (3.19) */
25 static inline int missing_pivot_root(const char *new_root
, const char *put_old
) {
26 return syscall(__NR_pivot_root
, new_root
, put_old
);
29 # define pivot_root missing_pivot_root
32 /* ======================================================================= */
34 #if !HAVE_MEMFD_CREATE
35 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
36 # if ! (defined __NR_memfd_create && __NR_memfd_create > 0)
37 # if defined __NR_memfd_create
38 # undef __NR_memfd_create
40 # if defined __x86_64__
41 # define __NR_memfd_create 319
42 # elif defined __arm__
43 # define __NR_memfd_create 385
44 # elif defined __aarch64__
45 # define __NR_memfd_create 279
46 # elif defined __s390__
47 # define __NR_memfd_create 350
48 # elif defined _MIPS_SIM
49 # if _MIPS_SIM == _MIPS_SIM_ABI32
50 # define __NR_memfd_create 4354
52 # if _MIPS_SIM == _MIPS_SIM_NABI32
53 # define __NR_memfd_create 6318
55 # if _MIPS_SIM == _MIPS_SIM_ABI64
56 # define __NR_memfd_create 5314
58 # elif defined __i386__
59 # define __NR_memfd_create 356
60 # elif defined __arc__
61 # define __NR_memfd_create 279
63 # warning "__NR_memfd_create unknown for your architecture"
67 static inline int missing_memfd_create(const char *name
, unsigned int flags
) {
68 # ifdef __NR_memfd_create
69 return syscall(__NR_memfd_create
, name
, flags
);
76 # define memfd_create missing_memfd_create
79 /* ======================================================================= */
82 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
83 # if ! (defined __NR_getrandom && __NR_getrandom > 0)
84 # if defined __NR_getrandom
85 # undef __NR_getrandom
87 # if defined __x86_64__
88 # define __NR_getrandom 318
89 # elif defined(__i386__)
90 # define __NR_getrandom 355
91 # elif defined(__arm__)
92 # define __NR_getrandom 384
93 # elif defined(__aarch64__)
94 # define __NR_getrandom 278
95 # elif defined(__ia64__)
96 # define __NR_getrandom 1339
97 # elif defined(__m68k__)
98 # define __NR_getrandom 352
99 # elif defined(__s390x__)
100 # define __NR_getrandom 349
101 # elif defined(__powerpc__)
102 # define __NR_getrandom 359
103 # elif defined _MIPS_SIM
104 # if _MIPS_SIM == _MIPS_SIM_ABI32
105 # define __NR_getrandom 4353
107 # if _MIPS_SIM == _MIPS_SIM_NABI32
108 # define __NR_getrandom 6317
110 # if _MIPS_SIM == _MIPS_SIM_ABI64
111 # define __NR_getrandom 5313
113 # elif defined(__arc__)
114 # define __NR_getrandom 278
116 # warning "__NR_getrandom unknown for your architecture"
120 static inline int missing_getrandom(void *buffer
, size_t count
, unsigned flags
) {
121 # ifdef __NR_getrandom
122 return syscall(__NR_getrandom
, buffer
, count
, flags
);
129 # define getrandom missing_getrandom
132 /* ======================================================================= */
135 static inline pid_t
missing_gettid(void) {
136 return (pid_t
) syscall(__NR_gettid
);
139 # define gettid missing_gettid
142 /* ======================================================================= */
144 #if !HAVE_NAME_TO_HANDLE_AT
145 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
146 # if ! (defined __NR_name_to_handle_at && __NR_name_to_handle_at > 0)
147 # if defined __NR_name_to_handle_at
148 # undef __NR_name_to_handle_at
150 # if defined(__x86_64__)
151 # define __NR_name_to_handle_at 303
152 # elif defined(__i386__)
153 # define __NR_name_to_handle_at 341
154 # elif defined(__arm__)
155 # define __NR_name_to_handle_at 370
156 # elif defined(__powerpc__)
157 # define __NR_name_to_handle_at 345
158 # elif defined(__arc__)
159 # define __NR_name_to_handle_at 264
161 # error "__NR_name_to_handle_at is not defined"
166 unsigned int handle_bytes
;
168 unsigned char f_handle
[0];
171 static inline int missing_name_to_handle_at(int fd
, const char *name
, struct file_handle
*handle
, int *mnt_id
, int flags
) {
172 # ifdef __NR_name_to_handle_at
173 return syscall(__NR_name_to_handle_at
, fd
, name
, handle
, mnt_id
, flags
);
180 # define name_to_handle_at missing_name_to_handle_at
183 /* ======================================================================= */
186 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
187 # if ! (defined __NR_setns && __NR_setns > 0)
188 # if defined __NR_setns
191 # if defined(__x86_64__)
192 # define __NR_setns 308
193 # elif defined(__i386__)
194 # define __NR_setns 346
195 # elif defined(__arc__)
196 # define __NR_setns 268
198 # error "__NR_setns is not defined"
202 static inline int missing_setns(int fd
, int nstype
) {
204 return syscall(__NR_setns
, fd
, nstype
);
211 # define setns missing_setns
214 /* ======================================================================= */
216 static inline pid_t
raw_getpid(void) {
217 #if defined(__alpha__)
218 return (pid_t
) syscall(__NR_getxpid
);
220 return (pid_t
) syscall(__NR_getpid
);
224 /* ======================================================================= */
227 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
228 # if ! (defined __NR_renameat2 && __NR_renameat2 > 0)
229 # if defined __NR_renameat2
230 # undef __NR_renameat2
232 # if defined __x86_64__
233 # define __NR_renameat2 316
234 # elif defined __arm__
235 # define __NR_renameat2 382
236 # elif defined __aarch64__
237 # define __NR_renameat2 276
238 # elif defined _MIPS_SIM
239 # if _MIPS_SIM == _MIPS_SIM_ABI32
240 # define __NR_renameat2 4351
242 # if _MIPS_SIM == _MIPS_SIM_NABI32
243 # define __NR_renameat2 6315
245 # if _MIPS_SIM == _MIPS_SIM_ABI64
246 # define __NR_renameat2 5311
248 # elif defined __i386__
249 # define __NR_renameat2 353
250 # elif defined __powerpc64__
251 # define __NR_renameat2 357
252 # elif defined __s390__ || defined __s390x__
253 # define __NR_renameat2 347
254 # elif defined __arc__
255 # define __NR_renameat2 276
257 # warning "__NR_renameat2 unknown for your architecture"
261 static inline int missing_renameat2(int oldfd
, const char *oldname
, int newfd
, const char *newname
, unsigned flags
) {
262 # ifdef __NR_renameat2
263 return syscall(__NR_renameat2
, oldfd
, oldname
, newfd
, newname
, flags
);
270 # define renameat2 missing_renameat2
273 /* ======================================================================= */
276 static inline int missing_kcmp(pid_t pid1
, pid_t pid2
, int type
, unsigned long idx1
, unsigned long idx2
) {
277 # if defined __NR_kcmp && __NR_kcmp > 0
278 return syscall(__NR_kcmp
, pid1
, pid2
, type
, idx1
, idx2
);
285 # define kcmp missing_kcmp
288 /* ======================================================================= */
291 static inline long missing_keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
, unsigned long arg4
, unsigned long arg5
) {
292 # if defined __NR_keyctl && __NR_keyctl > 0
293 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
299 # define keyctl missing_keyctl
302 static inline key_serial_t
missing_add_key(const char *type
, const char *description
, const void *payload
, size_t plen
, key_serial_t ringid
) {
303 # if defined __NR_add_key && __NR_add_key > 0
304 return syscall(__NR_add_key
, type
, description
, payload
, plen
, ringid
);
310 # define add_key missing_add_key
313 static inline key_serial_t
missing_request_key(const char *type
, const char *description
, const char * callout_info
, key_serial_t destringid
) {
314 # if defined __NR_request_key && __NR_request_key > 0
315 return syscall(__NR_request_key
, type
, description
, callout_info
, destringid
);
321 # define request_key missing_request_key
325 /* ======================================================================= */
327 #if !HAVE_COPY_FILE_RANGE
328 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
329 # if ! (defined __NR_copy_file_range && __NR_copy_file_range > 0)
330 # if defined __NR_copy_file_range
331 # undef __NR_copy_file_range
333 # if defined(__x86_64__)
334 # define __NR_copy_file_range 326
335 # elif defined(__i386__)
336 # define __NR_copy_file_range 377
337 # elif defined __s390__
338 # define __NR_copy_file_range 375
339 # elif defined __arm__
340 # define __NR_copy_file_range 391
341 # elif defined __aarch64__
342 # define __NR_copy_file_range 285
343 # elif defined __powerpc__
344 # define __NR_copy_file_range 379
345 # elif defined __arc__
346 # define __NR_copy_file_range 285
348 # warning "__NR_copy_file_range not defined for your architecture"
352 static inline ssize_t
missing_copy_file_range(int fd_in
, loff_t
*off_in
,
353 int fd_out
, loff_t
*off_out
,
355 unsigned int flags
) {
356 # ifdef __NR_copy_file_range
357 return syscall(__NR_copy_file_range
, fd_in
, off_in
, fd_out
, off_out
, len
, flags
);
364 # define copy_file_range missing_copy_file_range
367 /* ======================================================================= */
370 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
371 # if ! (defined __NR_bpf && __NR_bpf > 0)
372 # if defined __NR_bpf
375 # if defined __i386__
376 # define __NR_bpf 357
377 # elif defined __x86_64__
378 # define __NR_bpf 321
379 # elif defined __aarch64__
380 # define __NR_bpf 280
381 # elif defined __arm__
382 # define __NR_bpf 386
383 # elif defined __sparc__
384 # define __NR_bpf 349
385 # elif defined __s390__
386 # define __NR_bpf 351
387 # elif defined __tilegx__
388 # define __NR_bpf 280
390 # warning "__NR_bpf not defined for your architecture"
396 static inline int missing_bpf(int cmd
, union bpf_attr
*attr
, size_t size
) {
398 return (int) syscall(__NR_bpf
, cmd
, attr
, size
);
405 # define bpf missing_bpf
408 /* ======================================================================= */
410 #ifndef __IGNORE_pkey_mprotect
411 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
412 # if ! (defined __NR_pkey_mprotect && __NR_pkey_mprotect > 0)
413 # if defined __NR_pkey_mprotect
414 # undef __NR_pkey_mprotect
416 # if defined __i386__
417 # define __NR_pkey_mprotect 380
418 # elif defined __x86_64__
419 # define __NR_pkey_mprotect 329
420 # elif defined __arm__
421 # define __NR_pkey_mprotect 394
422 # elif defined __aarch64__
423 # define __NR_pkey_mprotect 394
424 # elif defined __powerpc__
425 # define __NR_pkey_mprotect 386
426 # elif defined __s390__
427 # define __NR_pkey_mprotect 384
428 # elif defined _MIPS_SIM
429 # if _MIPS_SIM == _MIPS_SIM_ABI32
430 # define __NR_pkey_mprotect 4363
432 # if _MIPS_SIM == _MIPS_SIM_NABI32
433 # define __NR_pkey_mprotect 6327
435 # if _MIPS_SIM == _MIPS_SIM_ABI64
436 # define __NR_pkey_mprotect 5323
439 # warning "__NR_pkey_mprotect not defined for your architecture"
444 /* ======================================================================= */
447 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
448 # if ! (defined __NR_statx && __NR_statx > 0)
449 # if defined __NR_statx
452 # if defined __aarch64__ || defined __arm__
453 # define __NR_statx 397
454 # elif defined __alpha__
455 # define __NR_statx 522
456 # elif defined __i386__ || defined __powerpc64__
457 # define __NR_statx 383
458 # elif defined __sparc__
459 # define __NR_statx 360
460 # elif defined __x86_64__
461 # define __NR_statx 332
463 # warning "__NR_statx not defined for your architecture"
470 /* This typedef is supposed to be always defined. */
471 typedef struct statx struct_statx
;
474 static inline ssize_t
missing_statx(int dfd
, const char *filename
, unsigned flags
, unsigned int mask
, struct statx
*buffer
) {
476 return syscall(__NR_statx
, dfd
, filename
, flags
, mask
, buffer
);
483 # define statx missing_statx
486 #if !HAVE_SET_MEMPOLICY
496 static inline long missing_set_mempolicy(int mode
, const unsigned long *nodemask
,
497 unsigned long maxnode
) {
499 # if defined __NR_set_mempolicy && __NR_set_mempolicy > 0
500 i
= syscall(__NR_set_mempolicy
, mode
, nodemask
, maxnode
);
508 # define set_mempolicy missing_set_mempolicy
511 #if !HAVE_GET_MEMPOLICY
512 static inline long missing_get_mempolicy(int *mode
, unsigned long *nodemask
,
513 unsigned long maxnode
, void *addr
,
514 unsigned long flags
) {
516 # ifdef __NR_get_mempolicy
517 i
= syscall(__NR_get_mempolicy
, mode
, nodemask
, maxnode
, addr
, flags
);
525 #define get_mempolicy missing_get_mempolicy