]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/missing_syscall.h
ec62602989dfbfca1fe76b5d0eea748b68adb470
[thirdparty/systemd.git] / src / basic / missing_syscall.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 /* Missing glibc definitions to access certain kernel APIs */
5
6 #include <linux/mempolicy.h>
7 #include <signal.h>
8 #include <sys/syscall.h>
9 #include <sys/xattr.h>
10 #include <unistd.h>
11
12 #ifdef ARCH_MIPS
13 #include <asm/sgidefs.h>
14 #endif
15
16 #include "forward.h"
17 #include "missing_keyctl.h"
18 #include "missing_sched.h"
19 #include "missing_syscall_def.h"
20
21 /* ======================================================================= */
22
23 #if !HAVE_FCHMODAT2
24 /* since kernel v6.6 (78252deb023cf0879256fcfbafe37022c390762b) */
25 static inline int missing_fchmodat2(int dirfd, const char *path, mode_t mode, int flags) {
26 return syscall(__NR_fchmodat2, dirfd, path, mode, flags);
27 }
28
29 # define fchmodat2 missing_fchmodat2
30 #endif
31
32 /* ======================================================================= */
33
34 #if !HAVE_PIVOT_ROOT
35 static inline int missing_pivot_root(const char *new_root, const char *put_old) {
36 return syscall(__NR_pivot_root, new_root, put_old);
37 }
38
39 # define pivot_root missing_pivot_root
40 #endif
41
42 /* ======================================================================= */
43
44 #if !HAVE_IOPRIO_GET
45 static 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
55 static 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
64 #if !HAVE_KCMP
65 static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
66 return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
67 }
68
69 # define kcmp missing_kcmp
70 #endif
71
72 /* ======================================================================= */
73
74 #if !HAVE_KEYCTL
75 static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) {
76 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
77
78 # define keyctl missing_keyctl
79 }
80
81 /* ======================================================================= */
82
83 static inline key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
84 return syscall(__NR_add_key, type, description, payload, plen, ringid);
85
86 # define add_key missing_add_key
87 }
88
89 /* ======================================================================= */
90
91 static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
92 return syscall(__NR_request_key, type, description, callout_info, destringid);
93
94 # define request_key missing_request_key
95 }
96 #endif
97
98 /* ======================================================================= */
99
100 #if !HAVE_BPF
101 union bpf_attr;
102
103 static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) {
104 return (int) syscall(__NR_bpf, cmd, attr, size);
105 }
106
107 # define bpf missing_bpf
108 #endif
109
110 /* ======================================================================= */
111
112 #if !HAVE_SET_MEMPOLICY
113 static inline long missing_set_mempolicy(int mode, const unsigned long *nodemask,
114 unsigned long maxnode) {
115 return syscall(__NR_set_mempolicy, mode, nodemask, maxnode);
116 }
117
118 # define set_mempolicy missing_set_mempolicy
119 #endif
120
121 #if !HAVE_GET_MEMPOLICY
122 static inline long missing_get_mempolicy(int *mode, unsigned long *nodemask,
123 unsigned long maxnode, void *addr,
124 unsigned long flags) {
125 return syscall(__NR_get_mempolicy, mode, nodemask, maxnode, addr, flags);
126 }
127
128 # define get_mempolicy missing_get_mempolicy
129 #endif
130
131 /* ======================================================================= */
132
133 #if !HAVE_PIDFD_SEND_SIGNAL
134 /* since kernel v5.1 (3eb39f47934f9d5a3027fe00d906a45fe3a15fad) */
135 static inline int missing_pidfd_send_signal(int fd, int sig, siginfo_t *info, unsigned flags) {
136 return syscall(__NR_pidfd_send_signal, fd, sig, info, flags);
137 }
138
139 # define pidfd_send_signal missing_pidfd_send_signal
140 #endif
141
142 /* ======================================================================= */
143
144 #if !HAVE_PIDFD_OPEN
145 /* since kernel v5.3 (7615d9e1780e26e0178c93c55b73309a5dc093d7) */
146 static inline int missing_pidfd_open(pid_t pid, unsigned flags) {
147 return syscall(__NR_pidfd_open, pid, flags);
148 }
149
150 # define pidfd_open missing_pidfd_open
151 #endif
152
153 /* ======================================================================= */
154
155 #if !HAVE_RT_TGSIGQUEUEINFO
156 static inline int missing_rt_tgsigqueueinfo(pid_t tgid, pid_t tid, int sig, siginfo_t *info) {
157 return syscall(__NR_rt_tgsigqueueinfo, tgid, tid, sig, info);
158 }
159
160 # define rt_tgsigqueueinfo missing_rt_tgsigqueueinfo
161 #endif
162
163 /* ======================================================================= */
164
165 #if !HAVE_EXECVEAT
166 /* since kernel v3.19 (51f39a1f0cea1cacf8c787f652f26dfee9611874) */
167 static inline int missing_execveat(int dirfd, const char *pathname,
168 char *const argv[], char *const envp[],
169 int flags) {
170 return syscall(__NR_execveat, dirfd, pathname, argv, envp, flags);
171 }
172
173 # define execveat missing_execveat
174 #endif
175
176 /* ======================================================================= */
177
178 #if !HAVE_CLOSE_RANGE
179 /* since kernel v5.9 (9b4feb630e8e9801603f3cab3a36369e3c1cf88d) */
180 static inline int missing_close_range(unsigned first_fd, unsigned end_fd, unsigned flags) {
181 /* Kernel-side the syscall expects fds as unsigned integers (just like close() actually), while
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. */
184 return syscall(__NR_close_range,
185 first_fd,
186 end_fd,
187 flags);
188 }
189
190 # define close_range missing_close_range
191 #endif
192
193 /* ======================================================================= */
194
195 #if !HAVE_SCHED_SETATTR
196 /* since kernel 3.14 (e6cfc0295c7d51b008999a8b13a44fb43f8685ea) */
197 static inline ssize_t missing_sched_setattr(pid_t pid, struct sched_attr *attr, unsigned int flags) {
198 return syscall(__NR_sched_setattr, pid, attr, flags);
199 }
200
201 # define sched_setattr missing_sched_setattr
202 #endif
203
204 /* ======================================================================= */
205
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__)
210 int __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
217
218 /* ======================================================================= */
219
220 #if !HAVE_QUOTACTL_FD
221 /* since kernel v5.14 (64c2c2c62f92339b176ea24403d8db16db36f9e6) */
222 static inline int missing_quotactl_fd(int fd, int cmd, int id, void *addr) {
223 return syscall(__NR_quotactl_fd, fd, cmd, id, addr);
224 }
225
226 # define quotactl_fd missing_quotactl_fd
227 #endif
228
229 /* ======================================================================= */
230
231 #if !HAVE_SETXATTRAT
232 /* since kernel v6.13 (6140be90ec70c39fa844741ca3cc807dd0866394) */
233 static inline int missing_setxattrat(int fd, const char *path, int at_flags, const char *name, const struct xattr_args *args, size_t size) {
234 return syscall(__NR_setxattrat, fd, path, at_flags, name, args, size);
235 }
236
237 # define setxattrat missing_setxattrat
238 #endif
239
240 /* ======================================================================= */
241
242 #if !HAVE_REMOVEXATTRAT
243 /* since kernel v6.13 (6140be90ec70c39fa844741ca3cc807dd0866394) */
244 static inline int missing_removexattrat(int fd, const char *path, int at_flags, const char *name) {
245 return syscall(__NR_removexattrat, fd, path, at_flags, name);
246 }
247
248 # define removexattrat missing_removexattrat
249 #endif