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