]>
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 | 7 | #include <fcntl.h> |
5f152f43 | 8 | #include <signal.h> |
36dd5ffd | 9 | #include <sys/syscall.h> |
71e5200f | 10 | #include <sys/types.h> |
5f152f43 | 11 | #include <sys/wait.h> |
851d66fa YW |
12 | #include <unistd.h> |
13 | ||
14 | #ifdef ARCH_MIPS | |
15 | #include <asm/sgidefs.h> | |
16 | #endif | |
71e5200f | 17 | |
d7276b61 | 18 | #include "missing_keyctl.h" |
e01819f8 | 19 | #include "missing_stat.h" |
d7276b61 | 20 | |
851d66fa YW |
21 | /* linux/kcmp.h */ |
22 | #ifndef KCMP_FILE /* 3f4994cfc15f38a3159c6e3a4b3ab2e1481a6b02 (3.19) */ | |
23 | #define KCMP_FILE 0 | |
24 | #endif | |
25 | ||
4b9545f1 | 26 | #if !HAVE_PIVOT_ROOT |
5187dd2c | 27 | static inline int missing_pivot_root(const char *new_root, const char *put_old) { |
d06f3829 | 28 | return syscall(__NR_pivot_root, new_root, put_old); |
2f368e4a | 29 | } |
5187dd2c ZJS |
30 | |
31 | # define pivot_root missing_pivot_root | |
2f368e4a ZJS |
32 | #endif |
33 | ||
34 | /* ======================================================================= */ | |
35 | ||
5134e18e ZJS |
36 | #if defined __x86_64__ |
37 | # define systemd_NR_memfd_create 319 | |
38 | #elif defined __arm__ | |
39 | # define systemd_NR_memfd_create 385 | |
40 | #elif defined __aarch64__ | |
41 | # define systemd_NR_memfd_create 279 | |
af513d51 ZJS |
42 | #elif defined(__powerpc__) |
43 | # define systemd_NR_memfd_create 360 | |
5134e18e ZJS |
44 | #elif defined __s390__ |
45 | # define systemd_NR_memfd_create 350 | |
46 | #elif defined _MIPS_SIM | |
47 | # if _MIPS_SIM == _MIPS_SIM_ABI32 | |
48 | # define systemd_NR_memfd_create 4354 | |
49 | # endif | |
50 | # if _MIPS_SIM == _MIPS_SIM_NABI32 | |
51 | # define systemd_NR_memfd_create 6318 | |
52 | # endif | |
53 | # if _MIPS_SIM == _MIPS_SIM_ABI64 | |
54 | # define systemd_NR_memfd_create 5314 | |
55 | # endif | |
56 | #elif defined __i386__ | |
57 | # define systemd_NR_memfd_create 356 | |
58 | #elif defined __arc__ | |
59 | # define systemd_NR_memfd_create 279 | |
60 | #else | |
61 | # warning "memfd_create() syscall number unknown for your architecture" | |
62 | #endif | |
63 | ||
98418029 | 64 | /* may be (invalid) negative number due to libseccomp, see PR 13319 */ |
5134e18e ZJS |
65 | #if defined __NR_memfd_create && __NR_memfd_create >= 0 |
66 | # if defined systemd_NR_memfd_create | |
67 | assert_cc(__NR_memfd_create == systemd_NR_memfd_create); | |
68 | # endif | |
69 | #else | |
70 | # if defined __NR_memfd_create | |
71 | # undef __NR_memfd_create | |
72 | # endif | |
73 | # if defined systemd_NR_memfd_create | |
74 | # define __NR_memfd_create systemd_NR_memfd_create | |
2f368e4a | 75 | # endif |
5134e18e | 76 | #endif |
2f368e4a | 77 | |
5134e18e | 78 | #if !HAVE_MEMFD_CREATE |
5187dd2c | 79 | static inline int missing_memfd_create(const char *name, unsigned int flags) { |
2f368e4a ZJS |
80 | # ifdef __NR_memfd_create |
81 | return syscall(__NR_memfd_create, name, flags); | |
82 | # else | |
83 | errno = ENOSYS; | |
84 | return -1; | |
85 | # endif | |
86 | } | |
5187dd2c ZJS |
87 | |
88 | # define memfd_create missing_memfd_create | |
2f368e4a ZJS |
89 | #endif |
90 | ||
91 | /* ======================================================================= */ | |
92 | ||
5134e18e ZJS |
93 | #if defined __x86_64__ |
94 | # define systemd_NR_getrandom 318 | |
95 | #elif defined(__i386__) | |
96 | # define systemd_NR_getrandom 355 | |
97 | #elif defined(__arm__) | |
98 | # define systemd_NR_getrandom 384 | |
99 | #elif defined(__aarch64__) | |
100 | # define systemd_NR_getrandom 278 | |
101 | #elif defined(__ia64__) | |
102 | # define systemd_NR_getrandom 1339 | |
103 | #elif defined(__m68k__) | |
104 | # define systemd_NR_getrandom 352 | |
105 | #elif defined(__s390x__) | |
106 | # define systemd_NR_getrandom 349 | |
107 | #elif defined(__powerpc__) | |
108 | # define systemd_NR_getrandom 359 | |
109 | #elif defined _MIPS_SIM | |
110 | # if _MIPS_SIM == _MIPS_SIM_ABI32 | |
111 | # define systemd_NR_getrandom 4353 | |
112 | # endif | |
113 | # if _MIPS_SIM == _MIPS_SIM_NABI32 | |
114 | # define systemd_NR_getrandom 6317 | |
115 | # endif | |
116 | # if _MIPS_SIM == _MIPS_SIM_ABI64 | |
117 | # define systemd_NR_getrandom 5313 | |
118 | # endif | |
119 | #elif defined(__arc__) | |
120 | # define systemd_NR_getrandom 278 | |
121 | #else | |
122 | # warning "getrandom() syscall number unknown for your architecture" | |
123 | #endif | |
124 | ||
98418029 | 125 | /* may be (invalid) negative number due to libseccomp, see PR 13319 */ |
5134e18e ZJS |
126 | #if defined __NR_getrandom && __NR_getrandom >= 0 |
127 | # if defined systemd_NR_getrandom | |
128 | assert_cc(__NR_getrandom == systemd_NR_getrandom); | |
129 | # endif | |
130 | #else | |
131 | # if defined __NR_getrandom | |
132 | # undef __NR_getrandom | |
2f368e4a | 133 | # endif |
5134e18e ZJS |
134 | # if defined systemd_NR_getrandom |
135 | # define __NR_getrandom systemd_NR_getrandom | |
136 | # endif | |
137 | #endif | |
2f368e4a | 138 | |
5134e18e | 139 | #if !HAVE_GETRANDOM |
5187dd2c | 140 | static inline int missing_getrandom(void *buffer, size_t count, unsigned flags) { |
2f368e4a ZJS |
141 | # ifdef __NR_getrandom |
142 | return syscall(__NR_getrandom, buffer, count, flags); | |
143 | # else | |
144 | errno = ENOSYS; | |
145 | return -1; | |
146 | # endif | |
147 | } | |
5187dd2c ZJS |
148 | |
149 | # define getrandom missing_getrandom | |
2f368e4a ZJS |
150 | #endif |
151 | ||
152 | /* ======================================================================= */ | |
153 | ||
5134e18e | 154 | /* The syscall has been defined since forever, but the glibc wrapper was missing. */ |
4b9545f1 | 155 | #if !HAVE_GETTID |
5187dd2c | 156 | static inline pid_t missing_gettid(void) { |
5134e18e | 157 | # if defined __NR_gettid && __NR_gettid >= 0 |
d06f3829 | 158 | return (pid_t) syscall(__NR_gettid); |
5134e18e ZJS |
159 | # else |
160 | # error "__NR_gettid not defined" | |
161 | # endif | |
2f368e4a | 162 | } |
5187dd2c ZJS |
163 | |
164 | # define gettid missing_gettid | |
2f368e4a ZJS |
165 | #endif |
166 | ||
167 | /* ======================================================================= */ | |
168 | ||
5134e18e ZJS |
169 | #if defined(__x86_64__) |
170 | # define systemd_NR_name_to_handle_at 303 | |
171 | #elif defined(__i386__) | |
172 | # define systemd_NR_name_to_handle_at 341 | |
173 | #elif defined(__arm__) | |
174 | # define systemd_NR_name_to_handle_at 370 | |
af513d51 ZJS |
175 | #elif defined __aarch64__ |
176 | # define systemd_NR_name_to_handle_at 264 | |
5134e18e ZJS |
177 | #elif defined(__powerpc__) |
178 | # define systemd_NR_name_to_handle_at 345 | |
af513d51 ZJS |
179 | #elif defined __s390__ || defined __s390x__ |
180 | # define systemd_NR_name_to_handle_at 335 | |
5134e18e ZJS |
181 | #elif defined(__arc__) |
182 | # define systemd_NR_name_to_handle_at 264 | |
183 | #else | |
184 | # warning "name_to_handle_at number is not defined" | |
185 | #endif | |
186 | ||
98418029 | 187 | /* may be (invalid) negative number due to libseccomp, see PR 13319 */ |
5134e18e ZJS |
188 | #if defined __NR_name_to_handle_at && __NR_name_to_handle_at >= 0 |
189 | # if defined systemd_NR_name_to_handle_at | |
190 | assert_cc(__NR_name_to_handle_at == systemd_NR_name_to_handle_at); | |
191 | # endif | |
192 | #else | |
193 | # if defined __NR_name_to_handle_at | |
194 | # undef __NR_name_to_handle_at | |
195 | # endif | |
196 | # if defined systemd_NR_name_to_handle_at | |
197 | # define __NR_name_to_handle_at systemd_NR_name_to_handle_at | |
2f368e4a | 198 | # endif |
5134e18e | 199 | #endif |
2f368e4a | 200 | |
5134e18e | 201 | #if !HAVE_NAME_TO_HANDLE_AT |
2f368e4a ZJS |
202 | struct file_handle { |
203 | unsigned int handle_bytes; | |
204 | int handle_type; | |
205 | unsigned char f_handle[0]; | |
206 | }; | |
207 | ||
5187dd2c | 208 | static inline int missing_name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) { |
2f368e4a ZJS |
209 | # ifdef __NR_name_to_handle_at |
210 | return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags); | |
211 | # else | |
212 | errno = ENOSYS; | |
213 | return -1; | |
214 | # endif | |
215 | } | |
5187dd2c ZJS |
216 | |
217 | # define name_to_handle_at missing_name_to_handle_at | |
2f368e4a ZJS |
218 | #endif |
219 | ||
220 | /* ======================================================================= */ | |
221 | ||
af513d51 ZJS |
222 | #if defined __aarch64__ |
223 | # define systemd_NR_setns 268 | |
224 | #elif defined __arm__ | |
225 | # define systemd_NR_setns 375 | |
226 | #elif defined(__x86_64__) | |
5134e18e ZJS |
227 | # define systemd_NR_setns 308 |
228 | #elif defined(__i386__) | |
229 | # define systemd_NR_setns 346 | |
af513d51 ZJS |
230 | #elif defined(__powerpc__) |
231 | # define systemd_NR_setns 350 | |
232 | #elif defined __s390__ || defined __s390x__ | |
233 | # define systemd_NR_setns 339 | |
5134e18e ZJS |
234 | #elif defined(__arc__) |
235 | # define systemd_NR_setns 268 | |
236 | #else | |
237 | # warning "setns() syscall number unknown for your architecture" | |
238 | #endif | |
239 | ||
98418029 | 240 | /* may be (invalid) negative number due to libseccomp, see PR 13319 */ |
5134e18e ZJS |
241 | #if defined __NR_setns && __NR_setns >= 0 |
242 | # if defined systemd_NR_setns | |
243 | assert_cc(__NR_setns == systemd_NR_setns); | |
244 | # endif | |
245 | #else | |
246 | # if defined __NR_setns | |
247 | # undef __NR_setns | |
2f368e4a | 248 | # endif |
5134e18e ZJS |
249 | # if defined systemd_NR_setns |
250 | # define __NR_setns systemd_NR_setns | |
251 | # endif | |
252 | #endif | |
2f368e4a | 253 | |
5134e18e | 254 | #if !HAVE_SETNS |
5187dd2c | 255 | static inline int missing_setns(int fd, int nstype) { |
2f368e4a ZJS |
256 | # ifdef __NR_setns |
257 | return syscall(__NR_setns, fd, nstype); | |
258 | # else | |
259 | errno = ENOSYS; | |
260 | return -1; | |
261 | # endif | |
262 | } | |
5187dd2c ZJS |
263 | |
264 | # define setns missing_setns | |
2f368e4a ZJS |
265 | #endif |
266 | ||
267 | /* ======================================================================= */ | |
268 | ||
2f368e4a ZJS |
269 | static inline pid_t raw_getpid(void) { |
270 | #if defined(__alpha__) | |
271 | return (pid_t) syscall(__NR_getxpid); | |
272 | #else | |
273 | return (pid_t) syscall(__NR_getpid); | |
274 | #endif | |
275 | } | |
276 | ||
277 | /* ======================================================================= */ | |
278 | ||
5134e18e ZJS |
279 | #if defined __x86_64__ |
280 | # define systemd_NR_renameat2 316 | |
281 | #elif defined __arm__ | |
282 | # define systemd_NR_renameat2 382 | |
283 | #elif defined __aarch64__ | |
284 | # define systemd_NR_renameat2 276 | |
285 | #elif defined _MIPS_SIM | |
286 | # if _MIPS_SIM == _MIPS_SIM_ABI32 | |
287 | # define systemd_NR_renameat2 4351 | |
288 | # endif | |
289 | # if _MIPS_SIM == _MIPS_SIM_NABI32 | |
290 | # define systemd_NR_renameat2 6315 | |
291 | # endif | |
292 | # if _MIPS_SIM == _MIPS_SIM_ABI64 | |
293 | # define systemd_NR_renameat2 5311 | |
294 | # endif | |
295 | #elif defined __i386__ | |
296 | # define systemd_NR_renameat2 353 | |
297 | #elif defined __powerpc64__ | |
298 | # define systemd_NR_renameat2 357 | |
299 | #elif defined __s390__ || defined __s390x__ | |
300 | # define systemd_NR_renameat2 347 | |
301 | #elif defined __arc__ | |
302 | # define systemd_NR_renameat2 276 | |
303 | #else | |
304 | # warning "renameat2() syscall number unknown for your architecture" | |
305 | #endif | |
306 | ||
98418029 | 307 | /* may be (invalid) negative number due to libseccomp, see PR 13319 */ |
5134e18e ZJS |
308 | #if defined __NR_renameat2 && __NR_renameat2 >= 0 |
309 | # if defined systemd_NR_renameat2 | |
310 | assert_cc(__NR_renameat2 == systemd_NR_renameat2); | |
311 | # endif | |
312 | #else | |
313 | # if defined __NR_renameat2 | |
314 | # undef __NR_renameat2 | |
2f368e4a | 315 | # endif |
5134e18e ZJS |
316 | # if defined systemd_NR_renameat2 |
317 | # define __NR_renameat2 systemd_NR_renameat2 | |
318 | # endif | |
319 | #endif | |
2f368e4a | 320 | |
5134e18e | 321 | #if !HAVE_RENAMEAT2 |
5187dd2c | 322 | static inline int missing_renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) { |
2f368e4a ZJS |
323 | # ifdef __NR_renameat2 |
324 | return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags); | |
325 | # else | |
326 | errno = ENOSYS; | |
327 | return -1; | |
328 | # endif | |
329 | } | |
5187dd2c ZJS |
330 | |
331 | # define renameat2 missing_renameat2 | |
2f368e4a ZJS |
332 | #endif |
333 | ||
334 | /* ======================================================================= */ | |
335 | ||
4b9545f1 | 336 | #if !HAVE_KCMP |
5187dd2c | 337 | static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) { |
fb4b0465 | 338 | # if defined __NR_kcmp && __NR_kcmp >= 0 |
2f368e4a ZJS |
339 | return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2); |
340 | # else | |
341 | errno = ENOSYS; | |
342 | return -1; | |
343 | # endif | |
344 | } | |
5187dd2c ZJS |
345 | |
346 | # define kcmp missing_kcmp | |
2f368e4a ZJS |
347 | #endif |
348 | ||
349 | /* ======================================================================= */ | |
350 | ||
4b9545f1 | 351 | #if !HAVE_KEYCTL |
851d66fa | 352 | static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) { |
fb4b0465 | 353 | # if defined __NR_keyctl && __NR_keyctl >= 0 |
2f368e4a ZJS |
354 | return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5); |
355 | # else | |
356 | errno = ENOSYS; | |
357 | return -1; | |
358 | # endif | |
5187dd2c ZJS |
359 | |
360 | # define keyctl missing_keyctl | |
2f368e4a ZJS |
361 | } |
362 | ||
5187dd2c | 363 | static inline key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) { |
fb4b0465 | 364 | # if defined __NR_add_key && __NR_add_key >= 0 |
2f368e4a ZJS |
365 | return syscall(__NR_add_key, type, description, payload, plen, ringid); |
366 | # else | |
367 | errno = ENOSYS; | |
368 | return -1; | |
369 | # endif | |
5187dd2c ZJS |
370 | |
371 | # define add_key missing_add_key | |
2f368e4a ZJS |
372 | } |
373 | ||
5187dd2c | 374 | static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) { |
fb4b0465 | 375 | # if defined __NR_request_key && __NR_request_key >= 0 |
2f368e4a ZJS |
376 | return syscall(__NR_request_key, type, description, callout_info, destringid); |
377 | # else | |
378 | errno = ENOSYS; | |
379 | return -1; | |
380 | # endif | |
5187dd2c ZJS |
381 | |
382 | # define request_key missing_request_key | |
2f368e4a ZJS |
383 | } |
384 | #endif | |
385 | ||
386 | /* ======================================================================= */ | |
387 | ||
5134e18e ZJS |
388 | #if defined(__x86_64__) |
389 | # define systemd_NR_copy_file_range 326 | |
390 | #elif defined(__i386__) | |
391 | # define systemd_NR_copy_file_range 377 | |
392 | #elif defined __s390__ | |
393 | # define systemd_NR_copy_file_range 375 | |
394 | #elif defined __arm__ | |
395 | # define systemd_NR_copy_file_range 391 | |
396 | #elif defined __aarch64__ | |
397 | # define systemd_NR_copy_file_range 285 | |
398 | #elif defined __powerpc__ | |
399 | # define systemd_NR_copy_file_range 379 | |
400 | #elif defined __arc__ | |
401 | # define systemd_NR_copy_file_range 285 | |
402 | #else | |
403 | # warning "copy_file_range() syscall number unknown for your architecture" | |
404 | #endif | |
405 | ||
98418029 | 406 | /* may be (invalid) negative number due to libseccomp, see PR 13319 */ |
5134e18e ZJS |
407 | #if defined __NR_copy_file_range && __NR_copy_file_range >= 0 |
408 | # if defined systemd_NR_copy_file_range | |
409 | assert_cc(__NR_copy_file_range == systemd_NR_copy_file_range); | |
2f368e4a | 410 | # endif |
5134e18e ZJS |
411 | #else |
412 | # if defined __NR_copy_file_range | |
413 | # undef __NR_copy_file_range | |
414 | # endif | |
415 | # if defined systemd_NR_copy_file_range | |
416 | # define __NR_copy_file_range systemd_NR_copy_file_range | |
417 | # endif | |
418 | #endif | |
2f368e4a | 419 | |
5134e18e | 420 | #if !HAVE_COPY_FILE_RANGE |
5187dd2c ZJS |
421 | static inline ssize_t missing_copy_file_range(int fd_in, loff_t *off_in, |
422 | int fd_out, loff_t *off_out, | |
423 | size_t len, | |
424 | unsigned int flags) { | |
2f368e4a ZJS |
425 | # ifdef __NR_copy_file_range |
426 | return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags); | |
427 | # else | |
428 | errno = ENOSYS; | |
429 | return -1; | |
430 | # endif | |
431 | } | |
5187dd2c ZJS |
432 | |
433 | # define copy_file_range missing_copy_file_range | |
2f368e4a | 434 | #endif |
71e5200f | 435 | |
213f2883 ZJS |
436 | /* ======================================================================= */ |
437 | ||
5134e18e ZJS |
438 | #if defined __i386__ |
439 | # define systemd_NR_bpf 357 | |
440 | #elif defined __x86_64__ | |
441 | # define systemd_NR_bpf 321 | |
442 | #elif defined __aarch64__ | |
443 | # define systemd_NR_bpf 280 | |
444 | #elif defined __arm__ | |
445 | # define systemd_NR_bpf 386 | |
af513d51 ZJS |
446 | #elif defined(__powerpc__) |
447 | # define systemd_NR_bpf 361 | |
5134e18e ZJS |
448 | #elif defined __sparc__ |
449 | # define systemd_NR_bpf 349 | |
450 | #elif defined __s390__ | |
451 | # define systemd_NR_bpf 351 | |
452 | #elif defined __tilegx__ | |
453 | # define systemd_NR_bpf 280 | |
454 | #else | |
455 | # warning "bpf() syscall number unknown for your architecture" | |
456 | #endif | |
457 | ||
98418029 | 458 | /* may be (invalid) negative number due to libseccomp, see PR 13319 */ |
5134e18e ZJS |
459 | #if defined __NR_bpf && __NR_bpf >= 0 |
460 | # if defined systemd_NR_bpf | |
461 | assert_cc(__NR_bpf == systemd_NR_bpf); | |
462 | # endif | |
463 | #else | |
464 | # if defined __NR_bpf | |
465 | # undef __NR_bpf | |
71e5200f | 466 | # endif |
5134e18e ZJS |
467 | # if defined systemd_NR_bpf |
468 | # define __NR_bpf systemd_NR_bpf | |
469 | # endif | |
470 | #endif | |
71e5200f | 471 | |
5134e18e | 472 | #if !HAVE_BPF |
71e5200f DM |
473 | union bpf_attr; |
474 | ||
5187dd2c | 475 | static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) { |
71e5200f DM |
476 | #ifdef __NR_bpf |
477 | return (int) syscall(__NR_bpf, cmd, attr, size); | |
478 | #else | |
479 | errno = ENOSYS; | |
480 | return -1; | |
481 | #endif | |
482 | } | |
483 | ||
5187dd2c | 484 | # define bpf missing_bpf |
71e5200f | 485 | #endif |
213f2883 ZJS |
486 | |
487 | /* ======================================================================= */ | |
488 | ||
489 | #ifndef __IGNORE_pkey_mprotect | |
5134e18e ZJS |
490 | # if defined __i386__ |
491 | # define systemd_NR_pkey_mprotect 380 | |
492 | # elif defined __x86_64__ | |
493 | # define systemd_NR_pkey_mprotect 329 | |
5134e18e | 494 | # elif defined __aarch64__ |
b6ce3d2c ZJS |
495 | # define systemd_NR_pkey_mprotect 288 |
496 | # elif defined __arm__ | |
5134e18e ZJS |
497 | # define systemd_NR_pkey_mprotect 394 |
498 | # elif defined __powerpc__ | |
499 | # define systemd_NR_pkey_mprotect 386 | |
500 | # elif defined __s390__ | |
501 | # define systemd_NR_pkey_mprotect 384 | |
502 | # elif defined _MIPS_SIM | |
503 | # if _MIPS_SIM == _MIPS_SIM_ABI32 | |
504 | # define systemd_NR_pkey_mprotect 4363 | |
505 | # endif | |
506 | # if _MIPS_SIM == _MIPS_SIM_NABI32 | |
507 | # define systemd_NR_pkey_mprotect 6327 | |
508 | # endif | |
509 | # if _MIPS_SIM == _MIPS_SIM_ABI64 | |
510 | # define systemd_NR_pkey_mprotect 5323 | |
511 | # endif | |
512 | # else | |
513 | # warning "pkey_mprotect() syscall number unknown for your architecture" | |
514 | # endif | |
515 | ||
98418029 | 516 | /* may be (invalid) negative number due to libseccomp, see PR 13319 */ |
5134e18e ZJS |
517 | # if defined __NR_pkey_mprotect && __NR_pkey_mprotect >= 0 |
518 | # if defined systemd_NR_pkey_mprotect | |
519 | assert_cc(__NR_pkey_mprotect == systemd_NR_pkey_mprotect); | |
520 | # endif | |
521 | # else | |
59b65729 DS |
522 | # if defined __NR_pkey_mprotect |
523 | # undef __NR_pkey_mprotect | |
524 | # endif | |
5134e18e ZJS |
525 | # if defined systemd_NR_pkey_mprotect |
526 | # define __NR_pkey_mprotect systemd_NR_pkey_mprotect | |
213f2883 ZJS |
527 | # endif |
528 | # endif | |
529 | #endif | |
4c2e1b39 | 530 | |
5187dd2c ZJS |
531 | /* ======================================================================= */ |
532 | ||
b6ce3d2c ZJS |
533 | #if defined __aarch64__ |
534 | # define systemd_NR_statx 291 | |
535 | #elif defined __arm__ | |
5134e18e ZJS |
536 | # define systemd_NR_statx 397 |
537 | #elif defined __alpha__ | |
538 | # define systemd_NR_statx 522 | |
539 | #elif defined __i386__ || defined __powerpc64__ | |
540 | # define systemd_NR_statx 383 | |
af513d51 ZJS |
541 | #elif defined __s390__ || defined __s390x__ |
542 | # define systemd_NR_statx 379 | |
5134e18e ZJS |
543 | #elif defined __sparc__ |
544 | # define systemd_NR_statx 360 | |
545 | #elif defined __x86_64__ | |
546 | # define systemd_NR_statx 332 | |
547 | #else | |
548 | # warning "statx() syscall number unknown for your architecture" | |
549 | #endif | |
550 | ||
98418029 | 551 | /* may be (invalid) negative number due to libseccomp, see PR 13319 */ |
5134e18e ZJS |
552 | #if defined __NR_statx && __NR_statx >= 0 |
553 | # if defined systemd_NR_statx | |
554 | assert_cc(__NR_statx == systemd_NR_statx); | |
555 | # endif | |
556 | #else | |
557 | # if defined __NR_statx | |
558 | # undef __NR_statx | |
559 | # endif | |
560 | # if defined systemd_NR_statx | |
561 | # define __NR_statx systemd_NR_statx | |
4c2e1b39 | 562 | # endif |
5187dd2c ZJS |
563 | #endif |
564 | ||
5187dd2c | 565 | #if !HAVE_STATX |
5134e18e ZJS |
566 | struct statx; |
567 | ||
5187dd2c | 568 | static inline ssize_t missing_statx(int dfd, const char *filename, unsigned flags, unsigned int mask, struct statx *buffer) { |
4c2e1b39 LP |
569 | # ifdef __NR_statx |
570 | return syscall(__NR_statx, dfd, filename, flags, mask, buffer); | |
571 | # else | |
572 | errno = ENOSYS; | |
573 | return -1; | |
574 | # endif | |
575 | } | |
5134e18e ZJS |
576 | #endif |
577 | ||
578 | /* This typedef is supposed to be always defined. */ | |
579 | typedef struct statx struct_statx; | |
5187dd2c | 580 | |
5134e18e | 581 | #if !HAVE_STATX |
69b3fa14 | 582 | # define statx(dfd, filename, flags, mask, buffer) missing_statx(dfd, filename, flags, mask, buffer) |
4c2e1b39 | 583 | #endif |
b070c7c0 | 584 | |
5134e18e | 585 | /* ======================================================================= */ |
b070c7c0 | 586 | |
5134e18e | 587 | #if !HAVE_SET_MEMPOLICY |
b070c7c0 MS |
588 | enum { |
589 | MPOL_DEFAULT, | |
590 | MPOL_PREFERRED, | |
591 | MPOL_BIND, | |
592 | MPOL_INTERLEAVE, | |
593 | MPOL_LOCAL, | |
594 | }; | |
595 | ||
596 | static inline long missing_set_mempolicy(int mode, const unsigned long *nodemask, | |
597 | unsigned long maxnode) { | |
598 | long i; | |
fb4b0465 | 599 | # if defined __NR_set_mempolicy && __NR_set_mempolicy >= 0 |
b070c7c0 MS |
600 | i = syscall(__NR_set_mempolicy, mode, nodemask, maxnode); |
601 | # else | |
602 | errno = ENOSYS; | |
603 | i = -1; | |
604 | # endif | |
605 | return i; | |
606 | } | |
607 | ||
608 | # define set_mempolicy missing_set_mempolicy | |
609 | #endif | |
610 | ||
b070c7c0 MS |
611 | #if !HAVE_GET_MEMPOLICY |
612 | static inline long missing_get_mempolicy(int *mode, unsigned long *nodemask, | |
613 | unsigned long maxnode, void *addr, | |
614 | unsigned long flags) { | |
615 | long i; | |
0e682411 | 616 | # if defined __NR_get_mempolicy && __NR_get_mempolicy >= 0 |
b070c7c0 MS |
617 | i = syscall(__NR_get_mempolicy, mode, nodemask, maxnode, addr, flags); |
618 | # else | |
619 | errno = ENOSYS; | |
620 | i = -1; | |
621 | # endif | |
622 | return i; | |
623 | } | |
624 | ||
faeae444 | 625 | # define get_mempolicy missing_get_mempolicy |
b070c7c0 | 626 | #endif |
5f152f43 | 627 | |
5134e18e ZJS |
628 | /* ======================================================================= */ |
629 | ||
23654cee | 630 | /* should be always defined, see kernel 39036cd2727395c3369b1051005da74059a85317 */ |
5134e18e ZJS |
631 | #if defined(__alpha__) |
632 | # define systemd_NR_pidfd_send_signal 534 | |
633 | #else | |
634 | # define systemd_NR_pidfd_send_signal 424 | |
635 | #endif | |
636 | ||
637 | /* may be (invalid) negative number due to libseccomp, see PR 13319 */ | |
638 | #if defined __NR_pidfd_send_signal && __NR_pidfd_send_signal >= 0 | |
639 | # if defined systemd_NR_pidfd_send_signal | |
640 | assert_cc(__NR_pidfd_send_signal == systemd_NR_pidfd_send_signal); | |
23654cee | 641 | # endif |
5134e18e ZJS |
642 | #else |
643 | # if defined __NR_pidfd_send_signal | |
644 | # undef __NR_pidfd_send_signal | |
645 | # endif | |
646 | # define __NR_pidfd_send_signal systemd_NR_pidfd_send_signal | |
647 | #endif | |
648 | ||
649 | #if !HAVE_PIDFD_SEND_SIGNAL | |
faeae444 | 650 | static inline int missing_pidfd_send_signal(int fd, int sig, siginfo_t *info, unsigned flags) { |
23654cee | 651 | # ifdef __NR_pidfd_open |
5f152f43 | 652 | return syscall(__NR_pidfd_send_signal, fd, sig, info, flags); |
23654cee | 653 | # else |
5f152f43 LP |
654 | errno = ENOSYS; |
655 | return -1; | |
23654cee ZJS |
656 | # endif |
657 | } | |
faeae444 ZJS |
658 | |
659 | # define pidfd_send_signal missing_pidfd_send_signal | |
5f152f43 | 660 | #endif |
23654cee | 661 | |
23654cee | 662 | /* should be always defined, see kernel 7615d9e1780e26e0178c93c55b73309a5dc093d7 */ |
5134e18e ZJS |
663 | #if defined(__alpha__) |
664 | # define systemd_NR_pidfd_open 544 | |
665 | #else | |
666 | # define systemd_NR_pidfd_open 434 | |
667 | #endif | |
668 | ||
669 | /* may be (invalid) negative number due to libseccomp, see PR 13319 */ | |
670 | #if defined __NR_pidfd_open && __NR_pidfd_open >= 0 | |
671 | # if defined systemd_NR_pidfd_open | |
672 | assert_cc(__NR_pidfd_open == systemd_NR_pidfd_open); | |
23654cee | 673 | # endif |
5134e18e ZJS |
674 | #else |
675 | # if defined __NR_pidfd_open | |
676 | # undef __NR_pidfd_open | |
677 | # endif | |
678 | # define __NR_pidfd_open systemd_NR_pidfd_open | |
679 | #endif | |
680 | ||
681 | #if !HAVE_PIDFD_OPEN | |
faeae444 | 682 | static inline int missing_pidfd_open(pid_t pid, unsigned flags) { |
23654cee ZJS |
683 | # ifdef __NR_pidfd_open |
684 | return syscall(__NR_pidfd_open, pid, flags); | |
685 | # else | |
686 | errno = ENOSYS; | |
687 | return -1; | |
688 | # endif | |
5f152f43 | 689 | } |
faeae444 ZJS |
690 | |
691 | # define pidfd_open missing_pidfd_open | |
5f152f43 | 692 | #endif |
5ead4e85 | 693 | |
5134e18e ZJS |
694 | /* ======================================================================= */ |
695 | ||
5ead4e85 | 696 | #if !HAVE_RT_SIGQUEUEINFO |
faeae444 | 697 | static inline int missing_rt_sigqueueinfo(pid_t tgid, int sig, siginfo_t *info) { |
5134e18e | 698 | # if defined __NR_rt_sigqueueinfo && __NR_rt_sigqueueinfo >= 0 |
5ead4e85 | 699 | return syscall(__NR_rt_sigqueueinfo, tgid, sig, info); |
5134e18e ZJS |
700 | # else |
701 | # error "__NR_rt_sigqueueinfo not defined" | |
702 | # endif | |
5ead4e85 | 703 | } |
faeae444 ZJS |
704 | |
705 | # define rt_sigqueueinfo missing_rt_sigqueueinfo | |
5ead4e85 | 706 | #endif |