]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/missing_syscall.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 This file is part of systemd.
7 Copyright 2010 Lennart Poettering
8 Copyright 2016 Zbigniew Jędrzejewski-Szmek
11 /* Missing glibc definitions to access certain kernel APIs */
13 #include <sys/types.h>
16 static inline int missing_pivot_root(const char *new_root
, const char *put_old
) {
17 return syscall(__NR_pivot_root
, new_root
, put_old
);
20 # define pivot_root missing_pivot_root
23 /* ======================================================================= */
25 #if !HAVE_MEMFD_CREATE
26 # ifndef __NR_memfd_create
27 # if defined __x86_64__
28 # define __NR_memfd_create 319
29 # elif defined __arm__
30 # define __NR_memfd_create 385
31 # elif defined __aarch64__
32 # define __NR_memfd_create 279
33 # elif defined __s390__
34 # define __NR_memfd_create 350
35 # elif defined _MIPS_SIM
36 # if _MIPS_SIM == _MIPS_SIM_ABI32
37 # define __NR_memfd_create 4354
39 # if _MIPS_SIM == _MIPS_SIM_NABI32
40 # define __NR_memfd_create 6318
42 # if _MIPS_SIM == _MIPS_SIM_ABI64
43 # define __NR_memfd_create 5314
45 # elif defined __i386__
46 # define __NR_memfd_create 356
47 # elif defined __arc__
48 # define __NR_memfd_create 279
50 # warning "__NR_memfd_create unknown for your architecture"
54 static inline int missing_memfd_create(const char *name
, unsigned int flags
) {
55 # ifdef __NR_memfd_create
56 return syscall(__NR_memfd_create
, name
, flags
);
63 # define memfd_create missing_memfd_create
66 /* ======================================================================= */
69 # ifndef __NR_getrandom
70 # if defined __x86_64__
71 # define __NR_getrandom 318
72 # elif defined(__i386__)
73 # define __NR_getrandom 355
74 # elif defined(__arm__)
75 # define __NR_getrandom 384
76 # elif defined(__aarch64__)
77 # define __NR_getrandom 278
78 # elif defined(__ia64__)
79 # define __NR_getrandom 1339
80 # elif defined(__m68k__)
81 # define __NR_getrandom 352
82 # elif defined(__s390x__)
83 # define __NR_getrandom 349
84 # elif defined(__powerpc__)
85 # define __NR_getrandom 359
86 # elif defined _MIPS_SIM
87 # if _MIPS_SIM == _MIPS_SIM_ABI32
88 # define __NR_getrandom 4353
90 # if _MIPS_SIM == _MIPS_SIM_NABI32
91 # define __NR_getrandom 6317
93 # if _MIPS_SIM == _MIPS_SIM_ABI64
94 # define __NR_getrandom 5313
96 # elif defined(__arc__)
97 # define __NR_getrandom 278
99 # warning "__NR_getrandom unknown for your architecture"
103 static inline int missing_getrandom(void *buffer
, size_t count
, unsigned flags
) {
104 # ifdef __NR_getrandom
105 return syscall(__NR_getrandom
, buffer
, count
, flags
);
112 # define getrandom missing_getrandom
115 /* ======================================================================= */
118 static inline pid_t
missing_gettid(void) {
119 return (pid_t
) syscall(__NR_gettid
);
122 # define gettid missing_gettid
125 /* ======================================================================= */
127 #if !HAVE_NAME_TO_HANDLE_AT
128 # ifndef __NR_name_to_handle_at
129 # if defined(__x86_64__)
130 # define __NR_name_to_handle_at 303
131 # elif defined(__i386__)
132 # define __NR_name_to_handle_at 341
133 # elif defined(__arm__)
134 # define __NR_name_to_handle_at 370
135 # elif defined(__powerpc__)
136 # define __NR_name_to_handle_at 345
137 # elif defined(__arc__)
138 # define __NR_name_to_handle_at 264
140 # error "__NR_name_to_handle_at is not defined"
145 unsigned int handle_bytes
;
147 unsigned char f_handle
[0];
150 static inline int missing_name_to_handle_at(int fd
, const char *name
, struct file_handle
*handle
, int *mnt_id
, int flags
) {
151 # ifdef __NR_name_to_handle_at
152 return syscall(__NR_name_to_handle_at
, fd
, name
, handle
, mnt_id
, flags
);
159 # define name_to_handle_at missing_name_to_handle_at
162 /* ======================================================================= */
166 # if defined(__x86_64__)
167 # define __NR_setns 308
168 # elif defined(__i386__)
169 # define __NR_setns 346
170 # elif defined(__arc__)
171 # define __NR_setns 268
173 # error "__NR_setns is not defined"
177 static inline int missing_setns(int fd
, int nstype
) {
179 return syscall(__NR_setns
, fd
, nstype
);
186 # define setns missing_setns
189 /* ======================================================================= */
191 static inline pid_t
raw_getpid(void) {
192 #if defined(__alpha__)
193 return (pid_t
) syscall(__NR_getxpid
);
195 return (pid_t
) syscall(__NR_getpid
);
199 /* ======================================================================= */
202 # ifndef __NR_renameat2
203 # if defined __x86_64__
204 # define __NR_renameat2 316
205 # elif defined __arm__
206 # define __NR_renameat2 382
207 # elif defined __aarch64__
208 # define __NR_renameat2 276
209 # elif defined _MIPS_SIM
210 # if _MIPS_SIM == _MIPS_SIM_ABI32
211 # define __NR_renameat2 4351
213 # if _MIPS_SIM == _MIPS_SIM_NABI32
214 # define __NR_renameat2 6315
216 # if _MIPS_SIM == _MIPS_SIM_ABI64
217 # define __NR_renameat2 5311
219 # elif defined __i386__
220 # define __NR_renameat2 353
221 # elif defined __powerpc64__
222 # define __NR_renameat2 357
223 # elif defined __s390__ || defined __s390x__
224 # define __NR_renameat2 347
225 # elif defined __arc__
226 # define __NR_renameat2 276
228 # warning "__NR_renameat2 unknown for your architecture"
232 static inline int missing_renameat2(int oldfd
, const char *oldname
, int newfd
, const char *newname
, unsigned flags
) {
233 # ifdef __NR_renameat2
234 return syscall(__NR_renameat2
, oldfd
, oldname
, newfd
, newname
, flags
);
241 # define renameat2 missing_renameat2
244 /* ======================================================================= */
247 static inline int missing_kcmp(pid_t pid1
, pid_t pid2
, int type
, unsigned long idx1
, unsigned long idx2
) {
249 return syscall(__NR_kcmp
, pid1
, pid2
, type
, idx1
, idx2
);
256 # define kcmp missing_kcmp
259 /* ======================================================================= */
262 static inline long missing_keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
, unsigned long arg4
,unsigned long arg5
) {
264 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
270 # define keyctl missing_keyctl
273 static inline key_serial_t
missing_add_key(const char *type
, const char *description
, const void *payload
, size_t plen
, key_serial_t ringid
) {
275 return syscall(__NR_add_key
, type
, description
, payload
, plen
, ringid
);
281 # define add_key missing_add_key
284 static inline key_serial_t
missing_request_key(const char *type
, const char *description
, const char * callout_info
, key_serial_t destringid
) {
285 # ifdef __NR_request_key
286 return syscall(__NR_request_key
, type
, description
, callout_info
, destringid
);
292 # define request_key missing_request_key
296 /* ======================================================================= */
298 #if !HAVE_COPY_FILE_RANGE
299 # ifndef __NR_copy_file_range
300 # if defined(__x86_64__)
301 # define __NR_copy_file_range 326
302 # elif defined(__i386__)
303 # define __NR_copy_file_range 377
304 # elif defined __s390__
305 # define __NR_copy_file_range 375
306 # elif defined __arm__
307 # define __NR_copy_file_range 391
308 # elif defined __aarch64__
309 # define __NR_copy_file_range 285
310 # elif defined __powerpc__
311 # define __NR_copy_file_range 379
312 # elif defined __arc__
313 # define __NR_copy_file_range 285
315 # warning "__NR_copy_file_range not defined for your architecture"
319 static inline ssize_t
missing_copy_file_range(int fd_in
, loff_t
*off_in
,
320 int fd_out
, loff_t
*off_out
,
322 unsigned int flags
) {
323 # ifdef __NR_copy_file_range
324 return syscall(__NR_copy_file_range
, fd_in
, off_in
, fd_out
, off_out
, len
, flags
);
331 # define copy_file_range missing_copy_file_range
334 /* ======================================================================= */
338 # if defined __i386__
339 # define __NR_bpf 357
340 # elif defined __x86_64__
341 # define __NR_bpf 321
342 # elif defined __aarch64__
343 # define __NR_bpf 280
344 # elif defined __arm__
345 # define __NR_bpf 386
346 # elif defined __sparc__
347 # define __NR_bpf 349
348 # elif defined __s390__
349 # define __NR_bpf 351
350 # elif defined __tilegx__
351 # define __NR_bpf 280
353 # warning "__NR_bpf not defined for your architecture"
359 static inline int missing_bpf(int cmd
, union bpf_attr
*attr
, size_t size
) {
361 return (int) syscall(__NR_bpf
, cmd
, attr
, size
);
368 # define bpf missing_bpf
371 /* ======================================================================= */
373 #ifndef __IGNORE_pkey_mprotect
374 # ifndef __NR_pkey_mprotect
375 # if defined __i386__
376 # define __NR_pkey_mprotect 380
377 # elif defined __x86_64__
378 # define __NR_pkey_mprotect 329
379 # elif defined __arm__
380 # define __NR_pkey_mprotect 394
381 # elif defined __aarch64__
382 # define __NR_pkey_mprotect 394
383 # elif defined __powerpc__
384 # define __NR_pkey_mprotect 386
385 # elif defined _MIPS_SIM
386 # if _MIPS_SIM == _MIPS_SIM_ABI32
387 # define __NR_pkey_mprotect 4363
389 # if _MIPS_SIM == _MIPS_SIM_NABI32
390 # define __NR_pkey_mprotect 6327
392 # if _MIPS_SIM == _MIPS_SIM_ABI64
393 # define __NR_pkey_mprotect 5323
396 # warning "__NR_pkey_mprotect not defined for your architecture"
401 /* ======================================================================= */
405 # if defined __aarch64__ || defined __arm__
406 # define __NR_statx 397
407 # elif defined __alpha__
408 # define __NR_statx 522
409 # elif defined __i386__ || defined __powerpc64__
410 # define __NR_statx 383
411 # elif defined __sparc__
412 # define __NR_statx 360
413 # elif defined __x86_64__
414 # define __NR_statx 332
416 # warning "__NR_statx not defined for your architecture"
423 /* This typedef is supposed to be always defined. */
424 typedef struct statx struct_statx
;
427 static inline ssize_t
missing_statx(int dfd
, const char *filename
, unsigned flags
, unsigned int mask
, struct statx
*buffer
) {
429 return syscall(__NR_statx
, dfd
, filename
, flags
, mask
, buffer
);
436 # define statx missing_statx