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