]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/missing_syscall.h
man: rework systemd-vconsole-setup man page a bit (#7312)
[thirdparty/systemd.git] / src / basic / missing_syscall.h
CommitLineData
2f368e4a
ZJS
1#pragma once
2
3/***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7 Copyright 2016 Zbigniew Jędrzejewski-Szmek
8
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21***/
22
23/* Missing glibc definitions to access certain kernel APIs */
24
71e5200f
DM
25#include <sys/types.h>
26
4b9545f1 27#if !HAVE_PIVOT_ROOT
2f368e4a
ZJS
28static inline int pivot_root(const char *new_root, const char *put_old) {
29 return syscall(SYS_pivot_root, new_root, put_old);
30}
31#endif
32
33/* ======================================================================= */
34
4b9545f1 35#if !HAVE_MEMFD_CREATE
2f368e4a
ZJS
36# ifndef __NR_memfd_create
37# if defined __x86_64__
38# define __NR_memfd_create 319
39# elif defined __arm__
40# define __NR_memfd_create 385
41# elif defined __aarch64__
42# define __NR_memfd_create 279
43# elif defined __s390__
44# define __NR_memfd_create 350
45# elif defined _MIPS_SIM
46# if _MIPS_SIM == _MIPS_SIM_ABI32
47# define __NR_memfd_create 4354
48# endif
49# if _MIPS_SIM == _MIPS_SIM_NABI32
50# define __NR_memfd_create 6318
51# endif
52# if _MIPS_SIM == _MIPS_SIM_ABI64
53# define __NR_memfd_create 5314
54# endif
55# elif defined __i386__
56# define __NR_memfd_create 356
27b09f1f
AB
57# elif defined __arc__
58# define __NR_memfd_create 279
2f368e4a
ZJS
59# else
60# warning "__NR_memfd_create unknown for your architecture"
61# endif
62# endif
63
64static inline int memfd_create(const char *name, unsigned int flags) {
65# ifdef __NR_memfd_create
66 return syscall(__NR_memfd_create, name, flags);
67# else
68 errno = ENOSYS;
69 return -1;
70# endif
71}
72#endif
73
74/* ======================================================================= */
75
4b9545f1 76#if !HAVE_GETRANDOM
2f368e4a
ZJS
77# ifndef __NR_getrandom
78# if defined __x86_64__
79# define __NR_getrandom 318
80# elif defined(__i386__)
81# define __NR_getrandom 355
82# elif defined(__arm__)
83# define __NR_getrandom 384
84# elif defined(__aarch64__)
85# define __NR_getrandom 278
86# elif defined(__ia64__)
87# define __NR_getrandom 1339
88# elif defined(__m68k__)
89# define __NR_getrandom 352
90# elif defined(__s390x__)
91# define __NR_getrandom 349
92# elif defined(__powerpc__)
93# define __NR_getrandom 359
94# elif defined _MIPS_SIM
95# if _MIPS_SIM == _MIPS_SIM_ABI32
96# define __NR_getrandom 4353
97# endif
98# if _MIPS_SIM == _MIPS_SIM_NABI32
99# define __NR_getrandom 6317
100# endif
101# if _MIPS_SIM == _MIPS_SIM_ABI64
102# define __NR_getrandom 5313
103# endif
27b09f1f
AB
104# elif defined(__arc__)
105# define __NR_getrandom 278
2f368e4a
ZJS
106# else
107# warning "__NR_getrandom unknown for your architecture"
108# endif
109# endif
110
111static inline int getrandom(void *buffer, size_t count, unsigned flags) {
112# ifdef __NR_getrandom
113 return syscall(__NR_getrandom, buffer, count, flags);
114# else
115 errno = ENOSYS;
116 return -1;
117# endif
118}
119#endif
120
121/* ======================================================================= */
122
4b9545f1 123#if !HAVE_GETTID
2f368e4a
ZJS
124static inline pid_t gettid(void) {
125 return (pid_t) syscall(SYS_gettid);
126}
127#endif
128
129/* ======================================================================= */
130
4b9545f1 131#if !HAVE_NAME_TO_HANDLE_AT
2f368e4a
ZJS
132# ifndef __NR_name_to_handle_at
133# if defined(__x86_64__)
134# define __NR_name_to_handle_at 303
135# elif defined(__i386__)
136# define __NR_name_to_handle_at 341
137# elif defined(__arm__)
138# define __NR_name_to_handle_at 370
139# elif defined(__powerpc__)
140# define __NR_name_to_handle_at 345
27b09f1f
AB
141# elif defined(__arc__)
142# define __NR_name_to_handle_at 264
2f368e4a
ZJS
143# else
144# error "__NR_name_to_handle_at is not defined"
145# endif
146# endif
147
148struct file_handle {
149 unsigned int handle_bytes;
150 int handle_type;
151 unsigned char f_handle[0];
152};
153
154static inline int name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
155# ifdef __NR_name_to_handle_at
156 return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
157# else
158 errno = ENOSYS;
159 return -1;
160# endif
161}
162#endif
163
164/* ======================================================================= */
165
4b9545f1 166#if !HAVE_SETNS
2f368e4a
ZJS
167# ifndef __NR_setns
168# if defined(__x86_64__)
169# define __NR_setns 308
170# elif defined(__i386__)
171# define __NR_setns 346
27b09f1f
AB
172# elif defined(__arc__)
173# define __NR_setns 268
2f368e4a
ZJS
174# else
175# error "__NR_setns is not defined"
176# endif
177# endif
178
179static inline int setns(int fd, int nstype) {
180# ifdef __NR_setns
181 return syscall(__NR_setns, fd, nstype);
182# else
183 errno = ENOSYS;
184 return -1;
185# endif
186}
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
232static inline int renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
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}
240#endif
241
242/* ======================================================================= */
243
4b9545f1 244#if !HAVE_KCMP
2f368e4a
ZJS
245static inline int kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
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}
253#endif
254
255/* ======================================================================= */
256
4b9545f1 257#if !HAVE_KEYCTL
2f368e4a
ZJS
258static inline long keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4,unsigned long arg5) {
259# ifdef __NR_keyctl
260 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
261# else
262 errno = ENOSYS;
263 return -1;
264# endif
265}
266
267static inline key_serial_t add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
268# ifdef __NR_add_key
269 return syscall(__NR_add_key, type, description, payload, plen, ringid);
270# else
271 errno = ENOSYS;
272 return -1;
273# endif
274}
275
276static inline key_serial_t request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
277# ifdef __NR_request_key
278 return syscall(__NR_request_key, type, description, callout_info, destringid);
279# else
280 errno = ENOSYS;
281 return -1;
282# endif
283}
284#endif
285
286/* ======================================================================= */
287
4b9545f1 288#if !HAVE_COPY_FILE_RANGE
2f368e4a
ZJS
289# ifndef __NR_copy_file_range
290# if defined(__x86_64__)
291# define __NR_copy_file_range 326
292# elif defined(__i386__)
293# define __NR_copy_file_range 377
294# elif defined __s390__
295# define __NR_copy_file_range 375
296# elif defined __arm__
297# define __NR_copy_file_range 391
298# elif defined __aarch64__
299# define __NR_copy_file_range 285
4d07c8d3
AIB
300# elif defined __powerpc__
301# define __NR_copy_file_range 379
27b09f1f
AB
302# elif defined __arc__
303# define __NR_copy_file_range 285
2f368e4a
ZJS
304# else
305# warning "__NR_copy_file_range not defined for your architecture"
306# endif
307# endif
308
309static inline ssize_t copy_file_range(int fd_in, loff_t *off_in,
310 int fd_out, loff_t *off_out,
311 size_t len,
312 unsigned int flags) {
313# ifdef __NR_copy_file_range
314 return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags);
315# else
316 errno = ENOSYS;
317 return -1;
318# endif
319}
320#endif
71e5200f 321
213f2883
ZJS
322/* ======================================================================= */
323
4b9545f1 324#if !HAVE_BPF
71e5200f
DM
325# ifndef __NR_bpf
326# if defined __i386__
327# define __NR_bpf 357
328# elif defined __x86_64__
329# define __NR_bpf 321
330# elif defined __aarch64__
331# define __NR_bpf 280
332# elif defined __sparc__
333# define __NR_bpf 349
334# elif defined __s390__
335# define __NR_bpf 351
336# else
337# warning "__NR_bpf not defined for your architecture"
338# endif
339# endif
340
341union bpf_attr;
342
343static inline int bpf(int cmd, union bpf_attr *attr, size_t size) {
344#ifdef __NR_bpf
345 return (int) syscall(__NR_bpf, cmd, attr, size);
346#else
347 errno = ENOSYS;
348 return -1;
349#endif
350}
351
352#endif
213f2883
ZJS
353
354/* ======================================================================= */
355
356#ifndef __IGNORE_pkey_mprotect
357# ifndef __NR_pkey_mprotect
358# if defined __i386__
359# define __NR_pkey_mprotect 380
360# elif defined __x86_64__
361# define __NR_pkey_mprotect 329
362# elif defined __arm__
363# define __NR_pkey_mprotect 394
364# elif defined __aarch64__
365# define __NR_pkey_mprotect 394
366# elif defined _MIPS_SIM
367# if _MIPS_SIM == _MIPS_SIM_ABI32
368# define __NR_pkey_mprotect 4363
369# endif
370# if _MIPS_SIM == _MIPS_SIM_NABI32
371# define __NR_pkey_mprotect 6327
372# endif
373# if _MIPS_SIM == _MIPS_SIM_ABI64
374# define __NR_pkey_mprotect 5323
375# endif
376# elif ! defined(__IGNORE_pkey_mprotect)
377# warning "__NR_pkey_mprotect not defined for your architecture"
378# endif
379# endif
380#endif