]> git.ipfire.org Git - thirdparty/systemd.git/blame_incremental - src/basic/missing_syscall.h
Merge pull request #8575 from keszybz/non-absolute-paths
[thirdparty/systemd.git] / src / basic / missing_syscall.h
... / ...
CommitLineData
1/* SPDX-License-Identifier: LGPL-2.1+ */
2#pragma once
3
4/***
5 This file is part of systemd.
6
7 Copyright 2010 Lennart Poettering
8 Copyright 2016 Zbigniew Jędrzejewski-Szmek
9***/
10
11/* Missing glibc definitions to access certain kernel APIs */
12
13#include <sys/types.h>
14
15#if !HAVE_PIVOT_ROOT
16static inline int missing_pivot_root(const char *new_root, const char *put_old) {
17 return syscall(__NR_pivot_root, new_root, put_old);
18}
19
20# define pivot_root missing_pivot_root
21#endif
22
23/* ======================================================================= */
24
25#if !HAVE_MEMFD_CREATE
26# ifndef __NR_memfd_create
27# if defined __x86_64__
28# define __NR_memfd_create 319
29# elif defined __arm__
30# define __NR_memfd_create 385
31# elif defined __aarch64__
32# define __NR_memfd_create 279
33# elif defined __s390__
34# define __NR_memfd_create 350
35# elif defined _MIPS_SIM
36# if _MIPS_SIM == _MIPS_SIM_ABI32
37# define __NR_memfd_create 4354
38# endif
39# if _MIPS_SIM == _MIPS_SIM_NABI32
40# define __NR_memfd_create 6318
41# endif
42# if _MIPS_SIM == _MIPS_SIM_ABI64
43# define __NR_memfd_create 5314
44# endif
45# elif defined __i386__
46# define __NR_memfd_create 356
47# elif defined __arc__
48# define __NR_memfd_create 279
49# else
50# warning "__NR_memfd_create unknown for your architecture"
51# endif
52# endif
53
54static inline int missing_memfd_create(const char *name, unsigned int flags) {
55# ifdef __NR_memfd_create
56 return syscall(__NR_memfd_create, name, flags);
57# else
58 errno = ENOSYS;
59 return -1;
60# endif
61}
62
63# define memfd_create missing_memfd_create
64#endif
65
66/* ======================================================================= */
67
68#if !HAVE_GETRANDOM
69# ifndef __NR_getrandom
70# if defined __x86_64__
71# define __NR_getrandom 318
72# elif defined(__i386__)
73# define __NR_getrandom 355
74# elif defined(__arm__)
75# define __NR_getrandom 384
76# elif defined(__aarch64__)
77# define __NR_getrandom 278
78# elif defined(__ia64__)
79# define __NR_getrandom 1339
80# elif defined(__m68k__)
81# define __NR_getrandom 352
82# elif defined(__s390x__)
83# define __NR_getrandom 349
84# elif defined(__powerpc__)
85# define __NR_getrandom 359
86# elif defined _MIPS_SIM
87# if _MIPS_SIM == _MIPS_SIM_ABI32
88# define __NR_getrandom 4353
89# endif
90# if _MIPS_SIM == _MIPS_SIM_NABI32
91# define __NR_getrandom 6317
92# endif
93# if _MIPS_SIM == _MIPS_SIM_ABI64
94# define __NR_getrandom 5313
95# endif
96# elif defined(__arc__)
97# define __NR_getrandom 278
98# else
99# warning "__NR_getrandom unknown for your architecture"
100# endif
101# endif
102
103static inline int missing_getrandom(void *buffer, size_t count, unsigned flags) {
104# ifdef __NR_getrandom
105 return syscall(__NR_getrandom, buffer, count, flags);
106# else
107 errno = ENOSYS;
108 return -1;
109# endif
110}
111
112# define getrandom missing_getrandom
113#endif
114
115/* ======================================================================= */
116
117#if !HAVE_GETTID
118static inline pid_t missing_gettid(void) {
119 return (pid_t) syscall(__NR_gettid);
120}
121
122# define gettid missing_gettid
123#endif
124
125/* ======================================================================= */
126
127#if !HAVE_NAME_TO_HANDLE_AT
128# ifndef __NR_name_to_handle_at
129# if defined(__x86_64__)
130# define __NR_name_to_handle_at 303
131# elif defined(__i386__)
132# define __NR_name_to_handle_at 341
133# elif defined(__arm__)
134# define __NR_name_to_handle_at 370
135# elif defined(__powerpc__)
136# define __NR_name_to_handle_at 345
137# elif defined(__arc__)
138# define __NR_name_to_handle_at 264
139# else
140# error "__NR_name_to_handle_at is not defined"
141# endif
142# endif
143
144struct file_handle {
145 unsigned int handle_bytes;
146 int handle_type;
147 unsigned char f_handle[0];
148};
149
150static inline int missing_name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
151# ifdef __NR_name_to_handle_at
152 return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
153# else
154 errno = ENOSYS;
155 return -1;
156# endif
157}
158
159# define name_to_handle_at missing_name_to_handle_at
160#endif
161
162/* ======================================================================= */
163
164#if !HAVE_SETNS
165# ifndef __NR_setns
166# if defined(__x86_64__)
167# define __NR_setns 308
168# elif defined(__i386__)
169# define __NR_setns 346
170# elif defined(__arc__)
171# define __NR_setns 268
172# else
173# error "__NR_setns is not defined"
174# endif
175# endif
176
177static inline int missing_setns(int fd, int nstype) {
178# ifdef __NR_setns
179 return syscall(__NR_setns, fd, nstype);
180# else
181 errno = ENOSYS;
182 return -1;
183# endif
184}
185
186# define setns missing_setns
187#endif
188
189/* ======================================================================= */
190
191static inline pid_t raw_getpid(void) {
192#if defined(__alpha__)
193 return (pid_t) syscall(__NR_getxpid);
194#else
195 return (pid_t) syscall(__NR_getpid);
196#endif
197}
198
199/* ======================================================================= */
200
201#if !HAVE_RENAMEAT2
202# ifndef __NR_renameat2
203# if defined __x86_64__
204# define __NR_renameat2 316
205# elif defined __arm__
206# define __NR_renameat2 382
207# elif defined __aarch64__
208# define __NR_renameat2 276
209# elif defined _MIPS_SIM
210# if _MIPS_SIM == _MIPS_SIM_ABI32
211# define __NR_renameat2 4351
212# endif
213# if _MIPS_SIM == _MIPS_SIM_NABI32
214# define __NR_renameat2 6315
215# endif
216# if _MIPS_SIM == _MIPS_SIM_ABI64
217# define __NR_renameat2 5311
218# endif
219# elif defined __i386__
220# define __NR_renameat2 353
221# elif defined __powerpc64__
222# define __NR_renameat2 357
223# elif defined __s390__ || defined __s390x__
224# define __NR_renameat2 347
225# elif defined __arc__
226# define __NR_renameat2 276
227# else
228# warning "__NR_renameat2 unknown for your architecture"
229# endif
230# endif
231
232static inline int missing_renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
233# ifdef __NR_renameat2
234 return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
235# else
236 errno = ENOSYS;
237 return -1;
238# endif
239}
240
241# define renameat2 missing_renameat2
242#endif
243
244/* ======================================================================= */
245
246#if !HAVE_KCMP
247static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
248# ifdef __NR_kcmp
249 return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
250# else
251 errno = ENOSYS;
252 return -1;
253# endif
254}
255
256# define kcmp missing_kcmp
257#endif
258
259
260/* ======================================================================= */
261
262#if !HAVE_KEYCTL
263static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4,unsigned long arg5) {
264# ifdef __NR_keyctl
265 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
266# else
267 errno = ENOSYS;
268 return -1;
269# endif
270
271# define keyctl missing_keyctl
272}
273
274static inline key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
275# ifdef __NR_add_key
276 return syscall(__NR_add_key, type, description, payload, plen, ringid);
277# else
278 errno = ENOSYS;
279 return -1;
280# endif
281
282# define add_key missing_add_key
283}
284
285static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
286# ifdef __NR_request_key
287 return syscall(__NR_request_key, type, description, callout_info, destringid);
288# else
289 errno = ENOSYS;
290 return -1;
291# endif
292
293# define request_key missing_request_key
294}
295#endif
296
297/* ======================================================================= */
298
299#if !HAVE_COPY_FILE_RANGE
300# ifndef __NR_copy_file_range
301# if defined(__x86_64__)
302# define __NR_copy_file_range 326
303# elif defined(__i386__)
304# define __NR_copy_file_range 377
305# elif defined __s390__
306# define __NR_copy_file_range 375
307# elif defined __arm__
308# define __NR_copy_file_range 391
309# elif defined __aarch64__
310# define __NR_copy_file_range 285
311# elif defined __powerpc__
312# define __NR_copy_file_range 379
313# elif defined __arc__
314# define __NR_copy_file_range 285
315# else
316# warning "__NR_copy_file_range not defined for your architecture"
317# endif
318# endif
319
320static inline ssize_t missing_copy_file_range(int fd_in, loff_t *off_in,
321 int fd_out, loff_t *off_out,
322 size_t len,
323 unsigned int flags) {
324# ifdef __NR_copy_file_range
325 return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags);
326# else
327 errno = ENOSYS;
328 return -1;
329# endif
330}
331
332# define copy_file_range missing_copy_file_range
333#endif
334
335/* ======================================================================= */
336
337#if !HAVE_BPF
338# ifndef __NR_bpf
339# if defined __i386__
340# define __NR_bpf 357
341# elif defined __x86_64__
342# define __NR_bpf 321
343# elif defined __aarch64__
344# define __NR_bpf 280
345# elif defined __arm__
346# define __NR_bpf 386
347# elif defined __sparc__
348# define __NR_bpf 349
349# elif defined __s390__
350# define __NR_bpf 351
351# elif defined __tilegx__
352# define __NR_bpf 280
353# else
354# warning "__NR_bpf not defined for your architecture"
355# endif
356# endif
357
358union bpf_attr;
359
360static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) {
361#ifdef __NR_bpf
362 return (int) syscall(__NR_bpf, cmd, attr, size);
363#else
364 errno = ENOSYS;
365 return -1;
366#endif
367}
368
369# define bpf missing_bpf
370#endif
371
372/* ======================================================================= */
373
374#ifndef __IGNORE_pkey_mprotect
375# ifndef __NR_pkey_mprotect
376# if defined __i386__
377# define __NR_pkey_mprotect 380
378# elif defined __x86_64__
379# define __NR_pkey_mprotect 329
380# elif defined __arm__
381# define __NR_pkey_mprotect 394
382# elif defined __aarch64__
383# define __NR_pkey_mprotect 394
384# elif defined __powerpc__
385# define __NR_pkey_mprotect 386
386# elif defined _MIPS_SIM
387# if _MIPS_SIM == _MIPS_SIM_ABI32
388# define __NR_pkey_mprotect 4363
389# endif
390# if _MIPS_SIM == _MIPS_SIM_NABI32
391# define __NR_pkey_mprotect 6327
392# endif
393# if _MIPS_SIM == _MIPS_SIM_ABI64
394# define __NR_pkey_mprotect 5323
395# endif
396# else
397# warning "__NR_pkey_mprotect not defined for your architecture"
398# endif
399# endif
400#endif
401
402/* ======================================================================= */
403
404#if !HAVE_STATX
405# ifndef __NR_statx
406# if defined __i386__
407# define __NR_statx 383
408# elif defined __x86_64__
409# define __NR_statx 332
410# else
411# warning "__NR_statx not defined for your architecture"
412# endif
413# endif
414
415struct statx;
416#endif
417
418/* This typedef is supposed to be always defined. */
419typedef struct statx struct_statx;
420
421#if !HAVE_STATX
422static inline ssize_t missing_statx(int dfd, const char *filename, unsigned flags, unsigned int mask, struct statx *buffer) {
423# ifdef __NR_statx
424 return syscall(__NR_statx, dfd, filename, flags, mask, buffer);
425# else
426 errno = ENOSYS;
427 return -1;
428# endif
429}
430
431# define statx missing_statx
432#endif