]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/missing_syscall.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 Copyright © 2016 Zbigniew Jędrzejewski-Szmek
8 /* Missing glibc definitions to access certain kernel APIs */
10 #include <sys/types.h>
13 static inline int missing_pivot_root(const char *new_root
, const char *put_old
) {
14 return syscall(__NR_pivot_root
, new_root
, put_old
);
17 # define pivot_root missing_pivot_root
20 /* ======================================================================= */
22 #if !HAVE_MEMFD_CREATE
23 # ifndef __NR_memfd_create
24 # if defined __x86_64__
25 # define __NR_memfd_create 319
26 # elif defined __arm__
27 # define __NR_memfd_create 385
28 # elif defined __aarch64__
29 # define __NR_memfd_create 279
30 # elif defined __s390__
31 # define __NR_memfd_create 350
32 # elif defined _MIPS_SIM
33 # if _MIPS_SIM == _MIPS_SIM_ABI32
34 # define __NR_memfd_create 4354
36 # if _MIPS_SIM == _MIPS_SIM_NABI32
37 # define __NR_memfd_create 6318
39 # if _MIPS_SIM == _MIPS_SIM_ABI64
40 # define __NR_memfd_create 5314
42 # elif defined __i386__
43 # define __NR_memfd_create 356
44 # elif defined __arc__
45 # define __NR_memfd_create 279
47 # warning "__NR_memfd_create unknown for your architecture"
51 static inline int missing_memfd_create(const char *name
, unsigned int flags
) {
52 # ifdef __NR_memfd_create
53 return syscall(__NR_memfd_create
, name
, flags
);
60 # define memfd_create missing_memfd_create
63 /* ======================================================================= */
66 # ifndef __NR_getrandom
67 # if defined __x86_64__
68 # define __NR_getrandom 318
69 # elif defined(__i386__)
70 # define __NR_getrandom 355
71 # elif defined(__arm__)
72 # define __NR_getrandom 384
73 # elif defined(__aarch64__)
74 # define __NR_getrandom 278
75 # elif defined(__ia64__)
76 # define __NR_getrandom 1339
77 # elif defined(__m68k__)
78 # define __NR_getrandom 352
79 # elif defined(__s390x__)
80 # define __NR_getrandom 349
81 # elif defined(__powerpc__)
82 # define __NR_getrandom 359
83 # elif defined _MIPS_SIM
84 # if _MIPS_SIM == _MIPS_SIM_ABI32
85 # define __NR_getrandom 4353
87 # if _MIPS_SIM == _MIPS_SIM_NABI32
88 # define __NR_getrandom 6317
90 # if _MIPS_SIM == _MIPS_SIM_ABI64
91 # define __NR_getrandom 5313
93 # elif defined(__arc__)
94 # define __NR_getrandom 278
96 # warning "__NR_getrandom unknown for your architecture"
100 static inline int missing_getrandom(void *buffer
, size_t count
, unsigned flags
) {
101 # ifdef __NR_getrandom
102 return syscall(__NR_getrandom
, buffer
, count
, flags
);
109 # define getrandom missing_getrandom
112 /* ======================================================================= */
115 static inline pid_t
missing_gettid(void) {
116 return (pid_t
) syscall(__NR_gettid
);
119 # define gettid missing_gettid
122 /* ======================================================================= */
124 #if !HAVE_NAME_TO_HANDLE_AT
125 # ifndef __NR_name_to_handle_at
126 # if defined(__x86_64__)
127 # define __NR_name_to_handle_at 303
128 # elif defined(__i386__)
129 # define __NR_name_to_handle_at 341
130 # elif defined(__arm__)
131 # define __NR_name_to_handle_at 370
132 # elif defined(__powerpc__)
133 # define __NR_name_to_handle_at 345
134 # elif defined(__arc__)
135 # define __NR_name_to_handle_at 264
137 # error "__NR_name_to_handle_at is not defined"
142 unsigned int handle_bytes
;
144 unsigned char f_handle
[0];
147 static inline int missing_name_to_handle_at(int fd
, const char *name
, struct file_handle
*handle
, int *mnt_id
, int flags
) {
148 # ifdef __NR_name_to_handle_at
149 return syscall(__NR_name_to_handle_at
, fd
, name
, handle
, mnt_id
, flags
);
156 # define name_to_handle_at missing_name_to_handle_at
159 /* ======================================================================= */
163 # if defined(__x86_64__)
164 # define __NR_setns 308
165 # elif defined(__i386__)
166 # define __NR_setns 346
167 # elif defined(__arc__)
168 # define __NR_setns 268
170 # error "__NR_setns is not defined"
174 static inline int missing_setns(int fd
, int nstype
) {
176 return syscall(__NR_setns
, fd
, nstype
);
183 # define setns missing_setns
186 /* ======================================================================= */
188 static inline pid_t
raw_getpid(void) {
189 #if defined(__alpha__)
190 return (pid_t
) syscall(__NR_getxpid
);
192 return (pid_t
) syscall(__NR_getpid
);
196 /* ======================================================================= */
199 # ifndef __NR_renameat2
200 # if defined __x86_64__
201 # define __NR_renameat2 316
202 # elif defined __arm__
203 # define __NR_renameat2 382
204 # elif defined __aarch64__
205 # define __NR_renameat2 276
206 # elif defined _MIPS_SIM
207 # if _MIPS_SIM == _MIPS_SIM_ABI32
208 # define __NR_renameat2 4351
210 # if _MIPS_SIM == _MIPS_SIM_NABI32
211 # define __NR_renameat2 6315
213 # if _MIPS_SIM == _MIPS_SIM_ABI64
214 # define __NR_renameat2 5311
216 # elif defined __i386__
217 # define __NR_renameat2 353
218 # elif defined __powerpc64__
219 # define __NR_renameat2 357
220 # elif defined __s390__ || defined __s390x__
221 # define __NR_renameat2 347
222 # elif defined __arc__
223 # define __NR_renameat2 276
225 # warning "__NR_renameat2 unknown for your architecture"
229 static inline int missing_renameat2(int oldfd
, const char *oldname
, int newfd
, const char *newname
, unsigned flags
) {
230 # ifdef __NR_renameat2
231 return syscall(__NR_renameat2
, oldfd
, oldname
, newfd
, newname
, flags
);
238 # define renameat2 missing_renameat2
241 /* ======================================================================= */
244 static inline int missing_kcmp(pid_t pid1
, pid_t pid2
, int type
, unsigned long idx1
, unsigned long idx2
) {
246 return syscall(__NR_kcmp
, pid1
, pid2
, type
, idx1
, idx2
);
253 # define kcmp missing_kcmp
256 /* ======================================================================= */
259 static inline long missing_keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
, unsigned long arg4
,unsigned long arg5
) {
261 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
267 # define keyctl missing_keyctl
270 static inline key_serial_t
missing_add_key(const char *type
, const char *description
, const void *payload
, size_t plen
, key_serial_t ringid
) {
272 return syscall(__NR_add_key
, type
, description
, payload
, plen
, ringid
);
278 # define add_key missing_add_key
281 static inline key_serial_t
missing_request_key(const char *type
, const char *description
, const char * callout_info
, key_serial_t destringid
) {
282 # ifdef __NR_request_key
283 return syscall(__NR_request_key
, type
, description
, callout_info
, destringid
);
289 # define request_key missing_request_key
293 /* ======================================================================= */
295 #if !HAVE_COPY_FILE_RANGE
296 # ifndef __NR_copy_file_range
297 # if defined(__x86_64__)
298 # define __NR_copy_file_range 326
299 # elif defined(__i386__)
300 # define __NR_copy_file_range 377
301 # elif defined __s390__
302 # define __NR_copy_file_range 375
303 # elif defined __arm__
304 # define __NR_copy_file_range 391
305 # elif defined __aarch64__
306 # define __NR_copy_file_range 285
307 # elif defined __powerpc__
308 # define __NR_copy_file_range 379
309 # elif defined __arc__
310 # define __NR_copy_file_range 285
312 # warning "__NR_copy_file_range not defined for your architecture"
316 static inline ssize_t
missing_copy_file_range(int fd_in
, loff_t
*off_in
,
317 int fd_out
, loff_t
*off_out
,
319 unsigned int flags
) {
320 # ifdef __NR_copy_file_range
321 return syscall(__NR_copy_file_range
, fd_in
, off_in
, fd_out
, off_out
, len
, flags
);
328 # define copy_file_range missing_copy_file_range
331 /* ======================================================================= */
335 # if defined __i386__
336 # define __NR_bpf 357
337 # elif defined __x86_64__
338 # define __NR_bpf 321
339 # elif defined __aarch64__
340 # define __NR_bpf 280
341 # elif defined __arm__
342 # define __NR_bpf 386
343 # elif defined __sparc__
344 # define __NR_bpf 349
345 # elif defined __s390__
346 # define __NR_bpf 351
347 # elif defined __tilegx__
348 # define __NR_bpf 280
350 # warning "__NR_bpf not defined for your architecture"
356 static inline int missing_bpf(int cmd
, union bpf_attr
*attr
, size_t size
) {
358 return (int) syscall(__NR_bpf
, cmd
, attr
, size
);
365 # define bpf missing_bpf
368 /* ======================================================================= */
370 #ifndef __IGNORE_pkey_mprotect
371 # ifndef __NR_pkey_mprotect
372 # if defined __i386__
373 # define __NR_pkey_mprotect 380
374 # elif defined __x86_64__
375 # define __NR_pkey_mprotect 329
376 # elif defined __arm__
377 # define __NR_pkey_mprotect 394
378 # elif defined __aarch64__
379 # define __NR_pkey_mprotect 394
380 # elif defined __powerpc__
381 # define __NR_pkey_mprotect 386
382 # elif defined _MIPS_SIM
383 # if _MIPS_SIM == _MIPS_SIM_ABI32
384 # define __NR_pkey_mprotect 4363
386 # if _MIPS_SIM == _MIPS_SIM_NABI32
387 # define __NR_pkey_mprotect 6327
389 # if _MIPS_SIM == _MIPS_SIM_ABI64
390 # define __NR_pkey_mprotect 5323
393 # warning "__NR_pkey_mprotect not defined for your architecture"
398 /* ======================================================================= */
402 # if defined __aarch64__ || defined __arm__
403 # define __NR_statx 397
404 # elif defined __alpha__
405 # define __NR_statx 522
406 # elif defined __i386__ || defined __powerpc64__
407 # define __NR_statx 383
408 # elif defined __sparc__
409 # define __NR_statx 360
410 # elif defined __x86_64__
411 # define __NR_statx 332
413 # warning "__NR_statx not defined for your architecture"
420 /* This typedef is supposed to be always defined. */
421 typedef struct statx struct_statx
;
424 static inline ssize_t
missing_statx(int dfd
, const char *filename
, unsigned flags
, unsigned int mask
, struct statx
*buffer
) {
426 return syscall(__NR_statx
, dfd
, filename
, flags
, mask
, buffer
);
433 # define statx missing_statx