]>
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 "missing_keyctl.h"
9 #include "missing_stat.h"
12 static inline int missing_pivot_root(const char *new_root
, const char *put_old
) {
13 return syscall(__NR_pivot_root
, new_root
, put_old
);
16 # define pivot_root missing_pivot_root
19 /* ======================================================================= */
21 #if !HAVE_MEMFD_CREATE
22 # ifndef __NR_memfd_create
23 # if defined __x86_64__
24 # define __NR_memfd_create 319
25 # elif defined __arm__
26 # define __NR_memfd_create 385
27 # elif defined __aarch64__
28 # define __NR_memfd_create 279
29 # elif defined __s390__
30 # define __NR_memfd_create 350
31 # elif defined _MIPS_SIM
32 # if _MIPS_SIM == _MIPS_SIM_ABI32
33 # define __NR_memfd_create 4354
35 # if _MIPS_SIM == _MIPS_SIM_NABI32
36 # define __NR_memfd_create 6318
38 # if _MIPS_SIM == _MIPS_SIM_ABI64
39 # define __NR_memfd_create 5314
41 # elif defined __i386__
42 # define __NR_memfd_create 356
43 # elif defined __arc__
44 # define __NR_memfd_create 279
46 # warning "__NR_memfd_create unknown for your architecture"
50 static inline int missing_memfd_create(const char *name
, unsigned int flags
) {
51 # ifdef __NR_memfd_create
52 return syscall(__NR_memfd_create
, name
, flags
);
59 # define memfd_create missing_memfd_create
62 /* ======================================================================= */
65 # ifndef __NR_getrandom
66 # if defined __x86_64__
67 # define __NR_getrandom 318
68 # elif defined(__i386__)
69 # define __NR_getrandom 355
70 # elif defined(__arm__)
71 # define __NR_getrandom 384
72 # elif defined(__aarch64__)
73 # define __NR_getrandom 278
74 # elif defined(__ia64__)
75 # define __NR_getrandom 1339
76 # elif defined(__m68k__)
77 # define __NR_getrandom 352
78 # elif defined(__s390x__)
79 # define __NR_getrandom 349
80 # elif defined(__powerpc__)
81 # define __NR_getrandom 359
82 # elif defined _MIPS_SIM
83 # if _MIPS_SIM == _MIPS_SIM_ABI32
84 # define __NR_getrandom 4353
86 # if _MIPS_SIM == _MIPS_SIM_NABI32
87 # define __NR_getrandom 6317
89 # if _MIPS_SIM == _MIPS_SIM_ABI64
90 # define __NR_getrandom 5313
92 # elif defined(__arc__)
93 # define __NR_getrandom 278
95 # warning "__NR_getrandom unknown for your architecture"
99 static inline int missing_getrandom(void *buffer
, size_t count
, unsigned flags
) {
100 # ifdef __NR_getrandom
101 return syscall(__NR_getrandom
, buffer
, count
, flags
);
108 # define getrandom missing_getrandom
111 /* ======================================================================= */
114 static inline pid_t
missing_gettid(void) {
115 return (pid_t
) syscall(__NR_gettid
);
118 # define gettid missing_gettid
121 /* ======================================================================= */
123 #if !HAVE_NAME_TO_HANDLE_AT
124 # ifndef __NR_name_to_handle_at
125 # if defined(__x86_64__)
126 # define __NR_name_to_handle_at 303
127 # elif defined(__i386__)
128 # define __NR_name_to_handle_at 341
129 # elif defined(__arm__)
130 # define __NR_name_to_handle_at 370
131 # elif defined(__powerpc__)
132 # define __NR_name_to_handle_at 345
133 # elif defined(__arc__)
134 # define __NR_name_to_handle_at 264
136 # error "__NR_name_to_handle_at is not defined"
141 unsigned int handle_bytes
;
143 unsigned char f_handle
[0];
146 static inline int missing_name_to_handle_at(int fd
, const char *name
, struct file_handle
*handle
, int *mnt_id
, int flags
) {
147 # ifdef __NR_name_to_handle_at
148 return syscall(__NR_name_to_handle_at
, fd
, name
, handle
, mnt_id
, flags
);
155 # define name_to_handle_at missing_name_to_handle_at
158 /* ======================================================================= */
162 # if defined(__x86_64__)
163 # define __NR_setns 308
164 # elif defined(__i386__)
165 # define __NR_setns 346
166 # elif defined(__arc__)
167 # define __NR_setns 268
169 # error "__NR_setns is not defined"
173 static inline int missing_setns(int fd
, int nstype
) {
175 return syscall(__NR_setns
, fd
, nstype
);
182 # define setns missing_setns
185 /* ======================================================================= */
187 static inline pid_t
raw_getpid(void) {
188 #if defined(__alpha__)
189 return (pid_t
) syscall(__NR_getxpid
);
191 return (pid_t
) syscall(__NR_getpid
);
195 /* ======================================================================= */
198 # ifndef __NR_renameat2
199 # if defined __x86_64__
200 # define __NR_renameat2 316
201 # elif defined __arm__
202 # define __NR_renameat2 382
203 # elif defined __aarch64__
204 # define __NR_renameat2 276
205 # elif defined _MIPS_SIM
206 # if _MIPS_SIM == _MIPS_SIM_ABI32
207 # define __NR_renameat2 4351
209 # if _MIPS_SIM == _MIPS_SIM_NABI32
210 # define __NR_renameat2 6315
212 # if _MIPS_SIM == _MIPS_SIM_ABI64
213 # define __NR_renameat2 5311
215 # elif defined __i386__
216 # define __NR_renameat2 353
217 # elif defined __powerpc64__
218 # define __NR_renameat2 357
219 # elif defined __s390__ || defined __s390x__
220 # define __NR_renameat2 347
221 # elif defined __arc__
222 # define __NR_renameat2 276
224 # warning "__NR_renameat2 unknown for your architecture"
228 static inline int missing_renameat2(int oldfd
, const char *oldname
, int newfd
, const char *newname
, unsigned flags
) {
229 # ifdef __NR_renameat2
230 return syscall(__NR_renameat2
, oldfd
, oldname
, newfd
, newname
, flags
);
237 # define renameat2 missing_renameat2
240 /* ======================================================================= */
243 static inline int missing_kcmp(pid_t pid1
, pid_t pid2
, int type
, unsigned long idx1
, unsigned long idx2
) {
245 return syscall(__NR_kcmp
, pid1
, pid2
, type
, idx1
, idx2
);
252 # define kcmp missing_kcmp
255 /* ======================================================================= */
258 static inline long missing_keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
, unsigned long arg4
,unsigned long arg5
) {
260 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
266 # define keyctl missing_keyctl
269 static inline key_serial_t
missing_add_key(const char *type
, const char *description
, const void *payload
, size_t plen
, key_serial_t ringid
) {
271 return syscall(__NR_add_key
, type
, description
, payload
, plen
, ringid
);
277 # define add_key missing_add_key
280 static inline key_serial_t
missing_request_key(const char *type
, const char *description
, const char * callout_info
, key_serial_t destringid
) {
281 # ifdef __NR_request_key
282 return syscall(__NR_request_key
, type
, description
, callout_info
, destringid
);
288 # define request_key missing_request_key
292 /* ======================================================================= */
294 #if !HAVE_COPY_FILE_RANGE
295 # ifndef __NR_copy_file_range
296 # if defined(__x86_64__)
297 # define __NR_copy_file_range 326
298 # elif defined(__i386__)
299 # define __NR_copy_file_range 377
300 # elif defined __s390__
301 # define __NR_copy_file_range 375
302 # elif defined __arm__
303 # define __NR_copy_file_range 391
304 # elif defined __aarch64__
305 # define __NR_copy_file_range 285
306 # elif defined __powerpc__
307 # define __NR_copy_file_range 379
308 # elif defined __arc__
309 # define __NR_copy_file_range 285
311 # warning "__NR_copy_file_range not defined for your architecture"
315 static inline ssize_t
missing_copy_file_range(int fd_in
, loff_t
*off_in
,
316 int fd_out
, loff_t
*off_out
,
318 unsigned int flags
) {
319 # ifdef __NR_copy_file_range
320 return syscall(__NR_copy_file_range
, fd_in
, off_in
, fd_out
, off_out
, len
, flags
);
327 # define copy_file_range missing_copy_file_range
330 /* ======================================================================= */
334 # if defined __i386__
335 # define __NR_bpf 357
336 # elif defined __x86_64__
337 # define __NR_bpf 321
338 # elif defined __aarch64__
339 # define __NR_bpf 280
340 # elif defined __arm__
341 # define __NR_bpf 386
342 # elif defined __sparc__
343 # define __NR_bpf 349
344 # elif defined __s390__
345 # define __NR_bpf 351
346 # elif defined __tilegx__
347 # define __NR_bpf 280
349 # warning "__NR_bpf not defined for your architecture"
355 static inline int missing_bpf(int cmd
, union bpf_attr
*attr
, size_t size
) {
357 return (int) syscall(__NR_bpf
, cmd
, attr
, size
);
364 # define bpf missing_bpf
367 /* ======================================================================= */
369 #ifndef __IGNORE_pkey_mprotect
370 # ifndef __NR_pkey_mprotect
371 # if defined __i386__
372 # define __NR_pkey_mprotect 380
373 # elif defined __x86_64__
374 # define __NR_pkey_mprotect 329
375 # elif defined __arm__
376 # define __NR_pkey_mprotect 394
377 # elif defined __aarch64__
378 # define __NR_pkey_mprotect 394
379 # elif defined __powerpc__
380 # define __NR_pkey_mprotect 386
381 # elif defined _MIPS_SIM
382 # if _MIPS_SIM == _MIPS_SIM_ABI32
383 # define __NR_pkey_mprotect 4363
385 # if _MIPS_SIM == _MIPS_SIM_NABI32
386 # define __NR_pkey_mprotect 6327
388 # if _MIPS_SIM == _MIPS_SIM_ABI64
389 # define __NR_pkey_mprotect 5323
392 # warning "__NR_pkey_mprotect not defined for your architecture"
397 /* ======================================================================= */
401 # if defined __aarch64__ || defined __arm__
402 # define __NR_statx 397
403 # elif defined __alpha__
404 # define __NR_statx 522
405 # elif defined __i386__ || defined __powerpc64__
406 # define __NR_statx 383
407 # elif defined __sparc__
408 # define __NR_statx 360
409 # elif defined __x86_64__
410 # define __NR_statx 332
412 # warning "__NR_statx not defined for your architecture"
419 /* This typedef is supposed to be always defined. */
420 typedef struct statx struct_statx
;
423 static inline ssize_t
missing_statx(int dfd
, const char *filename
, unsigned flags
, unsigned int mask
, struct statx
*buffer
) {
425 return syscall(__NR_statx
, dfd
, filename
, flags
, mask
, buffer
);
432 # define statx missing_statx