1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 Copyright © 2016 Zbigniew Jędrzejewski-Szmek
8 /* Missing glibc definitions to access certain kernel APIs */
10 #if 0 /// UNNEEDED by elogind
11 #include <sys/types.h>
14 static inline int missing_pivot_root(const char *new_root, const char *put_old) {
15 return syscall(__NR_pivot_root, new_root, put_old);
18 # define pivot_root missing_pivot_root
22 /* ======================================================================= */
24 #if !HAVE_MEMFD_CREATE
25 # ifndef __NR_memfd_create
26 # if defined __x86_64__
27 # define __NR_memfd_create 319
28 # elif defined __arm__
29 # define __NR_memfd_create 385
30 # elif defined __aarch64__
31 # define __NR_memfd_create 279
32 # elif defined __s390__
33 # define __NR_memfd_create 350
34 # elif defined _MIPS_SIM
35 # if _MIPS_SIM == _MIPS_SIM_ABI32
36 # define __NR_memfd_create 4354
38 # if _MIPS_SIM == _MIPS_SIM_NABI32
39 # define __NR_memfd_create 6318
41 # if _MIPS_SIM == _MIPS_SIM_ABI64
42 # define __NR_memfd_create 5314
44 # elif defined __i386__
45 # define __NR_memfd_create 356
46 # elif defined __arc__
47 # define __NR_memfd_create 279
49 # warning "__NR_memfd_create unknown for your architecture"
53 static inline int missing_memfd_create(const char *name, unsigned int flags) {
54 # ifdef __NR_memfd_create
55 return syscall(__NR_memfd_create, name, flags);
62 # define memfd_create missing_memfd_create
65 /* ======================================================================= */
68 # ifndef __NR_getrandom
69 # if defined __x86_64__
70 # define __NR_getrandom 318
71 # elif defined(__i386__)
72 # define __NR_getrandom 355
73 # elif defined(__arm__)
74 # define __NR_getrandom 384
75 # elif defined(__aarch64__)
76 # define __NR_getrandom 278
77 # elif defined(__ia64__)
78 # define __NR_getrandom 1339
79 # elif defined(__m68k__)
80 # define __NR_getrandom 352
81 # elif defined(__s390x__)
82 # define __NR_getrandom 349
83 # elif defined(__powerpc__)
84 # define __NR_getrandom 359
85 # elif defined _MIPS_SIM
86 # if _MIPS_SIM == _MIPS_SIM_ABI32
87 # define __NR_getrandom 4353
89 # if _MIPS_SIM == _MIPS_SIM_NABI32
90 # define __NR_getrandom 6317
92 # if _MIPS_SIM == _MIPS_SIM_ABI64
93 # define __NR_getrandom 5313
95 # elif defined(__arc__)
96 # define __NR_getrandom 278
98 # warning "__NR_getrandom unknown for your architecture"
102 static inline int missing_getrandom(void *buffer, size_t count, unsigned flags) {
103 # ifdef __NR_getrandom
104 return syscall(__NR_getrandom, buffer, count, flags);
111 # define getrandom missing_getrandom
114 /* ======================================================================= */
117 static inline pid_t missing_gettid(void) {
118 return (pid_t) syscall(__NR_gettid);
121 # define gettid missing_gettid
124 /* ======================================================================= */
126 #if !HAVE_NAME_TO_HANDLE_AT
127 # ifndef __NR_name_to_handle_at
128 # if defined(__x86_64__)
129 # define __NR_name_to_handle_at 303
130 # elif defined(__i386__)
131 # define __NR_name_to_handle_at 341
132 # elif defined(__arm__)
133 # define __NR_name_to_handle_at 370
134 # elif defined(__powerpc__)
135 # define __NR_name_to_handle_at 345
136 # elif defined(__arc__)
137 # define __NR_name_to_handle_at 264
139 # error "__NR_name_to_handle_at is not defined"
144 unsigned int handle_bytes;
146 unsigned char f_handle[0];
149 static inline int missing_name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
150 # ifdef __NR_name_to_handle_at
151 return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
158 # define name_to_handle_at missing_name_to_handle_at
161 /* ======================================================================= */
165 # if defined(__x86_64__)
166 # define __NR_setns 308
167 # elif defined(__i386__)
168 # define __NR_setns 346
169 # elif defined(__arc__)
170 # define __NR_setns 268
172 # error "__NR_setns is not defined"
176 static inline int missing_setns(int fd, int nstype) {
178 return syscall(__NR_setns, fd, nstype);
185 # define setns missing_setns
188 /* ======================================================================= */
190 static inline pid_t raw_getpid(void) {
191 #if defined(__alpha__)
192 return (pid_t) syscall(__NR_getxpid);
194 return (pid_t) syscall(__NR_getpid);
198 /* ======================================================================= */
201 # ifndef __NR_renameat2
202 # if defined __x86_64__
203 # define __NR_renameat2 316
204 # elif defined __arm__
205 # define __NR_renameat2 382
206 # elif defined __aarch64__
207 # define __NR_renameat2 276
208 # elif defined _MIPS_SIM
209 # if _MIPS_SIM == _MIPS_SIM_ABI32
210 # define __NR_renameat2 4351
212 # if _MIPS_SIM == _MIPS_SIM_NABI32
213 # define __NR_renameat2 6315
215 # if _MIPS_SIM == _MIPS_SIM_ABI64
216 # define __NR_renameat2 5311
218 # elif defined __i386__
219 # define __NR_renameat2 353
220 # elif defined __powerpc64__
221 # define __NR_renameat2 357
222 # elif defined __s390__ || defined __s390x__
223 # define __NR_renameat2 347
224 # elif defined __arc__
225 # define __NR_renameat2 276
227 # warning "__NR_renameat2 unknown for your architecture"
231 static inline int missing_renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
232 # ifdef __NR_renameat2
233 return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
240 # define renameat2 missing_renameat2
243 /* ======================================================================= */
246 static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
248 return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
255 # define kcmp missing_kcmp
258 /* ======================================================================= */
261 static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4,unsigned long arg5) {
263 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
269 # define keyctl missing_keyctl
272 static inline key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
274 return syscall(__NR_add_key, type, description, payload, plen, ringid);
280 # define add_key missing_add_key
283 static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
284 # ifdef __NR_request_key
285 return syscall(__NR_request_key, type, description, callout_info, destringid);
291 # define request_key missing_request_key
295 /* ======================================================================= */
297 #if !HAVE_COPY_FILE_RANGE
298 # ifndef __NR_copy_file_range
299 # if defined(__x86_64__)
300 # define __NR_copy_file_range 326
301 # elif defined(__i386__)
302 # define __NR_copy_file_range 377
303 # elif defined __s390__
304 # define __NR_copy_file_range 375
305 # elif defined __arm__
306 # define __NR_copy_file_range 391
307 # elif defined __aarch64__
308 # define __NR_copy_file_range 285
309 # elif defined __powerpc__
310 # define __NR_copy_file_range 379
311 # elif defined __arc__
312 # define __NR_copy_file_range 285
314 # warning "__NR_copy_file_range not defined for your architecture"
318 static inline ssize_t missing_copy_file_range(int fd_in, loff_t *off_in,
319 int fd_out, loff_t *off_out,
321 unsigned int flags) {
322 # ifdef __NR_copy_file_range
323 return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags);
330 # define copy_file_range missing_copy_file_range
333 /* ======================================================================= */
337 # if defined __i386__
338 # define __NR_bpf 357
339 # elif defined __x86_64__
340 # define __NR_bpf 321
341 # elif defined __aarch64__
342 # define __NR_bpf 280
343 # elif defined __arm__
344 # define __NR_bpf 386
345 # elif defined __sparc__
346 # define __NR_bpf 349
347 # elif defined __s390__
348 # define __NR_bpf 351
349 # elif defined __tilegx__
350 # define __NR_bpf 280
352 # warning "__NR_bpf not defined for your architecture"
358 static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) {
360 return (int) syscall(__NR_bpf, cmd, attr, size);
367 # define bpf missing_bpf
370 /* ======================================================================= */
372 #ifndef __IGNORE_pkey_mprotect
373 # ifndef __NR_pkey_mprotect
374 # if defined __i386__
375 # define __NR_pkey_mprotect 380
376 # elif defined __x86_64__
377 # define __NR_pkey_mprotect 329
378 # elif defined __arm__
379 # define __NR_pkey_mprotect 394
380 # elif defined __aarch64__
381 # define __NR_pkey_mprotect 394
382 # elif defined __powerpc__
383 # define __NR_pkey_mprotect 386
384 # elif defined _MIPS_SIM
385 # if _MIPS_SIM == _MIPS_SIM_ABI32
386 # define __NR_pkey_mprotect 4363
388 # if _MIPS_SIM == _MIPS_SIM_NABI32
389 # define __NR_pkey_mprotect 6327
391 # if _MIPS_SIM == _MIPS_SIM_ABI64
392 # define __NR_pkey_mprotect 5323
395 # warning "__NR_pkey_mprotect not defined for your architecture"
400 /* ======================================================================= */
404 # if defined __aarch64__ || defined __arm__
405 # define __NR_statx 397
406 # elif defined __alpha__
407 # define __NR_statx 522
408 # elif defined __i386__ || defined __powerpc64__
409 # define __NR_statx 383
410 # elif defined __sparc__
411 # define __NR_statx 360
412 # elif defined __x86_64__
413 # define __NR_statx 332
415 # warning "__NR_statx not defined for your architecture"
422 /* This typedef is supposed to be always defined. */
423 typedef struct statx struct_statx;
426 static inline ssize_t missing_statx(int dfd, const char *filename, unsigned flags, unsigned int mask, struct statx *buffer) {
428 return syscall(__NR_statx, dfd, filename, flags, mask, buffer);
435 # define statx missing_statx