]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2f368e4a ZJS |
2 | #pragma once |
3 | ||
2f368e4a ZJS |
4 | /* Missing glibc definitions to access certain kernel APIs */ |
5 | ||
e2d94d0c | 6 | #include <errno.h> |
36dd5ffd YW |
7 | #include <fcntl.h> |
8 | #include <sys/syscall.h> | |
71e5200f | 9 | #include <sys/types.h> |
851d66fa YW |
10 | #include <unistd.h> |
11 | ||
12 | #ifdef ARCH_MIPS | |
13 | #include <asm/sgidefs.h> | |
14 | #endif | |
71e5200f | 15 | |
d7276b61 | 16 | #include "missing_keyctl.h" |
e01819f8 | 17 | #include "missing_stat.h" |
d7276b61 | 18 | |
851d66fa YW |
19 | /* linux/kcmp.h */ |
20 | #ifndef KCMP_FILE /* 3f4994cfc15f38a3159c6e3a4b3ab2e1481a6b02 (3.19) */ | |
21 | #define KCMP_FILE 0 | |
22 | #endif | |
23 | ||
4b9545f1 | 24 | #if !HAVE_PIVOT_ROOT |
5187dd2c | 25 | static inline int missing_pivot_root(const char *new_root, const char *put_old) { |
d06f3829 | 26 | return syscall(__NR_pivot_root, new_root, put_old); |
2f368e4a | 27 | } |
5187dd2c ZJS |
28 | |
29 | # define pivot_root missing_pivot_root | |
2f368e4a ZJS |
30 | #endif |
31 | ||
32 | /* ======================================================================= */ | |
33 | ||
4b9545f1 | 34 | #if !HAVE_MEMFD_CREATE |
2f368e4a ZJS |
35 | # ifndef __NR_memfd_create |
36 | # if defined __x86_64__ | |
37 | # define __NR_memfd_create 319 | |
38 | # elif defined __arm__ | |
39 | # define __NR_memfd_create 385 | |
40 | # elif defined __aarch64__ | |
41 | # define __NR_memfd_create 279 | |
42 | # elif defined __s390__ | |
43 | # define __NR_memfd_create 350 | |
44 | # elif defined _MIPS_SIM | |
45 | # if _MIPS_SIM == _MIPS_SIM_ABI32 | |
46 | # define __NR_memfd_create 4354 | |
47 | # endif | |
48 | # if _MIPS_SIM == _MIPS_SIM_NABI32 | |
49 | # define __NR_memfd_create 6318 | |
50 | # endif | |
51 | # if _MIPS_SIM == _MIPS_SIM_ABI64 | |
52 | # define __NR_memfd_create 5314 | |
53 | # endif | |
54 | # elif defined __i386__ | |
55 | # define __NR_memfd_create 356 | |
27b09f1f AB |
56 | # elif defined __arc__ |
57 | # define __NR_memfd_create 279 | |
2f368e4a ZJS |
58 | # else |
59 | # warning "__NR_memfd_create unknown for your architecture" | |
60 | # endif | |
61 | # endif | |
62 | ||
5187dd2c | 63 | static inline int missing_memfd_create(const char *name, unsigned int flags) { |
2f368e4a ZJS |
64 | # ifdef __NR_memfd_create |
65 | return syscall(__NR_memfd_create, name, flags); | |
66 | # else | |
67 | errno = ENOSYS; | |
68 | return -1; | |
69 | # endif | |
70 | } | |
5187dd2c ZJS |
71 | |
72 | # define memfd_create missing_memfd_create | |
2f368e4a ZJS |
73 | #endif |
74 | ||
75 | /* ======================================================================= */ | |
76 | ||
4b9545f1 | 77 | #if !HAVE_GETRANDOM |
2f368e4a ZJS |
78 | # ifndef __NR_getrandom |
79 | # if defined __x86_64__ | |
80 | # define __NR_getrandom 318 | |
81 | # elif defined(__i386__) | |
82 | # define __NR_getrandom 355 | |
83 | # elif defined(__arm__) | |
84 | # define __NR_getrandom 384 | |
85 | # elif defined(__aarch64__) | |
86 | # define __NR_getrandom 278 | |
87 | # elif defined(__ia64__) | |
88 | # define __NR_getrandom 1339 | |
89 | # elif defined(__m68k__) | |
90 | # define __NR_getrandom 352 | |
91 | # elif defined(__s390x__) | |
92 | # define __NR_getrandom 349 | |
93 | # elif defined(__powerpc__) | |
94 | # define __NR_getrandom 359 | |
95 | # elif defined _MIPS_SIM | |
96 | # if _MIPS_SIM == _MIPS_SIM_ABI32 | |
97 | # define __NR_getrandom 4353 | |
98 | # endif | |
99 | # if _MIPS_SIM == _MIPS_SIM_NABI32 | |
100 | # define __NR_getrandom 6317 | |
101 | # endif | |
102 | # if _MIPS_SIM == _MIPS_SIM_ABI64 | |
103 | # define __NR_getrandom 5313 | |
104 | # endif | |
27b09f1f AB |
105 | # elif defined(__arc__) |
106 | # define __NR_getrandom 278 | |
2f368e4a ZJS |
107 | # else |
108 | # warning "__NR_getrandom unknown for your architecture" | |
109 | # endif | |
110 | # endif | |
111 | ||
5187dd2c | 112 | static inline int missing_getrandom(void *buffer, size_t count, unsigned flags) { |
2f368e4a ZJS |
113 | # ifdef __NR_getrandom |
114 | return syscall(__NR_getrandom, buffer, count, flags); | |
115 | # else | |
116 | errno = ENOSYS; | |
117 | return -1; | |
118 | # endif | |
119 | } | |
5187dd2c ZJS |
120 | |
121 | # define getrandom missing_getrandom | |
2f368e4a ZJS |
122 | #endif |
123 | ||
124 | /* ======================================================================= */ | |
125 | ||
4b9545f1 | 126 | #if !HAVE_GETTID |
5187dd2c | 127 | static inline pid_t missing_gettid(void) { |
d06f3829 | 128 | return (pid_t) syscall(__NR_gettid); |
2f368e4a | 129 | } |
5187dd2c ZJS |
130 | |
131 | # define gettid missing_gettid | |
2f368e4a ZJS |
132 | #endif |
133 | ||
134 | /* ======================================================================= */ | |
135 | ||
4b9545f1 | 136 | #if !HAVE_NAME_TO_HANDLE_AT |
2f368e4a ZJS |
137 | # ifndef __NR_name_to_handle_at |
138 | # if defined(__x86_64__) | |
139 | # define __NR_name_to_handle_at 303 | |
140 | # elif defined(__i386__) | |
141 | # define __NR_name_to_handle_at 341 | |
142 | # elif defined(__arm__) | |
143 | # define __NR_name_to_handle_at 370 | |
144 | # elif defined(__powerpc__) | |
145 | # define __NR_name_to_handle_at 345 | |
27b09f1f AB |
146 | # elif defined(__arc__) |
147 | # define __NR_name_to_handle_at 264 | |
2f368e4a ZJS |
148 | # else |
149 | # error "__NR_name_to_handle_at is not defined" | |
150 | # endif | |
151 | # endif | |
152 | ||
153 | struct file_handle { | |
154 | unsigned int handle_bytes; | |
155 | int handle_type; | |
156 | unsigned char f_handle[0]; | |
157 | }; | |
158 | ||
5187dd2c | 159 | static inline int missing_name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) { |
2f368e4a ZJS |
160 | # ifdef __NR_name_to_handle_at |
161 | return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags); | |
162 | # else | |
163 | errno = ENOSYS; | |
164 | return -1; | |
165 | # endif | |
166 | } | |
5187dd2c ZJS |
167 | |
168 | # define name_to_handle_at missing_name_to_handle_at | |
2f368e4a ZJS |
169 | #endif |
170 | ||
171 | /* ======================================================================= */ | |
172 | ||
4b9545f1 | 173 | #if !HAVE_SETNS |
2f368e4a ZJS |
174 | # ifndef __NR_setns |
175 | # if defined(__x86_64__) | |
176 | # define __NR_setns 308 | |
177 | # elif defined(__i386__) | |
178 | # define __NR_setns 346 | |
27b09f1f AB |
179 | # elif defined(__arc__) |
180 | # define __NR_setns 268 | |
2f368e4a ZJS |
181 | # else |
182 | # error "__NR_setns is not defined" | |
183 | # endif | |
184 | # endif | |
185 | ||
5187dd2c | 186 | static inline int missing_setns(int fd, int nstype) { |
2f368e4a ZJS |
187 | # ifdef __NR_setns |
188 | return syscall(__NR_setns, fd, nstype); | |
189 | # else | |
190 | errno = ENOSYS; | |
191 | return -1; | |
192 | # endif | |
193 | } | |
5187dd2c ZJS |
194 | |
195 | # define setns missing_setns | |
2f368e4a ZJS |
196 | #endif |
197 | ||
198 | /* ======================================================================= */ | |
199 | ||
2f368e4a ZJS |
200 | static inline pid_t raw_getpid(void) { |
201 | #if defined(__alpha__) | |
202 | return (pid_t) syscall(__NR_getxpid); | |
203 | #else | |
204 | return (pid_t) syscall(__NR_getpid); | |
205 | #endif | |
206 | } | |
207 | ||
208 | /* ======================================================================= */ | |
209 | ||
4b9545f1 | 210 | #if !HAVE_RENAMEAT2 |
2f368e4a ZJS |
211 | # ifndef __NR_renameat2 |
212 | # if defined __x86_64__ | |
213 | # define __NR_renameat2 316 | |
214 | # elif defined __arm__ | |
215 | # define __NR_renameat2 382 | |
925c81cd LP |
216 | # elif defined __aarch64__ |
217 | # define __NR_renameat2 276 | |
2f368e4a ZJS |
218 | # elif defined _MIPS_SIM |
219 | # if _MIPS_SIM == _MIPS_SIM_ABI32 | |
220 | # define __NR_renameat2 4351 | |
221 | # endif | |
222 | # if _MIPS_SIM == _MIPS_SIM_NABI32 | |
223 | # define __NR_renameat2 6315 | |
224 | # endif | |
225 | # if _MIPS_SIM == _MIPS_SIM_ABI64 | |
226 | # define __NR_renameat2 5311 | |
227 | # endif | |
228 | # elif defined __i386__ | |
229 | # define __NR_renameat2 353 | |
92369d5e ZJS |
230 | # elif defined __powerpc64__ |
231 | # define __NR_renameat2 357 | |
232 | # elif defined __s390__ || defined __s390x__ | |
233 | # define __NR_renameat2 347 | |
27b09f1f AB |
234 | # elif defined __arc__ |
235 | # define __NR_renameat2 276 | |
2f368e4a ZJS |
236 | # else |
237 | # warning "__NR_renameat2 unknown for your architecture" | |
238 | # endif | |
239 | # endif | |
240 | ||
5187dd2c | 241 | static inline int missing_renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) { |
2f368e4a ZJS |
242 | # ifdef __NR_renameat2 |
243 | return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags); | |
244 | # else | |
245 | errno = ENOSYS; | |
246 | return -1; | |
247 | # endif | |
248 | } | |
5187dd2c ZJS |
249 | |
250 | # define renameat2 missing_renameat2 | |
2f368e4a ZJS |
251 | #endif |
252 | ||
253 | /* ======================================================================= */ | |
254 | ||
4b9545f1 | 255 | #if !HAVE_KCMP |
5187dd2c | 256 | static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) { |
2f368e4a ZJS |
257 | # ifdef __NR_kcmp |
258 | return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2); | |
259 | # else | |
260 | errno = ENOSYS; | |
261 | return -1; | |
262 | # endif | |
263 | } | |
5187dd2c ZJS |
264 | |
265 | # define kcmp missing_kcmp | |
2f368e4a ZJS |
266 | #endif |
267 | ||
268 | /* ======================================================================= */ | |
269 | ||
4b9545f1 | 270 | #if !HAVE_KEYCTL |
851d66fa | 271 | static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) { |
2f368e4a ZJS |
272 | # ifdef __NR_keyctl |
273 | return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5); | |
274 | # else | |
275 | errno = ENOSYS; | |
276 | return -1; | |
277 | # endif | |
5187dd2c ZJS |
278 | |
279 | # define keyctl missing_keyctl | |
2f368e4a ZJS |
280 | } |
281 | ||
5187dd2c | 282 | static inline key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) { |
2f368e4a ZJS |
283 | # ifdef __NR_add_key |
284 | return syscall(__NR_add_key, type, description, payload, plen, ringid); | |
285 | # else | |
286 | errno = ENOSYS; | |
287 | return -1; | |
288 | # endif | |
5187dd2c ZJS |
289 | |
290 | # define add_key missing_add_key | |
2f368e4a ZJS |
291 | } |
292 | ||
5187dd2c | 293 | static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) { |
2f368e4a ZJS |
294 | # ifdef __NR_request_key |
295 | return syscall(__NR_request_key, type, description, callout_info, destringid); | |
296 | # else | |
297 | errno = ENOSYS; | |
298 | return -1; | |
299 | # endif | |
5187dd2c ZJS |
300 | |
301 | # define request_key missing_request_key | |
2f368e4a ZJS |
302 | } |
303 | #endif | |
304 | ||
305 | /* ======================================================================= */ | |
306 | ||
4b9545f1 | 307 | #if !HAVE_COPY_FILE_RANGE |
2f368e4a ZJS |
308 | # ifndef __NR_copy_file_range |
309 | # if defined(__x86_64__) | |
310 | # define __NR_copy_file_range 326 | |
311 | # elif defined(__i386__) | |
312 | # define __NR_copy_file_range 377 | |
313 | # elif defined __s390__ | |
314 | # define __NR_copy_file_range 375 | |
315 | # elif defined __arm__ | |
316 | # define __NR_copy_file_range 391 | |
317 | # elif defined __aarch64__ | |
318 | # define __NR_copy_file_range 285 | |
4d07c8d3 AIB |
319 | # elif defined __powerpc__ |
320 | # define __NR_copy_file_range 379 | |
27b09f1f AB |
321 | # elif defined __arc__ |
322 | # define __NR_copy_file_range 285 | |
2f368e4a ZJS |
323 | # else |
324 | # warning "__NR_copy_file_range not defined for your architecture" | |
325 | # endif | |
326 | # endif | |
327 | ||
5187dd2c ZJS |
328 | static inline ssize_t missing_copy_file_range(int fd_in, loff_t *off_in, |
329 | int fd_out, loff_t *off_out, | |
330 | size_t len, | |
331 | unsigned int flags) { | |
2f368e4a ZJS |
332 | # ifdef __NR_copy_file_range |
333 | return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags); | |
334 | # else | |
335 | errno = ENOSYS; | |
336 | return -1; | |
337 | # endif | |
338 | } | |
5187dd2c ZJS |
339 | |
340 | # define copy_file_range missing_copy_file_range | |
2f368e4a | 341 | #endif |
71e5200f | 342 | |
213f2883 ZJS |
343 | /* ======================================================================= */ |
344 | ||
4b9545f1 | 345 | #if !HAVE_BPF |
71e5200f DM |
346 | # ifndef __NR_bpf |
347 | # if defined __i386__ | |
348 | # define __NR_bpf 357 | |
349 | # elif defined __x86_64__ | |
350 | # define __NR_bpf 321 | |
351 | # elif defined __aarch64__ | |
352 | # define __NR_bpf 280 | |
d07ba5d7 HCNE |
353 | # elif defined __arm__ |
354 | # define __NR_bpf 386 | |
71e5200f DM |
355 | # elif defined __sparc__ |
356 | # define __NR_bpf 349 | |
357 | # elif defined __s390__ | |
358 | # define __NR_bpf 351 | |
66ffb275 HCNE |
359 | # elif defined __tilegx__ |
360 | # define __NR_bpf 280 | |
71e5200f DM |
361 | # else |
362 | # warning "__NR_bpf not defined for your architecture" | |
363 | # endif | |
364 | # endif | |
365 | ||
366 | union bpf_attr; | |
367 | ||
5187dd2c | 368 | static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) { |
71e5200f DM |
369 | #ifdef __NR_bpf |
370 | return (int) syscall(__NR_bpf, cmd, attr, size); | |
371 | #else | |
372 | errno = ENOSYS; | |
373 | return -1; | |
374 | #endif | |
375 | } | |
376 | ||
5187dd2c | 377 | # define bpf missing_bpf |
71e5200f | 378 | #endif |
213f2883 ZJS |
379 | |
380 | /* ======================================================================= */ | |
381 | ||
382 | #ifndef __IGNORE_pkey_mprotect | |
383 | # ifndef __NR_pkey_mprotect | |
384 | # if defined __i386__ | |
385 | # define __NR_pkey_mprotect 380 | |
386 | # elif defined __x86_64__ | |
387 | # define __NR_pkey_mprotect 329 | |
388 | # elif defined __arm__ | |
389 | # define __NR_pkey_mprotect 394 | |
390 | # elif defined __aarch64__ | |
391 | # define __NR_pkey_mprotect 394 | |
033c8366 ZJS |
392 | # elif defined __powerpc__ |
393 | # define __NR_pkey_mprotect 386 | |
4f6d0cf8 DS |
394 | # elif defined __s390__ |
395 | # define __NR_pkey_mprotect 384 | |
213f2883 ZJS |
396 | # elif defined _MIPS_SIM |
397 | # if _MIPS_SIM == _MIPS_SIM_ABI32 | |
398 | # define __NR_pkey_mprotect 4363 | |
399 | # endif | |
400 | # if _MIPS_SIM == _MIPS_SIM_NABI32 | |
401 | # define __NR_pkey_mprotect 6327 | |
402 | # endif | |
403 | # if _MIPS_SIM == _MIPS_SIM_ABI64 | |
404 | # define __NR_pkey_mprotect 5323 | |
405 | # endif | |
9c6888ac | 406 | # else |
213f2883 ZJS |
407 | # warning "__NR_pkey_mprotect not defined for your architecture" |
408 | # endif | |
409 | # endif | |
410 | #endif | |
4c2e1b39 | 411 | |
5187dd2c ZJS |
412 | /* ======================================================================= */ |
413 | ||
4c2e1b39 LP |
414 | #if !HAVE_STATX |
415 | # ifndef __NR_statx | |
773c8434 AD |
416 | # if defined __aarch64__ || defined __arm__ |
417 | # define __NR_statx 397 | |
418 | # elif defined __alpha__ | |
419 | # define __NR_statx 522 | |
420 | # elif defined __i386__ || defined __powerpc64__ | |
fd91e3ef | 421 | # define __NR_statx 383 |
773c8434 AD |
422 | # elif defined __sparc__ |
423 | # define __NR_statx 360 | |
4c2e1b39 | 424 | # elif defined __x86_64__ |
fd91e3ef | 425 | # define __NR_statx 332 |
4c2e1b39 LP |
426 | # else |
427 | # warning "__NR_statx not defined for your architecture" | |
428 | # endif | |
429 | # endif | |
430 | ||
431 | struct statx; | |
5187dd2c ZJS |
432 | #endif |
433 | ||
434 | /* This typedef is supposed to be always defined. */ | |
435 | typedef struct statx struct_statx; | |
4c2e1b39 | 436 | |
5187dd2c ZJS |
437 | #if !HAVE_STATX |
438 | static inline ssize_t missing_statx(int dfd, const char *filename, unsigned flags, unsigned int mask, struct statx *buffer) { | |
4c2e1b39 LP |
439 | # ifdef __NR_statx |
440 | return syscall(__NR_statx, dfd, filename, flags, mask, buffer); | |
441 | # else | |
442 | errno = ENOSYS; | |
443 | return -1; | |
444 | # endif | |
445 | } | |
5187dd2c ZJS |
446 | |
447 | # define statx missing_statx | |
4c2e1b39 | 448 | #endif |
b070c7c0 MS |
449 | |
450 | #if !HAVE_SET_MEMPOLICY | |
451 | ||
452 | enum { | |
453 | MPOL_DEFAULT, | |
454 | MPOL_PREFERRED, | |
455 | MPOL_BIND, | |
456 | MPOL_INTERLEAVE, | |
457 | MPOL_LOCAL, | |
458 | }; | |
459 | ||
460 | static inline long missing_set_mempolicy(int mode, const unsigned long *nodemask, | |
461 | unsigned long maxnode) { | |
462 | long i; | |
463 | # ifdef __NR_set_mempolicy | |
464 | i = syscall(__NR_set_mempolicy, mode, nodemask, maxnode); | |
465 | # else | |
466 | errno = ENOSYS; | |
467 | i = -1; | |
468 | # endif | |
469 | return i; | |
470 | } | |
471 | ||
472 | # define set_mempolicy missing_set_mempolicy | |
473 | #endif | |
474 | ||
b070c7c0 MS |
475 | #if !HAVE_GET_MEMPOLICY |
476 | static inline long missing_get_mempolicy(int *mode, unsigned long *nodemask, | |
477 | unsigned long maxnode, void *addr, | |
478 | unsigned long flags) { | |
479 | long i; | |
480 | # ifdef __NR_get_mempolicy | |
481 | i = syscall(__NR_get_mempolicy, mode, nodemask, maxnode, addr, flags); | |
482 | # else | |
483 | errno = ENOSYS; | |
484 | i = -1; | |
485 | # endif | |
486 | return i; | |
487 | } | |
488 | ||
489 | #define get_mempolicy missing_get_mempolicy | |
490 | #endif |