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