]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/missing_syscall.h
missing: move char{16,32}_t definitions to missing_type.h
[thirdparty/systemd.git] / src / basic / missing_syscall.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /* Missing glibc definitions to access certain kernel APIs */
5
6 #include <sys/types.h>
7
8 #include "missing_keyctl.h"
9 #include "missing_stat.h"
10
11 #if !HAVE_PIVOT_ROOT
12 static inline int missing_pivot_root(const char *new_root, const char *put_old) {
13 return syscall(__NR_pivot_root, new_root, put_old);
14 }
15
16 # define pivot_root missing_pivot_root
17 #endif
18
19 /* ======================================================================= */
20
21 #if !HAVE_MEMFD_CREATE
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
43 # elif defined __arc__
44 # define __NR_memfd_create 279
45 # else
46 # warning "__NR_memfd_create unknown for your architecture"
47 # endif
48 # endif
49
50 static inline int missing_memfd_create(const char *name, unsigned int flags) {
51 # ifdef __NR_memfd_create
52 return syscall(__NR_memfd_create, name, flags);
53 # else
54 errno = ENOSYS;
55 return -1;
56 # endif
57 }
58
59 # define memfd_create missing_memfd_create
60 #endif
61
62 /* ======================================================================= */
63
64 #if !HAVE_GETRANDOM
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
92 # elif defined(__arc__)
93 # define __NR_getrandom 278
94 # else
95 # warning "__NR_getrandom unknown for your architecture"
96 # endif
97 # endif
98
99 static inline int missing_getrandom(void *buffer, size_t count, unsigned flags) {
100 # ifdef __NR_getrandom
101 return syscall(__NR_getrandom, buffer, count, flags);
102 # else
103 errno = ENOSYS;
104 return -1;
105 # endif
106 }
107
108 # define getrandom missing_getrandom
109 #endif
110
111 /* ======================================================================= */
112
113 #if !HAVE_GETTID
114 static inline pid_t missing_gettid(void) {
115 return (pid_t) syscall(__NR_gettid);
116 }
117
118 # define gettid missing_gettid
119 #endif
120
121 /* ======================================================================= */
122
123 #if !HAVE_NAME_TO_HANDLE_AT
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
133 # elif defined(__arc__)
134 # define __NR_name_to_handle_at 264
135 # else
136 # error "__NR_name_to_handle_at is not defined"
137 # endif
138 # endif
139
140 struct file_handle {
141 unsigned int handle_bytes;
142 int handle_type;
143 unsigned char f_handle[0];
144 };
145
146 static inline int missing_name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
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 }
154
155 # define name_to_handle_at missing_name_to_handle_at
156 #endif
157
158 /* ======================================================================= */
159
160 #if !HAVE_SETNS
161 # ifndef __NR_setns
162 # if defined(__x86_64__)
163 # define __NR_setns 308
164 # elif defined(__i386__)
165 # define __NR_setns 346
166 # elif defined(__arc__)
167 # define __NR_setns 268
168 # else
169 # error "__NR_setns is not defined"
170 # endif
171 # endif
172
173 static inline int missing_setns(int fd, int nstype) {
174 # ifdef __NR_setns
175 return syscall(__NR_setns, fd, nstype);
176 # else
177 errno = ENOSYS;
178 return -1;
179 # endif
180 }
181
182 # define setns missing_setns
183 #endif
184
185 /* ======================================================================= */
186
187 static 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
197 #if !HAVE_RENAMEAT2
198 # ifndef __NR_renameat2
199 # if defined __x86_64__
200 # define __NR_renameat2 316
201 # elif defined __arm__
202 # define __NR_renameat2 382
203 # elif defined __aarch64__
204 # define __NR_renameat2 276
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
217 # elif defined __powerpc64__
218 # define __NR_renameat2 357
219 # elif defined __s390__ || defined __s390x__
220 # define __NR_renameat2 347
221 # elif defined __arc__
222 # define __NR_renameat2 276
223 # else
224 # warning "__NR_renameat2 unknown for your architecture"
225 # endif
226 # endif
227
228 static inline int missing_renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
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 }
236
237 # define renameat2 missing_renameat2
238 #endif
239
240 /* ======================================================================= */
241
242 #if !HAVE_KCMP
243 static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
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 }
251
252 # define kcmp missing_kcmp
253 #endif
254
255 /* ======================================================================= */
256
257 #if !HAVE_KEYCTL
258 static inline long missing_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 # define keyctl missing_keyctl
267 }
268
269 static inline key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
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
276
277 # define add_key missing_add_key
278 }
279
280 static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
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
287
288 # define request_key missing_request_key
289 }
290 #endif
291
292 /* ======================================================================= */
293
294 #if !HAVE_COPY_FILE_RANGE
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
306 # elif defined __powerpc__
307 # define __NR_copy_file_range 379
308 # elif defined __arc__
309 # define __NR_copy_file_range 285
310 # else
311 # warning "__NR_copy_file_range not defined for your architecture"
312 # endif
313 # endif
314
315 static 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) {
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 }
326
327 # define copy_file_range missing_copy_file_range
328 #endif
329
330 /* ======================================================================= */
331
332 #if !HAVE_BPF
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
340 # elif defined __arm__
341 # define __NR_bpf 386
342 # elif defined __sparc__
343 # define __NR_bpf 349
344 # elif defined __s390__
345 # define __NR_bpf 351
346 # elif defined __tilegx__
347 # define __NR_bpf 280
348 # else
349 # warning "__NR_bpf not defined for your architecture"
350 # endif
351 # endif
352
353 union bpf_attr;
354
355 static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) {
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
364 # define bpf missing_bpf
365 #endif
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
379 # elif defined __powerpc__
380 # define __NR_pkey_mprotect 386
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
391 # else
392 # warning "__NR_pkey_mprotect not defined for your architecture"
393 # endif
394 # endif
395 #endif
396
397 /* ======================================================================= */
398
399 #if !HAVE_STATX
400 # ifndef __NR_statx
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__
406 # define __NR_statx 383
407 # elif defined __sparc__
408 # define __NR_statx 360
409 # elif defined __x86_64__
410 # define __NR_statx 332
411 # else
412 # warning "__NR_statx not defined for your architecture"
413 # endif
414 # endif
415
416 struct statx;
417 #endif
418
419 /* This typedef is supposed to be always defined. */
420 typedef struct statx struct_statx;
421
422 #if !HAVE_STATX
423 static inline ssize_t missing_statx(int dfd, const char *filename, unsigned flags, unsigned int mask, struct statx *buffer) {
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 }
431
432 # define statx missing_statx
433 #endif