]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/missing_syscall.h
tools/make-man-index: fix purpose text that contains tags
[thirdparty/systemd.git] / src / basic / missing_syscall.h
CommitLineData
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 27static 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
4b9545f1 36#if !HAVE_MEMFD_CREATE
98418029 37/* may be (invalid) negative number due to libseccomp, see PR 13319 */
fb4b0465 38# if ! (defined __NR_memfd_create && __NR_memfd_create >= 0)
59b65729
DS
39# if defined __NR_memfd_create
40# undef __NR_memfd_create
41# endif
2f368e4a
ZJS
42# if defined __x86_64__
43# define __NR_memfd_create 319
44# elif defined __arm__
45# define __NR_memfd_create 385
46# elif defined __aarch64__
47# define __NR_memfd_create 279
48# elif defined __s390__
49# define __NR_memfd_create 350
50# elif defined _MIPS_SIM
51# if _MIPS_SIM == _MIPS_SIM_ABI32
52# define __NR_memfd_create 4354
53# endif
54# if _MIPS_SIM == _MIPS_SIM_NABI32
55# define __NR_memfd_create 6318
56# endif
57# if _MIPS_SIM == _MIPS_SIM_ABI64
58# define __NR_memfd_create 5314
59# endif
60# elif defined __i386__
61# define __NR_memfd_create 356
27b09f1f
AB
62# elif defined __arc__
63# define __NR_memfd_create 279
2f368e4a
ZJS
64# else
65# warning "__NR_memfd_create unknown for your architecture"
66# endif
67# endif
68
5187dd2c 69static inline int missing_memfd_create(const char *name, unsigned int flags) {
2f368e4a
ZJS
70# ifdef __NR_memfd_create
71 return syscall(__NR_memfd_create, name, flags);
72# else
73 errno = ENOSYS;
74 return -1;
75# endif
76}
5187dd2c
ZJS
77
78# define memfd_create missing_memfd_create
2f368e4a
ZJS
79#endif
80
81/* ======================================================================= */
82
4b9545f1 83#if !HAVE_GETRANDOM
98418029 84/* may be (invalid) negative number due to libseccomp, see PR 13319 */
fb4b0465 85# if ! (defined __NR_getrandom && __NR_getrandom >= 0)
59b65729
DS
86# if defined __NR_getrandom
87# undef __NR_getrandom
88# endif
2f368e4a
ZJS
89# if defined __x86_64__
90# define __NR_getrandom 318
91# elif defined(__i386__)
92# define __NR_getrandom 355
93# elif defined(__arm__)
94# define __NR_getrandom 384
95# elif defined(__aarch64__)
96# define __NR_getrandom 278
97# elif defined(__ia64__)
98# define __NR_getrandom 1339
99# elif defined(__m68k__)
100# define __NR_getrandom 352
101# elif defined(__s390x__)
102# define __NR_getrandom 349
103# elif defined(__powerpc__)
104# define __NR_getrandom 359
105# elif defined _MIPS_SIM
106# if _MIPS_SIM == _MIPS_SIM_ABI32
107# define __NR_getrandom 4353
108# endif
109# if _MIPS_SIM == _MIPS_SIM_NABI32
110# define __NR_getrandom 6317
111# endif
112# if _MIPS_SIM == _MIPS_SIM_ABI64
113# define __NR_getrandom 5313
114# endif
27b09f1f
AB
115# elif defined(__arc__)
116# define __NR_getrandom 278
2f368e4a
ZJS
117# else
118# warning "__NR_getrandom unknown for your architecture"
119# endif
120# endif
121
5187dd2c 122static inline int missing_getrandom(void *buffer, size_t count, unsigned flags) {
2f368e4a
ZJS
123# ifdef __NR_getrandom
124 return syscall(__NR_getrandom, buffer, count, flags);
125# else
126 errno = ENOSYS;
127 return -1;
128# endif
129}
5187dd2c
ZJS
130
131# define getrandom missing_getrandom
2f368e4a
ZJS
132#endif
133
134/* ======================================================================= */
135
4b9545f1 136#if !HAVE_GETTID
5187dd2c 137static inline pid_t missing_gettid(void) {
d06f3829 138 return (pid_t) syscall(__NR_gettid);
2f368e4a 139}
5187dd2c
ZJS
140
141# define gettid missing_gettid
2f368e4a
ZJS
142#endif
143
144/* ======================================================================= */
145
4b9545f1 146#if !HAVE_NAME_TO_HANDLE_AT
98418029 147/* may be (invalid) negative number due to libseccomp, see PR 13319 */
fb4b0465 148# if ! (defined __NR_name_to_handle_at && __NR_name_to_handle_at >= 0)
59b65729
DS
149# if defined __NR_name_to_handle_at
150# undef __NR_name_to_handle_at
151# endif
2f368e4a
ZJS
152# if defined(__x86_64__)
153# define __NR_name_to_handle_at 303
154# elif defined(__i386__)
155# define __NR_name_to_handle_at 341
156# elif defined(__arm__)
157# define __NR_name_to_handle_at 370
158# elif defined(__powerpc__)
159# define __NR_name_to_handle_at 345
27b09f1f
AB
160# elif defined(__arc__)
161# define __NR_name_to_handle_at 264
2f368e4a
ZJS
162# else
163# error "__NR_name_to_handle_at is not defined"
164# endif
165# endif
166
167struct file_handle {
168 unsigned int handle_bytes;
169 int handle_type;
170 unsigned char f_handle[0];
171};
172
5187dd2c 173static inline int missing_name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
2f368e4a
ZJS
174# ifdef __NR_name_to_handle_at
175 return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
176# else
177 errno = ENOSYS;
178 return -1;
179# endif
180}
5187dd2c
ZJS
181
182# define name_to_handle_at missing_name_to_handle_at
2f368e4a
ZJS
183#endif
184
185/* ======================================================================= */
186
4b9545f1 187#if !HAVE_SETNS
98418029 188/* may be (invalid) negative number due to libseccomp, see PR 13319 */
fb4b0465 189# if ! (defined __NR_setns && __NR_setns >= 0)
59b65729
DS
190# if defined __NR_setns
191# undef __NR_setns
192# endif
2f368e4a
ZJS
193# if defined(__x86_64__)
194# define __NR_setns 308
195# elif defined(__i386__)
196# define __NR_setns 346
27b09f1f
AB
197# elif defined(__arc__)
198# define __NR_setns 268
2f368e4a
ZJS
199# else
200# error "__NR_setns is not defined"
201# endif
202# endif
203
5187dd2c 204static inline int missing_setns(int fd, int nstype) {
2f368e4a
ZJS
205# ifdef __NR_setns
206 return syscall(__NR_setns, fd, nstype);
207# else
208 errno = ENOSYS;
209 return -1;
210# endif
211}
5187dd2c
ZJS
212
213# define setns missing_setns
2f368e4a
ZJS
214#endif
215
216/* ======================================================================= */
217
2f368e4a
ZJS
218static inline pid_t raw_getpid(void) {
219#if defined(__alpha__)
220 return (pid_t) syscall(__NR_getxpid);
221#else
222 return (pid_t) syscall(__NR_getpid);
223#endif
224}
225
226/* ======================================================================= */
227
4b9545f1 228#if !HAVE_RENAMEAT2
98418029 229/* may be (invalid) negative number due to libseccomp, see PR 13319 */
fb4b0465 230# if ! (defined __NR_renameat2 && __NR_renameat2 >= 0)
59b65729
DS
231# if defined __NR_renameat2
232# undef __NR_renameat2
233# endif
2f368e4a
ZJS
234# if defined __x86_64__
235# define __NR_renameat2 316
236# elif defined __arm__
237# define __NR_renameat2 382
925c81cd
LP
238# elif defined __aarch64__
239# define __NR_renameat2 276
2f368e4a
ZJS
240# elif defined _MIPS_SIM
241# if _MIPS_SIM == _MIPS_SIM_ABI32
242# define __NR_renameat2 4351
243# endif
244# if _MIPS_SIM == _MIPS_SIM_NABI32
245# define __NR_renameat2 6315
246# endif
247# if _MIPS_SIM == _MIPS_SIM_ABI64
248# define __NR_renameat2 5311
249# endif
250# elif defined __i386__
251# define __NR_renameat2 353
92369d5e
ZJS
252# elif defined __powerpc64__
253# define __NR_renameat2 357
254# elif defined __s390__ || defined __s390x__
255# define __NR_renameat2 347
27b09f1f
AB
256# elif defined __arc__
257# define __NR_renameat2 276
2f368e4a
ZJS
258# else
259# warning "__NR_renameat2 unknown for your architecture"
260# endif
261# endif
262
5187dd2c 263static inline int missing_renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
2f368e4a
ZJS
264# ifdef __NR_renameat2
265 return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
266# else
267 errno = ENOSYS;
268 return -1;
269# endif
270}
5187dd2c
ZJS
271
272# define renameat2 missing_renameat2
2f368e4a
ZJS
273#endif
274
275/* ======================================================================= */
276
4b9545f1 277#if !HAVE_KCMP
5187dd2c 278static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
fb4b0465 279# if defined __NR_kcmp && __NR_kcmp >= 0
2f368e4a
ZJS
280 return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
281# else
282 errno = ENOSYS;
283 return -1;
284# endif
285}
5187dd2c
ZJS
286
287# define kcmp missing_kcmp
2f368e4a
ZJS
288#endif
289
290/* ======================================================================= */
291
4b9545f1 292#if !HAVE_KEYCTL
851d66fa 293static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) {
fb4b0465 294# if defined __NR_keyctl && __NR_keyctl >= 0
2f368e4a
ZJS
295 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
296# else
297 errno = ENOSYS;
298 return -1;
299# endif
5187dd2c
ZJS
300
301# define keyctl missing_keyctl
2f368e4a
ZJS
302}
303
5187dd2c 304static inline key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
fb4b0465 305# if defined __NR_add_key && __NR_add_key >= 0
2f368e4a
ZJS
306 return syscall(__NR_add_key, type, description, payload, plen, ringid);
307# else
308 errno = ENOSYS;
309 return -1;
310# endif
5187dd2c
ZJS
311
312# define add_key missing_add_key
2f368e4a
ZJS
313}
314
5187dd2c 315static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
fb4b0465 316# if defined __NR_request_key && __NR_request_key >= 0
2f368e4a
ZJS
317 return syscall(__NR_request_key, type, description, callout_info, destringid);
318# else
319 errno = ENOSYS;
320 return -1;
321# endif
5187dd2c
ZJS
322
323# define request_key missing_request_key
2f368e4a
ZJS
324}
325#endif
326
327/* ======================================================================= */
328
4b9545f1 329#if !HAVE_COPY_FILE_RANGE
98418029 330/* may be (invalid) negative number due to libseccomp, see PR 13319 */
fb4b0465 331# if ! (defined __NR_copy_file_range && __NR_copy_file_range >= 0)
59b65729
DS
332# if defined __NR_copy_file_range
333# undef __NR_copy_file_range
334# endif
2f368e4a
ZJS
335# if defined(__x86_64__)
336# define __NR_copy_file_range 326
337# elif defined(__i386__)
338# define __NR_copy_file_range 377
339# elif defined __s390__
340# define __NR_copy_file_range 375
341# elif defined __arm__
342# define __NR_copy_file_range 391
343# elif defined __aarch64__
344# define __NR_copy_file_range 285
4d07c8d3
AIB
345# elif defined __powerpc__
346# define __NR_copy_file_range 379
27b09f1f
AB
347# elif defined __arc__
348# define __NR_copy_file_range 285
2f368e4a
ZJS
349# else
350# warning "__NR_copy_file_range not defined for your architecture"
351# endif
352# endif
353
5187dd2c
ZJS
354static inline ssize_t missing_copy_file_range(int fd_in, loff_t *off_in,
355 int fd_out, loff_t *off_out,
356 size_t len,
357 unsigned int flags) {
2f368e4a
ZJS
358# ifdef __NR_copy_file_range
359 return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags);
360# else
361 errno = ENOSYS;
362 return -1;
363# endif
364}
5187dd2c
ZJS
365
366# define copy_file_range missing_copy_file_range
2f368e4a 367#endif
71e5200f 368
213f2883
ZJS
369/* ======================================================================= */
370
4b9545f1 371#if !HAVE_BPF
98418029 372/* may be (invalid) negative number due to libseccomp, see PR 13319 */
fb4b0465 373# if ! (defined __NR_bpf && __NR_bpf >= 0)
59b65729
DS
374# if defined __NR_bpf
375# undef __NR_bpf
376# endif
71e5200f
DM
377# if defined __i386__
378# define __NR_bpf 357
379# elif defined __x86_64__
380# define __NR_bpf 321
381# elif defined __aarch64__
382# define __NR_bpf 280
d07ba5d7
HCNE
383# elif defined __arm__
384# define __NR_bpf 386
71e5200f
DM
385# elif defined __sparc__
386# define __NR_bpf 349
387# elif defined __s390__
388# define __NR_bpf 351
66ffb275
HCNE
389# elif defined __tilegx__
390# define __NR_bpf 280
71e5200f
DM
391# else
392# warning "__NR_bpf not defined for your architecture"
393# endif
394# endif
395
396union bpf_attr;
397
5187dd2c 398static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) {
71e5200f
DM
399#ifdef __NR_bpf
400 return (int) syscall(__NR_bpf, cmd, attr, size);
401#else
402 errno = ENOSYS;
403 return -1;
404#endif
405}
406
5187dd2c 407# define bpf missing_bpf
71e5200f 408#endif
213f2883
ZJS
409
410/* ======================================================================= */
411
412#ifndef __IGNORE_pkey_mprotect
98418029 413/* may be (invalid) negative number due to libseccomp, see PR 13319 */
fb4b0465 414# if ! (defined __NR_pkey_mprotect && __NR_pkey_mprotect >= 0)
59b65729
DS
415# if defined __NR_pkey_mprotect
416# undef __NR_pkey_mprotect
417# endif
213f2883
ZJS
418# if defined __i386__
419# define __NR_pkey_mprotect 380
420# elif defined __x86_64__
421# define __NR_pkey_mprotect 329
422# elif defined __arm__
423# define __NR_pkey_mprotect 394
424# elif defined __aarch64__
425# define __NR_pkey_mprotect 394
033c8366
ZJS
426# elif defined __powerpc__
427# define __NR_pkey_mprotect 386
4f6d0cf8
DS
428# elif defined __s390__
429# define __NR_pkey_mprotect 384
213f2883
ZJS
430# elif defined _MIPS_SIM
431# if _MIPS_SIM == _MIPS_SIM_ABI32
432# define __NR_pkey_mprotect 4363
433# endif
434# if _MIPS_SIM == _MIPS_SIM_NABI32
435# define __NR_pkey_mprotect 6327
436# endif
437# if _MIPS_SIM == _MIPS_SIM_ABI64
438# define __NR_pkey_mprotect 5323
439# endif
9c6888ac 440# else
213f2883
ZJS
441# warning "__NR_pkey_mprotect not defined for your architecture"
442# endif
443# endif
444#endif
4c2e1b39 445
5187dd2c
ZJS
446/* ======================================================================= */
447
4c2e1b39 448#if !HAVE_STATX
98418029 449/* may be (invalid) negative number due to libseccomp, see PR 13319 */
fb4b0465 450# if ! (defined __NR_statx && __NR_statx >= 0)
59b65729
DS
451# if defined __NR_statx
452# undef __NR_statx
453# endif
773c8434
AD
454# if defined __aarch64__ || defined __arm__
455# define __NR_statx 397
456# elif defined __alpha__
457# define __NR_statx 522
458# elif defined __i386__ || defined __powerpc64__
fd91e3ef 459# define __NR_statx 383
773c8434
AD
460# elif defined __sparc__
461# define __NR_statx 360
4c2e1b39 462# elif defined __x86_64__
fd91e3ef 463# define __NR_statx 332
4c2e1b39
LP
464# else
465# warning "__NR_statx not defined for your architecture"
466# endif
467# endif
468
469struct statx;
5187dd2c
ZJS
470#endif
471
472/* This typedef is supposed to be always defined. */
473typedef struct statx struct_statx;
4c2e1b39 474
5187dd2c
ZJS
475#if !HAVE_STATX
476static inline ssize_t missing_statx(int dfd, const char *filename, unsigned flags, unsigned int mask, struct statx *buffer) {
4c2e1b39
LP
477# ifdef __NR_statx
478 return syscall(__NR_statx, dfd, filename, flags, mask, buffer);
479# else
480 errno = ENOSYS;
481 return -1;
482# endif
483}
5187dd2c
ZJS
484
485# define statx missing_statx
4c2e1b39 486#endif
b070c7c0
MS
487
488#if !HAVE_SET_MEMPOLICY
489
490enum {
491 MPOL_DEFAULT,
492 MPOL_PREFERRED,
493 MPOL_BIND,
494 MPOL_INTERLEAVE,
495 MPOL_LOCAL,
496};
497
498static inline long missing_set_mempolicy(int mode, const unsigned long *nodemask,
499 unsigned long maxnode) {
500 long i;
fb4b0465 501# if defined __NR_set_mempolicy && __NR_set_mempolicy >= 0
b070c7c0
MS
502 i = syscall(__NR_set_mempolicy, mode, nodemask, maxnode);
503# else
504 errno = ENOSYS;
505 i = -1;
506# endif
507 return i;
508}
509
510# define set_mempolicy missing_set_mempolicy
511#endif
512
b070c7c0
MS
513#if !HAVE_GET_MEMPOLICY
514static inline long missing_get_mempolicy(int *mode, unsigned long *nodemask,
515 unsigned long maxnode, void *addr,
516 unsigned long flags) {
517 long i;
518# ifdef __NR_get_mempolicy
519 i = syscall(__NR_get_mempolicy, mode, nodemask, maxnode, addr, flags);
520# else
521 errno = ENOSYS;
522 i = -1;
523# endif
524 return i;
525}
526
527#define get_mempolicy missing_get_mempolicy
528#endif
5f152f43
LP
529
530#if !HAVE_PIDFD_OPEN
531/* may be (invalid) negative number due to libseccomp, see PR 13319 */
fb4b0465 532# if ! (defined __NR_pidfd_open && __NR_pidfd_open >= 0)
5f152f43
LP
533# if defined __NR_pidfd_open
534# undef __NR_pidfd_open
535# endif
536# define __NR_pidfd_open 434
537#endif
538static inline int pidfd_open(pid_t pid, unsigned flags) {
539#ifdef __NR_pidfd_open
540 return syscall(__NR_pidfd_open, pid, flags);
541#else
542 errno = ENOSYS;
543 return -1;
544#endif
545}
546#endif
547
548#if !HAVE_PIDFD_SEND_SIGNAL
549/* may be (invalid) negative number due to libseccomp, see PR 13319 */
fb4b0465 550# if ! (defined __NR_pidfd_send_signal && __NR_pidfd_send_signal >= 0)
5f152f43
LP
551# if defined __NR_pidfd_send_signal
552# undef __NR_pidfd_send_signal
553# endif
554# define __NR_pidfd_send_signal 424
555#endif
556static inline int pidfd_send_signal(int fd, int sig, siginfo_t *info, unsigned flags) {
557#ifdef __NR_pidfd_open
558 return syscall(__NR_pidfd_send_signal, fd, sig, info, flags);
559#else
560 errno = ENOSYS;
561 return -1;
562#endif
563}
564#endif
5ead4e85
LP
565
566#if !HAVE_RT_SIGQUEUEINFO
567static inline int rt_sigqueueinfo(pid_t tgid, int sig, siginfo_t *info) {
568 return syscall(__NR_rt_sigqueueinfo, tgid, sig, info);
569}
570#endif