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