]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/missing_syscall.h
pkgconfig: define variables relative to ${prefix}/${rootprefix}/${sysconfdir}
[thirdparty/systemd.git] / src / basic / missing_syscall.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /* Missing glibc definitions to access certain kernel APIs */
5
6 #include <sys/types.h>
7
8 #if !HAVE_PIVOT_ROOT
9 static inline int missing_pivot_root(const char *new_root, const char *put_old) {
10 return syscall(__NR_pivot_root, new_root, put_old);
11 }
12
13 # define pivot_root missing_pivot_root
14 #endif
15
16 /* ======================================================================= */
17
18 #if !HAVE_MEMFD_CREATE
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
40 # elif defined __arc__
41 # define __NR_memfd_create 279
42 # else
43 # warning "__NR_memfd_create unknown for your architecture"
44 # endif
45 # endif
46
47 static inline int missing_memfd_create(const char *name, unsigned int flags) {
48 # ifdef __NR_memfd_create
49 return syscall(__NR_memfd_create, name, flags);
50 # else
51 errno = ENOSYS;
52 return -1;
53 # endif
54 }
55
56 # define memfd_create missing_memfd_create
57 #endif
58
59 /* ======================================================================= */
60
61 #if !HAVE_GETRANDOM
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
89 # elif defined(__arc__)
90 # define __NR_getrandom 278
91 # else
92 # warning "__NR_getrandom unknown for your architecture"
93 # endif
94 # endif
95
96 static inline int missing_getrandom(void *buffer, size_t count, unsigned flags) {
97 # ifdef __NR_getrandom
98 return syscall(__NR_getrandom, buffer, count, flags);
99 # else
100 errno = ENOSYS;
101 return -1;
102 # endif
103 }
104
105 # define getrandom missing_getrandom
106 #endif
107
108 /* ======================================================================= */
109
110 #if !HAVE_GETTID
111 static inline pid_t missing_gettid(void) {
112 return (pid_t) syscall(__NR_gettid);
113 }
114
115 # define gettid missing_gettid
116 #endif
117
118 /* ======================================================================= */
119
120 #if !HAVE_NAME_TO_HANDLE_AT
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
130 # elif defined(__arc__)
131 # define __NR_name_to_handle_at 264
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
143 static inline int missing_name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
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 }
151
152 # define name_to_handle_at missing_name_to_handle_at
153 #endif
154
155 /* ======================================================================= */
156
157 #if !HAVE_SETNS
158 # ifndef __NR_setns
159 # if defined(__x86_64__)
160 # define __NR_setns 308
161 # elif defined(__i386__)
162 # define __NR_setns 346
163 # elif defined(__arc__)
164 # define __NR_setns 268
165 # else
166 # error "__NR_setns is not defined"
167 # endif
168 # endif
169
170 static inline int missing_setns(int fd, int nstype) {
171 # ifdef __NR_setns
172 return syscall(__NR_setns, fd, nstype);
173 # else
174 errno = ENOSYS;
175 return -1;
176 # endif
177 }
178
179 # define setns missing_setns
180 #endif
181
182 /* ======================================================================= */
183
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
194 #if !HAVE_RENAMEAT2
195 # ifndef __NR_renameat2
196 # if defined __x86_64__
197 # define __NR_renameat2 316
198 # elif defined __arm__
199 # define __NR_renameat2 382
200 # elif defined __aarch64__
201 # define __NR_renameat2 276
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
214 # elif defined __powerpc64__
215 # define __NR_renameat2 357
216 # elif defined __s390__ || defined __s390x__
217 # define __NR_renameat2 347
218 # elif defined __arc__
219 # define __NR_renameat2 276
220 # else
221 # warning "__NR_renameat2 unknown for your architecture"
222 # endif
223 # endif
224
225 static inline int missing_renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
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 }
233
234 # define renameat2 missing_renameat2
235 #endif
236
237 /* ======================================================================= */
238
239 #if !HAVE_KCMP
240 static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
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 }
248
249 # define kcmp missing_kcmp
250 #endif
251
252 /* ======================================================================= */
253
254 #if !HAVE_KEYCTL
255 static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4,unsigned long arg5) {
256 # ifdef __NR_keyctl
257 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
258 # else
259 errno = ENOSYS;
260 return -1;
261 # endif
262
263 # define keyctl missing_keyctl
264 }
265
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) {
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
273
274 # define add_key missing_add_key
275 }
276
277 static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
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
284
285 # define request_key missing_request_key
286 }
287 #endif
288
289 /* ======================================================================= */
290
291 #if !HAVE_COPY_FILE_RANGE
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
303 # elif defined __powerpc__
304 # define __NR_copy_file_range 379
305 # elif defined __arc__
306 # define __NR_copy_file_range 285
307 # else
308 # warning "__NR_copy_file_range not defined for your architecture"
309 # endif
310 # endif
311
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) {
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 }
323
324 # define copy_file_range missing_copy_file_range
325 #endif
326
327 /* ======================================================================= */
328
329 #if !HAVE_BPF
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
337 # elif defined __arm__
338 # define __NR_bpf 386
339 # elif defined __sparc__
340 # define __NR_bpf 349
341 # elif defined __s390__
342 # define __NR_bpf 351
343 # elif defined __tilegx__
344 # define __NR_bpf 280
345 # else
346 # warning "__NR_bpf not defined for your architecture"
347 # endif
348 # endif
349
350 union bpf_attr;
351
352 static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) {
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
361 # define bpf missing_bpf
362 #endif
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
376 # elif defined __powerpc__
377 # define __NR_pkey_mprotect 386
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
388 # else
389 # warning "__NR_pkey_mprotect not defined for your architecture"
390 # endif
391 # endif
392 #endif
393
394 /* ======================================================================= */
395
396 #if !HAVE_STATX
397 # ifndef __NR_statx
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__
403 # define __NR_statx 383
404 # elif defined __sparc__
405 # define __NR_statx 360
406 # elif defined __x86_64__
407 # define __NR_statx 332
408 # else
409 # warning "__NR_statx not defined for your architecture"
410 # endif
411 # endif
412
413 struct statx;
414 #endif
415
416 /* This typedef is supposed to be always defined. */
417 typedef struct statx struct_statx;
418
419 #if !HAVE_STATX
420 static inline ssize_t missing_statx(int dfd, const char *filename, unsigned flags, unsigned int mask, struct statx *buffer) {
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 }
428
429 # define statx missing_statx
430 #endif