]>
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
260 /* ======================================================================= */
263 static inline long missing_keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
, unsigned long arg4
,unsigned long arg5
) {
265 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
271 # define keyctl missing_keyctl
274 static inline key_serial_t
missing_add_key(const char *type
, const char *description
, const void *payload
, size_t plen
, key_serial_t ringid
) {
276 return syscall(__NR_add_key
, type
, description
, payload
, plen
, ringid
);
282 # define add_key missing_add_key
285 static inline key_serial_t
missing_request_key(const char *type
, const char *description
, const char * callout_info
, key_serial_t destringid
) {
286 # ifdef __NR_request_key
287 return syscall(__NR_request_key
, type
, description
, callout_info
, destringid
);
293 # define request_key missing_request_key
297 /* ======================================================================= */
299 #if !HAVE_COPY_FILE_RANGE
300 # ifndef __NR_copy_file_range
301 # if defined(__x86_64__)
302 # define __NR_copy_file_range 326
303 # elif defined(__i386__)
304 # define __NR_copy_file_range 377
305 # elif defined __s390__
306 # define __NR_copy_file_range 375
307 # elif defined __arm__
308 # define __NR_copy_file_range 391
309 # elif defined __aarch64__
310 # define __NR_copy_file_range 285
311 # elif defined __powerpc__
312 # define __NR_copy_file_range 379
313 # elif defined __arc__
314 # define __NR_copy_file_range 285
316 # warning "__NR_copy_file_range not defined for your architecture"
320 static inline ssize_t
missing_copy_file_range(int fd_in
, loff_t
*off_in
,
321 int fd_out
, loff_t
*off_out
,
323 unsigned int flags
) {
324 # ifdef __NR_copy_file_range
325 return syscall(__NR_copy_file_range
, fd_in
, off_in
, fd_out
, off_out
, len
, flags
);
332 # define copy_file_range missing_copy_file_range
335 /* ======================================================================= */
339 # if defined __i386__
340 # define __NR_bpf 357
341 # elif defined __x86_64__
342 # define __NR_bpf 321
343 # elif defined __aarch64__
344 # define __NR_bpf 280
345 # elif defined __arm__
346 # define __NR_bpf 386
347 # elif defined __sparc__
348 # define __NR_bpf 349
349 # elif defined __s390__
350 # define __NR_bpf 351
351 # elif defined __tilegx__
352 # define __NR_bpf 280
354 # warning "__NR_bpf not defined for your architecture"
360 static inline int missing_bpf(int cmd
, union bpf_attr
*attr
, size_t size
) {
362 return (int) syscall(__NR_bpf
, cmd
, attr
, size
);
369 # define bpf missing_bpf
372 /* ======================================================================= */
374 #ifndef __IGNORE_pkey_mprotect
375 # ifndef __NR_pkey_mprotect
376 # if defined __i386__
377 # define __NR_pkey_mprotect 380
378 # elif defined __x86_64__
379 # define __NR_pkey_mprotect 329
380 # elif defined __arm__
381 # define __NR_pkey_mprotect 394
382 # elif defined __aarch64__
383 # define __NR_pkey_mprotect 394
384 # elif defined __powerpc__
385 # define __NR_pkey_mprotect 386
386 # elif defined _MIPS_SIM
387 # if _MIPS_SIM == _MIPS_SIM_ABI32
388 # define __NR_pkey_mprotect 4363
390 # if _MIPS_SIM == _MIPS_SIM_NABI32
391 # define __NR_pkey_mprotect 6327
393 # if _MIPS_SIM == _MIPS_SIM_ABI64
394 # define __NR_pkey_mprotect 5323
397 # warning "__NR_pkey_mprotect not defined for your architecture"
402 /* ======================================================================= */
406 # if defined __aarch64__ || defined __arm__
407 # define __NR_statx 397
408 # elif defined __alpha__
409 # define __NR_statx 522
410 # elif defined __i386__ || defined __powerpc64__
411 # define __NR_statx 383
412 # elif defined __sparc__
413 # define __NR_statx 360
414 # elif defined __x86_64__
415 # define __NR_statx 332
417 # warning "__NR_statx not defined for your architecture"
424 /* This typedef is supposed to be always defined. */
425 typedef struct statx struct_statx
;
428 static inline ssize_t
missing_statx(int dfd
, const char *filename
, unsigned flags
, unsigned int mask
, struct statx
*buffer
) {
430 return syscall(__NR_statx
, dfd
, filename
, flags
, mask
, buffer
);
437 # define statx missing_statx