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