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