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