]>
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 # ifndef __NR_memfd_create
36 # if defined __x86_64__
37 # define __NR_memfd_create 319
38 # elif defined __arm__
39 # define __NR_memfd_create 385
40 # elif defined __aarch64__
41 # define __NR_memfd_create 279
42 # elif defined __s390__
43 # define __NR_memfd_create 350
44 # elif defined _MIPS_SIM
45 # if _MIPS_SIM == _MIPS_SIM_ABI32
46 # define __NR_memfd_create 4354
48 # if _MIPS_SIM == _MIPS_SIM_NABI32
49 # define __NR_memfd_create 6318
51 # if _MIPS_SIM == _MIPS_SIM_ABI64
52 # define __NR_memfd_create 5314
54 # elif defined __i386__
55 # define __NR_memfd_create 356
56 # elif defined __arc__
57 # define __NR_memfd_create 279
59 # warning "__NR_memfd_create unknown for your architecture"
63 static inline int missing_memfd_create(const char *name
, unsigned int flags
) {
64 # ifdef __NR_memfd_create
65 return syscall(__NR_memfd_create
, name
, flags
);
72 # define memfd_create missing_memfd_create
75 /* ======================================================================= */
78 # ifndef __NR_getrandom
79 # if defined __x86_64__
80 # define __NR_getrandom 318
81 # elif defined(__i386__)
82 # define __NR_getrandom 355
83 # elif defined(__arm__)
84 # define __NR_getrandom 384
85 # elif defined(__aarch64__)
86 # define __NR_getrandom 278
87 # elif defined(__ia64__)
88 # define __NR_getrandom 1339
89 # elif defined(__m68k__)
90 # define __NR_getrandom 352
91 # elif defined(__s390x__)
92 # define __NR_getrandom 349
93 # elif defined(__powerpc__)
94 # define __NR_getrandom 359
95 # elif defined _MIPS_SIM
96 # if _MIPS_SIM == _MIPS_SIM_ABI32
97 # define __NR_getrandom 4353
99 # if _MIPS_SIM == _MIPS_SIM_NABI32
100 # define __NR_getrandom 6317
102 # if _MIPS_SIM == _MIPS_SIM_ABI64
103 # define __NR_getrandom 5313
105 # elif defined(__arc__)
106 # define __NR_getrandom 278
108 # warning "__NR_getrandom unknown for your architecture"
112 static inline int missing_getrandom(void *buffer
, size_t count
, unsigned flags
) {
113 # ifdef __NR_getrandom
114 return syscall(__NR_getrandom
, buffer
, count
, flags
);
121 # define getrandom missing_getrandom
124 /* ======================================================================= */
127 static inline pid_t
missing_gettid(void) {
128 return (pid_t
) syscall(__NR_gettid
);
131 # define gettid missing_gettid
134 /* ======================================================================= */
136 #if !HAVE_NAME_TO_HANDLE_AT
137 # ifndef __NR_name_to_handle_at
138 # if defined(__x86_64__)
139 # define __NR_name_to_handle_at 303
140 # elif defined(__i386__)
141 # define __NR_name_to_handle_at 341
142 # elif defined(__arm__)
143 # define __NR_name_to_handle_at 370
144 # elif defined(__powerpc__)
145 # define __NR_name_to_handle_at 345
146 # elif defined(__arc__)
147 # define __NR_name_to_handle_at 264
149 # error "__NR_name_to_handle_at is not defined"
154 unsigned int handle_bytes
;
156 unsigned char f_handle
[0];
159 static inline int missing_name_to_handle_at(int fd
, const char *name
, struct file_handle
*handle
, int *mnt_id
, int flags
) {
160 # ifdef __NR_name_to_handle_at
161 return syscall(__NR_name_to_handle_at
, fd
, name
, handle
, mnt_id
, flags
);
168 # define name_to_handle_at missing_name_to_handle_at
171 /* ======================================================================= */
175 # if defined(__x86_64__)
176 # define __NR_setns 308
177 # elif defined(__i386__)
178 # define __NR_setns 346
179 # elif defined(__arc__)
180 # define __NR_setns 268
182 # error "__NR_setns is not defined"
186 static inline int missing_setns(int fd
, int nstype
) {
188 return syscall(__NR_setns
, fd
, nstype
);
195 # define setns missing_setns
198 /* ======================================================================= */
200 static inline pid_t
raw_getpid(void) {
201 #if defined(__alpha__)
202 return (pid_t
) syscall(__NR_getxpid
);
204 return (pid_t
) syscall(__NR_getpid
);
208 /* ======================================================================= */
211 # ifndef __NR_renameat2
212 # if defined __x86_64__
213 # define __NR_renameat2 316
214 # elif defined __arm__
215 # define __NR_renameat2 382
216 # elif defined __aarch64__
217 # define __NR_renameat2 276
218 # elif defined _MIPS_SIM
219 # if _MIPS_SIM == _MIPS_SIM_ABI32
220 # define __NR_renameat2 4351
222 # if _MIPS_SIM == _MIPS_SIM_NABI32
223 # define __NR_renameat2 6315
225 # if _MIPS_SIM == _MIPS_SIM_ABI64
226 # define __NR_renameat2 5311
228 # elif defined __i386__
229 # define __NR_renameat2 353
230 # elif defined __powerpc64__
231 # define __NR_renameat2 357
232 # elif defined __s390__ || defined __s390x__
233 # define __NR_renameat2 347
234 # elif defined __arc__
235 # define __NR_renameat2 276
237 # warning "__NR_renameat2 unknown for your architecture"
241 static inline int missing_renameat2(int oldfd
, const char *oldname
, int newfd
, const char *newname
, unsigned flags
) {
242 # ifdef __NR_renameat2
243 return syscall(__NR_renameat2
, oldfd
, oldname
, newfd
, newname
, flags
);
250 # define renameat2 missing_renameat2
253 /* ======================================================================= */
256 static inline int missing_kcmp(pid_t pid1
, pid_t pid2
, int type
, unsigned long idx1
, unsigned long idx2
) {
258 return syscall(__NR_kcmp
, pid1
, pid2
, type
, idx1
, idx2
);
265 # define kcmp missing_kcmp
268 /* ======================================================================= */
271 static inline long missing_keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
, unsigned long arg4
, unsigned long arg5
) {
273 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
279 # define keyctl missing_keyctl
282 static inline key_serial_t
missing_add_key(const char *type
, const char *description
, const void *payload
, size_t plen
, key_serial_t ringid
) {
284 return syscall(__NR_add_key
, type
, description
, payload
, plen
, ringid
);
290 # define add_key missing_add_key
293 static inline key_serial_t
missing_request_key(const char *type
, const char *description
, const char * callout_info
, key_serial_t destringid
) {
294 # ifdef __NR_request_key
295 return syscall(__NR_request_key
, type
, description
, callout_info
, destringid
);
301 # define request_key missing_request_key
305 /* ======================================================================= */
307 #if !HAVE_COPY_FILE_RANGE
308 # ifndef __NR_copy_file_range
309 # if defined(__x86_64__)
310 # define __NR_copy_file_range 326
311 # elif defined(__i386__)
312 # define __NR_copy_file_range 377
313 # elif defined __s390__
314 # define __NR_copy_file_range 375
315 # elif defined __arm__
316 # define __NR_copy_file_range 391
317 # elif defined __aarch64__
318 # define __NR_copy_file_range 285
319 # elif defined __powerpc__
320 # define __NR_copy_file_range 379
321 # elif defined __arc__
322 # define __NR_copy_file_range 285
324 # warning "__NR_copy_file_range not defined for your architecture"
328 static inline ssize_t
missing_copy_file_range(int fd_in
, loff_t
*off_in
,
329 int fd_out
, loff_t
*off_out
,
331 unsigned int flags
) {
332 # ifdef __NR_copy_file_range
333 return syscall(__NR_copy_file_range
, fd_in
, off_in
, fd_out
, off_out
, len
, flags
);
340 # define copy_file_range missing_copy_file_range
343 /* ======================================================================= */
347 # if defined __i386__
348 # define __NR_bpf 357
349 # elif defined __x86_64__
350 # define __NR_bpf 321
351 # elif defined __aarch64__
352 # define __NR_bpf 280
353 # elif defined __arm__
354 # define __NR_bpf 386
355 # elif defined __sparc__
356 # define __NR_bpf 349
357 # elif defined __s390__
358 # define __NR_bpf 351
359 # elif defined __tilegx__
360 # define __NR_bpf 280
362 # warning "__NR_bpf not defined for your architecture"
368 static inline int missing_bpf(int cmd
, union bpf_attr
*attr
, size_t size
) {
370 return (int) syscall(__NR_bpf
, cmd
, attr
, size
);
377 # define bpf missing_bpf
380 /* ======================================================================= */
382 #ifndef __IGNORE_pkey_mprotect
383 # ifndef __NR_pkey_mprotect
384 # if defined __i386__
385 # define __NR_pkey_mprotect 380
386 # elif defined __x86_64__
387 # define __NR_pkey_mprotect 329
388 # elif defined __arm__
389 # define __NR_pkey_mprotect 394
390 # elif defined __aarch64__
391 # define __NR_pkey_mprotect 394
392 # elif defined __powerpc__
393 # define __NR_pkey_mprotect 386
394 # elif defined _MIPS_SIM
395 # if _MIPS_SIM == _MIPS_SIM_ABI32
396 # define __NR_pkey_mprotect 4363
398 # if _MIPS_SIM == _MIPS_SIM_NABI32
399 # define __NR_pkey_mprotect 6327
401 # if _MIPS_SIM == _MIPS_SIM_ABI64
402 # define __NR_pkey_mprotect 5323
405 # warning "__NR_pkey_mprotect not defined for your architecture"
410 /* ======================================================================= */
414 # if defined __aarch64__ || defined __arm__
415 # define __NR_statx 397
416 # elif defined __alpha__
417 # define __NR_statx 522
418 # elif defined __i386__ || defined __powerpc64__
419 # define __NR_statx 383
420 # elif defined __sparc__
421 # define __NR_statx 360
422 # elif defined __x86_64__
423 # define __NR_statx 332
425 # warning "__NR_statx not defined for your architecture"
432 /* This typedef is supposed to be always defined. */
433 typedef struct statx struct_statx
;
436 static inline ssize_t
missing_statx(int dfd
, const char *filename
, unsigned flags
, unsigned int mask
, struct statx
*buffer
) {
438 return syscall(__NR_statx
, dfd
, filename
, flags
, mask
, buffer
);
445 # define statx missing_statx
448 #if !HAVE_SET_MEMPOLICY
458 static inline long missing_set_mempolicy(int mode
, const unsigned long *nodemask
,
459 unsigned long maxnode
) {
461 # ifdef __NR_set_mempolicy
462 i
= syscall(__NR_set_mempolicy
, mode
, nodemask
, maxnode
);
470 # define set_mempolicy missing_set_mempolicy
474 #if !HAVE_GET_MEMPOLICY
475 static inline long missing_get_mempolicy(int *mode
, unsigned long *nodemask
,
476 unsigned long maxnode
, void *addr
,
477 unsigned long flags
) {
479 # ifdef __NR_get_mempolicy
480 i
= syscall(__NR_get_mempolicy
, mode
, nodemask
, maxnode
, addr
, flags
);
488 #define get_mempolicy missing_get_mempolicy