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 #if 0 /// UNNEEDED by elogind
14 #include <sys/types.h>
17 static inline int missing_pivot_root(const char *new_root, const char *put_old) {
18 return syscall(__NR_pivot_root, new_root, put_old);
21 # define pivot_root missing_pivot_root
25 /* ======================================================================= */
27 #if !HAVE_MEMFD_CREATE
28 # ifndef __NR_memfd_create
29 # if defined __x86_64__
30 # define __NR_memfd_create 319
31 # elif defined __arm__
32 # define __NR_memfd_create 385
33 # elif defined __aarch64__
34 # define __NR_memfd_create 279
35 # elif defined __s390__
36 # define __NR_memfd_create 350
37 # elif defined _MIPS_SIM
38 # if _MIPS_SIM == _MIPS_SIM_ABI32
39 # define __NR_memfd_create 4354
41 # if _MIPS_SIM == _MIPS_SIM_NABI32
42 # define __NR_memfd_create 6318
44 # if _MIPS_SIM == _MIPS_SIM_ABI64
45 # define __NR_memfd_create 5314
47 # elif defined __i386__
48 # define __NR_memfd_create 356
49 # elif defined __arc__
50 # define __NR_memfd_create 279
52 # warning "__NR_memfd_create unknown for your architecture"
56 static inline int missing_memfd_create(const char *name, unsigned int flags) {
57 # ifdef __NR_memfd_create
58 return syscall(__NR_memfd_create, name, flags);
65 # define memfd_create missing_memfd_create
68 /* ======================================================================= */
71 # ifndef __NR_getrandom
72 # if defined __x86_64__
73 # define __NR_getrandom 318
74 # elif defined(__i386__)
75 # define __NR_getrandom 355
76 # elif defined(__arm__)
77 # define __NR_getrandom 384
78 # elif defined(__aarch64__)
79 # define __NR_getrandom 278
80 # elif defined(__ia64__)
81 # define __NR_getrandom 1339
82 # elif defined(__m68k__)
83 # define __NR_getrandom 352
84 # elif defined(__s390x__)
85 # define __NR_getrandom 349
86 # elif defined(__powerpc__)
87 # define __NR_getrandom 359
88 # elif defined _MIPS_SIM
89 # if _MIPS_SIM == _MIPS_SIM_ABI32
90 # define __NR_getrandom 4353
92 # if _MIPS_SIM == _MIPS_SIM_NABI32
93 # define __NR_getrandom 6317
95 # if _MIPS_SIM == _MIPS_SIM_ABI64
96 # define __NR_getrandom 5313
98 # elif defined(__arc__)
99 # define __NR_getrandom 278
101 # warning "__NR_getrandom unknown for your architecture"
105 static inline int missing_getrandom(void *buffer, size_t count, unsigned flags) {
106 # ifdef __NR_getrandom
107 return syscall(__NR_getrandom, buffer, count, flags);
114 # define getrandom missing_getrandom
117 /* ======================================================================= */
120 static inline pid_t missing_gettid(void) {
121 return (pid_t) syscall(__NR_gettid);
124 # define gettid missing_gettid
127 /* ======================================================================= */
129 #if !HAVE_NAME_TO_HANDLE_AT
130 # ifndef __NR_name_to_handle_at
131 # if defined(__x86_64__)
132 # define __NR_name_to_handle_at 303
133 # elif defined(__i386__)
134 # define __NR_name_to_handle_at 341
135 # elif defined(__arm__)
136 # define __NR_name_to_handle_at 370
137 # elif defined(__powerpc__)
138 # define __NR_name_to_handle_at 345
139 # elif defined(__arc__)
140 # define __NR_name_to_handle_at 264
142 # error "__NR_name_to_handle_at is not defined"
147 unsigned int handle_bytes;
149 unsigned char f_handle[0];
152 static inline int missing_name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
153 # ifdef __NR_name_to_handle_at
154 return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
161 # define name_to_handle_at missing_name_to_handle_at
164 /* ======================================================================= */
168 # if defined(__x86_64__)
169 # define __NR_setns 308
170 # elif defined(__i386__)
171 # define __NR_setns 346
172 # elif defined(__arc__)
173 # define __NR_setns 268
175 # error "__NR_setns is not defined"
179 static inline int missing_setns(int fd, int nstype) {
181 return syscall(__NR_setns, fd, nstype);
188 # define setns missing_setns
191 /* ======================================================================= */
193 static inline pid_t raw_getpid(void) {
194 #if defined(__alpha__)
195 return (pid_t) syscall(__NR_getxpid);
197 return (pid_t) syscall(__NR_getpid);
201 /* ======================================================================= */
204 # ifndef __NR_renameat2
205 # if defined __x86_64__
206 # define __NR_renameat2 316
207 # elif defined __arm__
208 # define __NR_renameat2 382
209 # elif defined __aarch64__
210 # define __NR_renameat2 276
211 # elif defined _MIPS_SIM
212 # if _MIPS_SIM == _MIPS_SIM_ABI32
213 # define __NR_renameat2 4351
215 # if _MIPS_SIM == _MIPS_SIM_NABI32
216 # define __NR_renameat2 6315
218 # if _MIPS_SIM == _MIPS_SIM_ABI64
219 # define __NR_renameat2 5311
221 # elif defined __i386__
222 # define __NR_renameat2 353
223 # elif defined __powerpc64__
224 # define __NR_renameat2 357
225 # elif defined __s390__ || defined __s390x__
226 # define __NR_renameat2 347
227 # elif defined __arc__
228 # define __NR_renameat2 276
230 # warning "__NR_renameat2 unknown for your architecture"
234 static inline int missing_renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
235 # ifdef __NR_renameat2
236 return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
243 # define renameat2 missing_renameat2
246 /* ======================================================================= */
249 static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
251 return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
258 # define kcmp missing_kcmp
261 /* ======================================================================= */
264 static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4,unsigned long arg5) {
266 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
272 # define keyctl missing_keyctl
275 static inline key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
277 return syscall(__NR_add_key, type, description, payload, plen, ringid);
283 # define add_key missing_add_key
286 static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
287 # ifdef __NR_request_key
288 return syscall(__NR_request_key, type, description, callout_info, destringid);
294 # define request_key missing_request_key
298 /* ======================================================================= */
300 #if !HAVE_COPY_FILE_RANGE
301 # ifndef __NR_copy_file_range
302 # if defined(__x86_64__)
303 # define __NR_copy_file_range 326
304 # elif defined(__i386__)
305 # define __NR_copy_file_range 377
306 # elif defined __s390__
307 # define __NR_copy_file_range 375
308 # elif defined __arm__
309 # define __NR_copy_file_range 391
310 # elif defined __aarch64__
311 # define __NR_copy_file_range 285
312 # elif defined __powerpc__
313 # define __NR_copy_file_range 379
314 # elif defined __arc__
315 # define __NR_copy_file_range 285
317 # warning "__NR_copy_file_range not defined for your architecture"
321 static inline ssize_t missing_copy_file_range(int fd_in, loff_t *off_in,
322 int fd_out, loff_t *off_out,
324 unsigned int flags) {
325 # ifdef __NR_copy_file_range
326 return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags);
333 # define copy_file_range missing_copy_file_range
336 /* ======================================================================= */
340 # if defined __i386__
341 # define __NR_bpf 357
342 # elif defined __x86_64__
343 # define __NR_bpf 321
344 # elif defined __aarch64__
345 # define __NR_bpf 280
346 # elif defined __arm__
347 # define __NR_bpf 386
348 # elif defined __sparc__
349 # define __NR_bpf 349
350 # elif defined __s390__
351 # define __NR_bpf 351
352 # elif defined __tilegx__
353 # define __NR_bpf 280
355 # warning "__NR_bpf not defined for your architecture"
361 static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) {
363 return (int) syscall(__NR_bpf, cmd, attr, size);
370 # define bpf missing_bpf
373 /* ======================================================================= */
375 #ifndef __IGNORE_pkey_mprotect
376 # ifndef __NR_pkey_mprotect
377 # if defined __i386__
378 # define __NR_pkey_mprotect 380
379 # elif defined __x86_64__
380 # define __NR_pkey_mprotect 329
381 # elif defined __arm__
382 # define __NR_pkey_mprotect 394
383 # elif defined __aarch64__
384 # define __NR_pkey_mprotect 394
385 # elif defined __powerpc__
386 # define __NR_pkey_mprotect 386
387 # elif defined _MIPS_SIM
388 # if _MIPS_SIM == _MIPS_SIM_ABI32
389 # define __NR_pkey_mprotect 4363
391 # if _MIPS_SIM == _MIPS_SIM_NABI32
392 # define __NR_pkey_mprotect 6327
394 # if _MIPS_SIM == _MIPS_SIM_ABI64
395 # define __NR_pkey_mprotect 5323
398 # warning "__NR_pkey_mprotect not defined for your architecture"
403 /* ======================================================================= */
407 # if defined __aarch64__ || defined __arm__
408 # define __NR_statx 397
409 # elif defined __alpha__
410 # define __NR_statx 522
411 # elif defined __i386__ || defined __powerpc64__
412 # define __NR_statx 383
413 # elif defined __sparc__
414 # define __NR_statx 360
415 # elif defined __x86_64__
416 # define __NR_statx 332
418 # warning "__NR_statx not defined for your architecture"
425 /* This typedef is supposed to be always defined. */
426 typedef struct statx struct_statx;
429 static inline ssize_t missing_statx(int dfd, const char *filename, unsigned flags, unsigned int mask, struct statx *buffer) {
431 return syscall(__NR_statx, dfd, filename, flags, mask, buffer);
438 # define statx missing_statx