]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/missing_syscall.h
nspawn: fix warning by -Wnonnull (#8877)
[thirdparty/systemd.git] / src / basic / missing_syscall.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
2f368e4a
ZJS
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
2f368e4a
ZJS
9***/
10
11/* Missing glibc definitions to access certain kernel APIs */
12
71e5200f
DM
13#include <sys/types.h>
14
4b9545f1 15#if !HAVE_PIVOT_ROOT
5187dd2c 16static inline int missing_pivot_root(const char *new_root, const char *put_old) {
d06f3829 17 return syscall(__NR_pivot_root, new_root, put_old);
2f368e4a 18}
5187dd2c
ZJS
19
20# define pivot_root missing_pivot_root
2f368e4a
ZJS
21#endif
22
23/* ======================================================================= */
24
4b9545f1 25#if !HAVE_MEMFD_CREATE
2f368e4a
ZJS
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
27b09f1f
AB
47# elif defined __arc__
48# define __NR_memfd_create 279
2f368e4a
ZJS
49# else
50# warning "__NR_memfd_create unknown for your architecture"
51# endif
52# endif
53
5187dd2c 54static inline int missing_memfd_create(const char *name, unsigned int flags) {
2f368e4a
ZJS
55# ifdef __NR_memfd_create
56 return syscall(__NR_memfd_create, name, flags);
57# else
58 errno = ENOSYS;
59 return -1;
60# endif
61}
5187dd2c
ZJS
62
63# define memfd_create missing_memfd_create
2f368e4a
ZJS
64#endif
65
66/* ======================================================================= */
67
4b9545f1 68#if !HAVE_GETRANDOM
2f368e4a
ZJS
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
27b09f1f
AB
96# elif defined(__arc__)
97# define __NR_getrandom 278
2f368e4a
ZJS
98# else
99# warning "__NR_getrandom unknown for your architecture"
100# endif
101# endif
102
5187dd2c 103static inline int missing_getrandom(void *buffer, size_t count, unsigned flags) {
2f368e4a
ZJS
104# ifdef __NR_getrandom
105 return syscall(__NR_getrandom, buffer, count, flags);
106# else
107 errno = ENOSYS;
108 return -1;
109# endif
110}
5187dd2c
ZJS
111
112# define getrandom missing_getrandom
2f368e4a
ZJS
113#endif
114
115/* ======================================================================= */
116
4b9545f1 117#if !HAVE_GETTID
5187dd2c 118static inline pid_t missing_gettid(void) {
d06f3829 119 return (pid_t) syscall(__NR_gettid);
2f368e4a 120}
5187dd2c
ZJS
121
122# define gettid missing_gettid
2f368e4a
ZJS
123#endif
124
125/* ======================================================================= */
126
4b9545f1 127#if !HAVE_NAME_TO_HANDLE_AT
2f368e4a
ZJS
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
27b09f1f
AB
137# elif defined(__arc__)
138# define __NR_name_to_handle_at 264
2f368e4a
ZJS
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
5187dd2c 150static inline int missing_name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
2f368e4a
ZJS
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}
5187dd2c
ZJS
158
159# define name_to_handle_at missing_name_to_handle_at
2f368e4a
ZJS
160#endif
161
162/* ======================================================================= */
163
4b9545f1 164#if !HAVE_SETNS
2f368e4a
ZJS
165# ifndef __NR_setns
166# if defined(__x86_64__)
167# define __NR_setns 308
168# elif defined(__i386__)
169# define __NR_setns 346
27b09f1f
AB
170# elif defined(__arc__)
171# define __NR_setns 268
2f368e4a
ZJS
172# else
173# error "__NR_setns is not defined"
174# endif
175# endif
176
5187dd2c 177static inline int missing_setns(int fd, int nstype) {
2f368e4a
ZJS
178# ifdef __NR_setns
179 return syscall(__NR_setns, fd, nstype);
180# else
181 errno = ENOSYS;
182 return -1;
183# endif
184}
5187dd2c
ZJS
185
186# define setns missing_setns
2f368e4a
ZJS
187#endif
188
189/* ======================================================================= */
190
2f368e4a
ZJS
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
4b9545f1 201#if !HAVE_RENAMEAT2
2f368e4a
ZJS
202# ifndef __NR_renameat2
203# if defined __x86_64__
204# define __NR_renameat2 316
205# elif defined __arm__
206# define __NR_renameat2 382
925c81cd
LP
207# elif defined __aarch64__
208# define __NR_renameat2 276
2f368e4a
ZJS
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
92369d5e
ZJS
221# elif defined __powerpc64__
222# define __NR_renameat2 357
223# elif defined __s390__ || defined __s390x__
224# define __NR_renameat2 347
27b09f1f
AB
225# elif defined __arc__
226# define __NR_renameat2 276
2f368e4a
ZJS
227# else
228# warning "__NR_renameat2 unknown for your architecture"
229# endif
230# endif
231
5187dd2c 232static inline int missing_renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
2f368e4a
ZJS
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}
5187dd2c
ZJS
240
241# define renameat2 missing_renameat2
2f368e4a
ZJS
242#endif
243
244/* ======================================================================= */
245
4b9545f1 246#if !HAVE_KCMP
5187dd2c 247static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
2f368e4a
ZJS
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}
5187dd2c
ZJS
255
256# define kcmp missing_kcmp
2f368e4a
ZJS
257#endif
258
5187dd2c 259
2f368e4a
ZJS
260/* ======================================================================= */
261
4b9545f1 262#if !HAVE_KEYCTL
5187dd2c 263static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4,unsigned long arg5) {
2f368e4a
ZJS
264# ifdef __NR_keyctl
265 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
266# else
267 errno = ENOSYS;
268 return -1;
269# endif
5187dd2c
ZJS
270
271# define keyctl missing_keyctl
2f368e4a
ZJS
272}
273
5187dd2c 274static 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
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
5187dd2c
ZJS
281
282# define add_key missing_add_key
2f368e4a
ZJS
283}
284
5187dd2c 285static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
2f368e4a
ZJS
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
5187dd2c
ZJS
292
293# define request_key missing_request_key
2f368e4a
ZJS
294}
295#endif
296
297/* ======================================================================= */
298
4b9545f1 299#if !HAVE_COPY_FILE_RANGE
2f368e4a
ZJS
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
4d07c8d3
AIB
311# elif defined __powerpc__
312# define __NR_copy_file_range 379
27b09f1f
AB
313# elif defined __arc__
314# define __NR_copy_file_range 285
2f368e4a
ZJS
315# else
316# warning "__NR_copy_file_range not defined for your architecture"
317# endif
318# endif
319
5187dd2c
ZJS
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) {
2f368e4a
ZJS
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}
5187dd2c
ZJS
331
332# define copy_file_range missing_copy_file_range
2f368e4a 333#endif
71e5200f 334
213f2883
ZJS
335/* ======================================================================= */
336
4b9545f1 337#if !HAVE_BPF
71e5200f
DM
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
d07ba5d7
HCNE
345# elif defined __arm__
346# define __NR_bpf 386
71e5200f
DM
347# elif defined __sparc__
348# define __NR_bpf 349
349# elif defined __s390__
350# define __NR_bpf 351
66ffb275
HCNE
351# elif defined __tilegx__
352# define __NR_bpf 280
71e5200f
DM
353# else
354# warning "__NR_bpf not defined for your architecture"
355# endif
356# endif
357
358union bpf_attr;
359
5187dd2c 360static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) {
71e5200f
DM
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
5187dd2c 369# define bpf missing_bpf
71e5200f 370#endif
213f2883
ZJS
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
033c8366
ZJS
384# elif defined __powerpc__
385# define __NR_pkey_mprotect 386
213f2883
ZJS
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
9c6888ac 396# else
213f2883
ZJS
397# warning "__NR_pkey_mprotect not defined for your architecture"
398# endif
399# endif
400#endif
4c2e1b39 401
5187dd2c
ZJS
402/* ======================================================================= */
403
4c2e1b39
LP
404#if !HAVE_STATX
405# ifndef __NR_statx
406# if defined __i386__
fd91e3ef 407# define __NR_statx 383
4c2e1b39 408# elif defined __x86_64__
fd91e3ef 409# define __NR_statx 332
4c2e1b39
LP
410# else
411# warning "__NR_statx not defined for your architecture"
412# endif
413# endif
414
415struct statx;
5187dd2c
ZJS
416#endif
417
418/* This typedef is supposed to be always defined. */
419typedef struct statx struct_statx;
4c2e1b39 420
5187dd2c
ZJS
421#if !HAVE_STATX
422static inline ssize_t missing_statx(int dfd, const char *filename, unsigned flags, unsigned int mask, struct statx *buffer) {
4c2e1b39
LP
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}
5187dd2c
ZJS
430
431# define statx missing_statx
4c2e1b39 432#endif