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