]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/missing_syscall.h
man/systemd-sysext: list ephemeral/ephemeral-import in the list of options
[thirdparty/systemd.git] / src / basic / missing_syscall.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2f368e4a
ZJS
2#pragma once
3
2f368e4a
ZJS
4/* Missing glibc definitions to access certain kernel APIs */
5
118ac16b 6#include <linux/mempolicy.h>
5f152f43 7#include <signal.h>
36dd5ffd 8#include <sys/syscall.h>
118ac16b 9#include <sys/xattr.h>
851d66fa
YW
10#include <unistd.h>
11
12#ifdef ARCH_MIPS
13#include <asm/sgidefs.h>
14#endif
71e5200f 15
0c15577a 16#include "forward.h"
d7276b61 17#include "missing_keyctl.h"
016e9d8d 18#include "missing_sched.h"
35b42e56 19#include "missing_syscall_def.h"
d7276b61 20
35b42e56
ZJS
21/* ======================================================================= */
22
c21566d9 23#if !HAVE_FCHMODAT2
1d917ba4 24/* since kernel v6.6 (78252deb023cf0879256fcfbafe37022c390762b) */
c21566d9 25static inline int missing_fchmodat2(int dirfd, const char *path, mode_t mode, int flags) {
c21566d9 26 return syscall(__NR_fchmodat2, dirfd, path, mode, flags);
c21566d9
AM
27}
28
29# define fchmodat2 missing_fchmodat2
30#endif
31
32/* ======================================================================= */
33
4b9545f1 34#if !HAVE_PIVOT_ROOT
5187dd2c 35static inline int missing_pivot_root(const char *new_root, const char *put_old) {
d06f3829 36 return syscall(__NR_pivot_root, new_root, put_old);
2f368e4a 37}
5187dd2c
ZJS
38
39# define pivot_root missing_pivot_root
2f368e4a
ZJS
40#endif
41
42/* ======================================================================= */
43
51fe206f
ZJS
44#if !HAVE_IOPRIO_GET
45static inline int missing_ioprio_get(int which, int who) {
46 return syscall(__NR_ioprio_get, which, who);
47}
48
49# define ioprio_get missing_ioprio_get
50#endif
51
52/* ======================================================================= */
53
54#if !HAVE_IOPRIO_SET
55static inline int missing_ioprio_set(int which, int who, int ioprio) {
56 return syscall(__NR_ioprio_set, which, who, ioprio);
57}
58
59# define ioprio_set missing_ioprio_set
60#endif
61
62/* ======================================================================= */
63
4b9545f1 64#if !HAVE_KCMP
5187dd2c 65static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
2f368e4a 66 return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
2f368e4a 67}
5187dd2c
ZJS
68
69# define kcmp missing_kcmp
2f368e4a
ZJS
70#endif
71
72/* ======================================================================= */
73
4b9545f1 74#if !HAVE_KEYCTL
851d66fa 75static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) {
2f368e4a 76 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
5187dd2c
ZJS
77
78# define keyctl missing_keyctl
2f368e4a
ZJS
79}
80
1d917ba4
YW
81/* ======================================================================= */
82
5187dd2c 83static inline key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
2f368e4a 84 return syscall(__NR_add_key, type, description, payload, plen, ringid);
5187dd2c
ZJS
85
86# define add_key missing_add_key
2f368e4a
ZJS
87}
88
1d917ba4
YW
89/* ======================================================================= */
90
5187dd2c 91static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
2f368e4a 92 return syscall(__NR_request_key, type, description, callout_info, destringid);
5187dd2c
ZJS
93
94# define request_key missing_request_key
2f368e4a
ZJS
95}
96#endif
97
98/* ======================================================================= */
99
5134e18e 100#if !HAVE_BPF
71e5200f
DM
101union bpf_attr;
102
5187dd2c 103static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) {
71e5200f 104 return (int) syscall(__NR_bpf, cmd, attr, size);
71e5200f
DM
105}
106
5187dd2c 107# define bpf missing_bpf
71e5200f 108#endif
213f2883
ZJS
109
110/* ======================================================================= */
111
5134e18e 112#if !HAVE_SET_MEMPOLICY
b070c7c0
MS
113static inline long missing_set_mempolicy(int mode, const unsigned long *nodemask,
114 unsigned long maxnode) {
1d917ba4 115 return syscall(__NR_set_mempolicy, mode, nodemask, maxnode);
b070c7c0
MS
116}
117
118# define set_mempolicy missing_set_mempolicy
119#endif
120
b070c7c0
MS
121#if !HAVE_GET_MEMPOLICY
122static inline long missing_get_mempolicy(int *mode, unsigned long *nodemask,
123 unsigned long maxnode, void *addr,
124 unsigned long flags) {
1d917ba4 125 return syscall(__NR_get_mempolicy, mode, nodemask, maxnode, addr, flags);
b070c7c0
MS
126}
127
faeae444 128# define get_mempolicy missing_get_mempolicy
b070c7c0 129#endif
5f152f43 130
5134e18e
ZJS
131/* ======================================================================= */
132
5134e18e 133#if !HAVE_PIDFD_SEND_SIGNAL
1d917ba4 134/* since kernel v5.1 (3eb39f47934f9d5a3027fe00d906a45fe3a15fad) */
faeae444 135static inline int missing_pidfd_send_signal(int fd, int sig, siginfo_t *info, unsigned flags) {
5f152f43 136 return syscall(__NR_pidfd_send_signal, fd, sig, info, flags);
23654cee 137}
faeae444
ZJS
138
139# define pidfd_send_signal missing_pidfd_send_signal
5f152f43 140#endif
23654cee 141
1d917ba4
YW
142/* ======================================================================= */
143
5134e18e 144#if !HAVE_PIDFD_OPEN
1d917ba4 145/* since kernel v5.3 (7615d9e1780e26e0178c93c55b73309a5dc093d7) */
faeae444 146static inline int missing_pidfd_open(pid_t pid, unsigned flags) {
23654cee 147 return syscall(__NR_pidfd_open, pid, flags);
5f152f43 148}
faeae444
ZJS
149
150# define pidfd_open missing_pidfd_open
5f152f43 151#endif
5ead4e85 152
5134e18e
ZJS
153/* ======================================================================= */
154
a5421953
DDM
155#if !HAVE_RT_TGSIGQUEUEINFO
156static inline int missing_rt_tgsigqueueinfo(pid_t tgid, pid_t tid, int sig, siginfo_t *info) {
a5421953 157 return syscall(__NR_rt_tgsigqueueinfo, tgid, tid, sig, info);
a5421953
DDM
158}
159
160# define rt_tgsigqueueinfo missing_rt_tgsigqueueinfo
161#endif
162
163/* ======================================================================= */
b8bcd4c6 164
8939eeae 165#if !HAVE_EXECVEAT
1d917ba4 166/* since kernel v3.19 (51f39a1f0cea1cacf8c787f652f26dfee9611874) */
8939eeae
ZJS
167static inline int missing_execveat(int dirfd, const char *pathname,
168 char *const argv[], char *const envp[],
169 int flags) {
8939eeae 170 return syscall(__NR_execveat, dirfd, pathname, argv, envp, flags);
8939eeae 171}
b8bcd4c6 172
8939eeae
ZJS
173# define execveat missing_execveat
174#endif
175
441e0fdb
LP
176/* ======================================================================= */
177
441e0fdb 178#if !HAVE_CLOSE_RANGE
1d917ba4 179/* since kernel v5.9 (9b4feb630e8e9801603f3cab3a36369e3c1cf88d) */
39d69836 180static inline int missing_close_range(unsigned first_fd, unsigned end_fd, unsigned flags) {
441e0fdb 181 /* Kernel-side the syscall expects fds as unsigned integers (just like close() actually), while
39d69836
LP
182 * userspace exclusively uses signed integers for fds. glibc chose to expose it 1:1 however, hence we
183 * do so here too, even if we end up passing signed fds to it most of the time. */
441e0fdb 184 return syscall(__NR_close_range,
39d69836
LP
185 first_fd,
186 end_fd,
441e0fdb 187 flags);
441e0fdb
LP
188}
189
190# define close_range missing_close_range
191#endif
420297c9
LP
192
193/* ======================================================================= */
194
016e9d8d 195#if !HAVE_SCHED_SETATTR
1d917ba4 196/* since kernel 3.14 (e6cfc0295c7d51b008999a8b13a44fb43f8685ea) */
016e9d8d 197static inline ssize_t missing_sched_setattr(pid_t pid, struct sched_attr *attr, unsigned int flags) {
016e9d8d 198 return syscall(__NR_sched_setattr, pid, attr, flags);
016e9d8d
FS
199}
200
201# define sched_setattr missing_sched_setattr
202#endif
203
204/* ======================================================================= */
205
840ac5cd
LB
206/* glibc does not provide clone() on ia64, only clone2(). Not only that, but it also doesn't provide a
207 * prototype, only the symbol in the shared library (it provides a prototype for clone(), but not the
208 * symbol in the shared library). */
209#if defined(__ia64__)
210int __clone2(int (*fn)(void *), void *stack_base, size_t stack_size, int flags, void *arg);
211#define HAVE_CLONE 0
212#else
213/* We know that everywhere else clone() is available, so we don't bother with a meson check (that takes time
214 * at build time) and just define it. Once the kernel drops ia64 support, we can drop this too. */
215#define HAVE_CLONE 1
216#endif
7adafb08
LP
217
218/* ======================================================================= */
219
220#if !HAVE_QUOTACTL_FD
1d917ba4 221/* since kernel v5.14 (64c2c2c62f92339b176ea24403d8db16db36f9e6) */
7adafb08 222static inline int missing_quotactl_fd(int fd, int cmd, int id, void *addr) {
7adafb08 223 return syscall(__NR_quotactl_fd, fd, cmd, id, addr);
7adafb08
LP
224}
225
226# define quotactl_fd missing_quotactl_fd
227#endif
a0924d96
MY
228
229/* ======================================================================= */
230
231#if !HAVE_SETXATTRAT
1d917ba4 232/* since kernel v6.13 (6140be90ec70c39fa844741ca3cc807dd0866394) */
a0924d96 233static inline int missing_setxattrat(int fd, const char *path, int at_flags, const char *name, const struct xattr_args *args, size_t size) {
a0924d96 234 return syscall(__NR_setxattrat, fd, path, at_flags, name, args, size);
a0924d96
MY
235}
236
237# define setxattrat missing_setxattrat
238#endif
239
1d917ba4
YW
240/* ======================================================================= */
241
a0924d96 242#if !HAVE_REMOVEXATTRAT
1d917ba4 243/* since kernel v6.13 (6140be90ec70c39fa844741ca3cc807dd0866394) */
a0924d96 244static inline int missing_removexattrat(int fd, const char *path, int at_flags, const char *name) {
a0924d96 245 return syscall(__NR_removexattrat, fd, path, at_flags, name);
a0924d96
MY
246}
247
248# define removexattrat missing_removexattrat
249#endif