]>
git.proxmox.com Git - systemd.git/blob - src/basic/missing_syscall.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 /* Missing glibc definitions to access certain kernel APIs */
7 #include <sys/syscall.h>
12 #include <asm/sgidefs.h>
15 #include "missing_keyctl.h"
16 #include "missing_stat.h"
19 #ifndef KCMP_FILE /* 3f4994cfc15f38a3159c6e3a4b3ab2e1481a6b02 (3.19) */
24 static inline int missing_pivot_root(const char *new_root
, const char *put_old
) {
25 return syscall(__NR_pivot_root
, new_root
, put_old
);
28 # define pivot_root missing_pivot_root
31 /* ======================================================================= */
33 #if !HAVE_MEMFD_CREATE
34 # ifndef __NR_memfd_create
35 # if defined __x86_64__
36 # define __NR_memfd_create 319
37 # elif defined __arm__
38 # define __NR_memfd_create 385
39 # elif defined __aarch64__
40 # define __NR_memfd_create 279
41 # elif defined __s390__
42 # define __NR_memfd_create 350
43 # elif defined _MIPS_SIM
44 # if _MIPS_SIM == _MIPS_SIM_ABI32
45 # define __NR_memfd_create 4354
47 # if _MIPS_SIM == _MIPS_SIM_NABI32
48 # define __NR_memfd_create 6318
50 # if _MIPS_SIM == _MIPS_SIM_ABI64
51 # define __NR_memfd_create 5314
53 # elif defined __i386__
54 # define __NR_memfd_create 356
55 # elif defined __arc__
56 # define __NR_memfd_create 279
58 # warning "__NR_memfd_create unknown for your architecture"
62 static inline int missing_memfd_create(const char *name
, unsigned int flags
) {
63 # ifdef __NR_memfd_create
64 return syscall(__NR_memfd_create
, name
, flags
);
71 # define memfd_create missing_memfd_create
74 /* ======================================================================= */
77 # ifndef __NR_getrandom
78 # if defined __x86_64__
79 # define __NR_getrandom 318
80 # elif defined(__i386__)
81 # define __NR_getrandom 355
82 # elif defined(__arm__)
83 # define __NR_getrandom 384
84 # elif defined(__aarch64__)
85 # define __NR_getrandom 278
86 # elif defined(__ia64__)
87 # define __NR_getrandom 1339
88 # elif defined(__m68k__)
89 # define __NR_getrandom 352
90 # elif defined(__s390x__)
91 # define __NR_getrandom 349
92 # elif defined(__powerpc__)
93 # define __NR_getrandom 359
94 # elif defined _MIPS_SIM
95 # if _MIPS_SIM == _MIPS_SIM_ABI32
96 # define __NR_getrandom 4353
98 # if _MIPS_SIM == _MIPS_SIM_NABI32
99 # define __NR_getrandom 6317
101 # if _MIPS_SIM == _MIPS_SIM_ABI64
102 # define __NR_getrandom 5313
104 # elif defined(__arc__)
105 # define __NR_getrandom 278
107 # warning "__NR_getrandom unknown for your architecture"
111 static inline int missing_getrandom(void *buffer
, size_t count
, unsigned flags
) {
112 # ifdef __NR_getrandom
113 return syscall(__NR_getrandom
, buffer
, count
, flags
);
120 # define getrandom missing_getrandom
123 /* ======================================================================= */
126 static inline pid_t
missing_gettid(void) {
127 return (pid_t
) syscall(__NR_gettid
);
130 # define gettid missing_gettid
133 /* ======================================================================= */
135 #if !HAVE_NAME_TO_HANDLE_AT
136 # ifndef __NR_name_to_handle_at
137 # if defined(__x86_64__)
138 # define __NR_name_to_handle_at 303
139 # elif defined(__i386__)
140 # define __NR_name_to_handle_at 341
141 # elif defined(__arm__)
142 # define __NR_name_to_handle_at 370
143 # elif defined(__powerpc__)
144 # define __NR_name_to_handle_at 345
145 # elif defined(__arc__)
146 # define __NR_name_to_handle_at 264
148 # error "__NR_name_to_handle_at is not defined"
153 unsigned int handle_bytes
;
155 unsigned char f_handle
[0];
158 static inline int missing_name_to_handle_at(int fd
, const char *name
, struct file_handle
*handle
, int *mnt_id
, int flags
) {
159 # ifdef __NR_name_to_handle_at
160 return syscall(__NR_name_to_handle_at
, fd
, name
, handle
, mnt_id
, flags
);
167 # define name_to_handle_at missing_name_to_handle_at
170 /* ======================================================================= */
174 # if defined(__x86_64__)
175 # define __NR_setns 308
176 # elif defined(__i386__)
177 # define __NR_setns 346
178 # elif defined(__arc__)
179 # define __NR_setns 268
181 # error "__NR_setns is not defined"
185 static inline int missing_setns(int fd
, int nstype
) {
187 return syscall(__NR_setns
, fd
, nstype
);
194 # define setns missing_setns
197 /* ======================================================================= */
199 static inline pid_t
raw_getpid(void) {
200 #if defined(__alpha__)
201 return (pid_t
) syscall(__NR_getxpid
);
203 return (pid_t
) syscall(__NR_getpid
);
207 /* ======================================================================= */
210 # ifndef __NR_renameat2
211 # if defined __x86_64__
212 # define __NR_renameat2 316
213 # elif defined __arm__
214 # define __NR_renameat2 382
215 # elif defined __aarch64__
216 # define __NR_renameat2 276
217 # elif defined _MIPS_SIM
218 # if _MIPS_SIM == _MIPS_SIM_ABI32
219 # define __NR_renameat2 4351
221 # if _MIPS_SIM == _MIPS_SIM_NABI32
222 # define __NR_renameat2 6315
224 # if _MIPS_SIM == _MIPS_SIM_ABI64
225 # define __NR_renameat2 5311
227 # elif defined __i386__
228 # define __NR_renameat2 353
229 # elif defined __powerpc64__
230 # define __NR_renameat2 357
231 # elif defined __s390__ || defined __s390x__
232 # define __NR_renameat2 347
233 # elif defined __arc__
234 # define __NR_renameat2 276
236 # warning "__NR_renameat2 unknown for your architecture"
240 static inline int missing_renameat2(int oldfd
, const char *oldname
, int newfd
, const char *newname
, unsigned flags
) {
241 # ifdef __NR_renameat2
242 return syscall(__NR_renameat2
, oldfd
, oldname
, newfd
, newname
, flags
);
249 # define renameat2 missing_renameat2
252 /* ======================================================================= */
255 static inline int missing_kcmp(pid_t pid1
, pid_t pid2
, int type
, unsigned long idx1
, unsigned long idx2
) {
257 return syscall(__NR_kcmp
, pid1
, pid2
, type
, idx1
, idx2
);
264 # define kcmp missing_kcmp
267 /* ======================================================================= */
270 static inline long missing_keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
, unsigned long arg4
, unsigned long arg5
) {
272 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
278 # define keyctl missing_keyctl
281 static inline key_serial_t
missing_add_key(const char *type
, const char *description
, const void *payload
, size_t plen
, key_serial_t ringid
) {
283 return syscall(__NR_add_key
, type
, description
, payload
, plen
, ringid
);
289 # define add_key missing_add_key
292 static inline key_serial_t
missing_request_key(const char *type
, const char *description
, const char * callout_info
, key_serial_t destringid
) {
293 # ifdef __NR_request_key
294 return syscall(__NR_request_key
, type
, description
, callout_info
, destringid
);
300 # define request_key missing_request_key
304 /* ======================================================================= */
306 #if !HAVE_COPY_FILE_RANGE
307 # ifndef __NR_copy_file_range
308 # if defined(__x86_64__)
309 # define __NR_copy_file_range 326
310 # elif defined(__i386__)
311 # define __NR_copy_file_range 377
312 # elif defined __s390__
313 # define __NR_copy_file_range 375
314 # elif defined __arm__
315 # define __NR_copy_file_range 391
316 # elif defined __aarch64__
317 # define __NR_copy_file_range 285
318 # elif defined __powerpc__
319 # define __NR_copy_file_range 379
320 # elif defined __arc__
321 # define __NR_copy_file_range 285
323 # warning "__NR_copy_file_range not defined for your architecture"
327 static inline ssize_t
missing_copy_file_range(int fd_in
, loff_t
*off_in
,
328 int fd_out
, loff_t
*off_out
,
330 unsigned int flags
) {
331 # ifdef __NR_copy_file_range
332 return syscall(__NR_copy_file_range
, fd_in
, off_in
, fd_out
, off_out
, len
, flags
);
339 # define copy_file_range missing_copy_file_range
342 /* ======================================================================= */
346 # if defined __i386__
347 # define __NR_bpf 357
348 # elif defined __x86_64__
349 # define __NR_bpf 321
350 # elif defined __aarch64__
351 # define __NR_bpf 280
352 # elif defined __arm__
353 # define __NR_bpf 386
354 # elif defined __sparc__
355 # define __NR_bpf 349
356 # elif defined __s390__
357 # define __NR_bpf 351
358 # elif defined __tilegx__
359 # define __NR_bpf 280
361 # warning "__NR_bpf not defined for your architecture"
367 static inline int missing_bpf(int cmd
, union bpf_attr
*attr
, size_t size
) {
369 return (int) syscall(__NR_bpf
, cmd
, attr
, size
);
376 # define bpf missing_bpf
379 /* ======================================================================= */
381 #ifndef __IGNORE_pkey_mprotect
382 # ifndef __NR_pkey_mprotect
383 # if defined __i386__
384 # define __NR_pkey_mprotect 380
385 # elif defined __x86_64__
386 # define __NR_pkey_mprotect 329
387 # elif defined __arm__
388 # define __NR_pkey_mprotect 394
389 # elif defined __aarch64__
390 # define __NR_pkey_mprotect 394
391 # elif defined __powerpc__
392 # define __NR_pkey_mprotect 386
393 # elif defined _MIPS_SIM
394 # if _MIPS_SIM == _MIPS_SIM_ABI32
395 # define __NR_pkey_mprotect 4363
397 # if _MIPS_SIM == _MIPS_SIM_NABI32
398 # define __NR_pkey_mprotect 6327
400 # if _MIPS_SIM == _MIPS_SIM_ABI64
401 # define __NR_pkey_mprotect 5323
404 # warning "__NR_pkey_mprotect not defined for your architecture"
409 /* ======================================================================= */
413 # if defined __aarch64__ || defined __arm__
414 # define __NR_statx 397
415 # elif defined __alpha__
416 # define __NR_statx 522
417 # elif defined __i386__ || defined __powerpc64__
418 # define __NR_statx 383
419 # elif defined __sparc__
420 # define __NR_statx 360
421 # elif defined __x86_64__
422 # define __NR_statx 332
424 # warning "__NR_statx not defined for your architecture"
431 /* This typedef is supposed to be always defined. */
432 typedef struct statx struct_statx
;
435 static inline ssize_t
missing_statx(int dfd
, const char *filename
, unsigned flags
, unsigned int mask
, struct statx
*buffer
) {
437 return syscall(__NR_statx
, dfd
, filename
, flags
, mask
, buffer
);
444 # define statx missing_statx