1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 This file is part of systemd.
7 Copyright 2010 Lennart Poettering
8 Copyright 2016 Zbigniew Jędrzejewski-Szmek
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.
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.
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/>.
24 /* Missing glibc definitions to access certain kernel APIs */
26 #if 0 /// UNNEEDED by elogind
27 #include <sys/types.h>
30 static inline int missing_pivot_root(const char *new_root, const char *put_old) {
31 return syscall(SYS_pivot_root, new_root, put_old);
34 # define pivot_root missing_pivot_root
38 /* ======================================================================= */
40 #if !HAVE_MEMFD_CREATE
41 # ifndef __NR_memfd_create
42 # if defined __x86_64__
43 # define __NR_memfd_create 319
44 # elif defined __arm__
45 # define __NR_memfd_create 385
46 # elif defined __aarch64__
47 # define __NR_memfd_create 279
48 # elif defined __s390__
49 # define __NR_memfd_create 350
50 # elif defined _MIPS_SIM
51 # if _MIPS_SIM == _MIPS_SIM_ABI32
52 # define __NR_memfd_create 4354
54 # if _MIPS_SIM == _MIPS_SIM_NABI32
55 # define __NR_memfd_create 6318
57 # if _MIPS_SIM == _MIPS_SIM_ABI64
58 # define __NR_memfd_create 5314
60 # elif defined __i386__
61 # define __NR_memfd_create 356
62 # elif defined __arc__
63 # define __NR_memfd_create 279
65 # warning "__NR_memfd_create unknown for your architecture"
69 static inline int missing_memfd_create(const char *name, unsigned int flags) {
70 # ifdef __NR_memfd_create
71 return syscall(__NR_memfd_create, name, flags);
78 # define memfd_create missing_memfd_create
81 /* ======================================================================= */
84 # ifndef __NR_getrandom
85 # if defined __x86_64__
86 # define __NR_getrandom 318
87 # elif defined(__i386__)
88 # define __NR_getrandom 355
89 # elif defined(__arm__)
90 # define __NR_getrandom 384
91 # elif defined(__aarch64__)
92 # define __NR_getrandom 278
93 # elif defined(__ia64__)
94 # define __NR_getrandom 1339
95 # elif defined(__m68k__)
96 # define __NR_getrandom 352
97 # elif defined(__s390x__)
98 # define __NR_getrandom 349
99 # elif defined(__powerpc__)
100 # define __NR_getrandom 359
101 # elif defined _MIPS_SIM
102 # if _MIPS_SIM == _MIPS_SIM_ABI32
103 # define __NR_getrandom 4353
105 # if _MIPS_SIM == _MIPS_SIM_NABI32
106 # define __NR_getrandom 6317
108 # if _MIPS_SIM == _MIPS_SIM_ABI64
109 # define __NR_getrandom 5313
111 # elif defined(__arc__)
112 # define __NR_getrandom 278
114 # warning "__NR_getrandom unknown for your architecture"
118 static inline int missing_getrandom(void *buffer, size_t count, unsigned flags) {
119 # ifdef __NR_getrandom
120 return syscall(__NR_getrandom, buffer, count, flags);
127 # define getrandom missing_getrandom
130 /* ======================================================================= */
133 static inline pid_t missing_gettid(void) {
134 return (pid_t) syscall(SYS_gettid);
137 # define gettid missing_gettid
140 /* ======================================================================= */
142 #if !HAVE_NAME_TO_HANDLE_AT
143 # ifndef __NR_name_to_handle_at
144 # if defined(__x86_64__)
145 # define __NR_name_to_handle_at 303
146 # elif defined(__i386__)
147 # define __NR_name_to_handle_at 341
148 # elif defined(__arm__)
149 # define __NR_name_to_handle_at 370
150 # elif defined(__powerpc__)
151 # define __NR_name_to_handle_at 345
152 # elif defined(__arc__)
153 # define __NR_name_to_handle_at 264
155 # error "__NR_name_to_handle_at is not defined"
160 unsigned int handle_bytes;
162 unsigned char f_handle[0];
165 static inline int missing_name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
166 # ifdef __NR_name_to_handle_at
167 return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
174 # define name_to_handle_at missing_name_to_handle_at
177 /* ======================================================================= */
181 # if defined(__x86_64__)
182 # define __NR_setns 308
183 # elif defined(__i386__)
184 # define __NR_setns 346
185 # elif defined(__arc__)
186 # define __NR_setns 268
188 # error "__NR_setns is not defined"
192 static inline int missing_setns(int fd, int nstype) {
194 return syscall(__NR_setns, fd, nstype);
201 # define setns missing_setns
204 /* ======================================================================= */
206 static inline pid_t raw_getpid(void) {
207 #if defined(__alpha__)
208 return (pid_t) syscall(__NR_getxpid);
210 return (pid_t) syscall(__NR_getpid);
214 /* ======================================================================= */
217 # ifndef __NR_renameat2
218 # if defined __x86_64__
219 # define __NR_renameat2 316
220 # elif defined __arm__
221 # define __NR_renameat2 382
222 # elif defined __aarch64__
223 # define __NR_renameat2 276
224 # elif defined _MIPS_SIM
225 # if _MIPS_SIM == _MIPS_SIM_ABI32
226 # define __NR_renameat2 4351
228 # if _MIPS_SIM == _MIPS_SIM_NABI32
229 # define __NR_renameat2 6315
231 # if _MIPS_SIM == _MIPS_SIM_ABI64
232 # define __NR_renameat2 5311
234 # elif defined __i386__
235 # define __NR_renameat2 353
236 # elif defined __powerpc64__
237 # define __NR_renameat2 357
238 # elif defined __s390__ || defined __s390x__
239 # define __NR_renameat2 347
240 # elif defined __arc__
241 # define __NR_renameat2 276
243 # warning "__NR_renameat2 unknown for your architecture"
247 static inline int missing_renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
248 # ifdef __NR_renameat2
249 return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
256 # define renameat2 missing_renameat2
259 /* ======================================================================= */
262 static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
264 return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
271 # define kcmp missing_kcmp
275 /* ======================================================================= */
278 static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4,unsigned long arg5) {
280 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
286 # define keyctl missing_keyctl
289 static inline key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
291 return syscall(__NR_add_key, type, description, payload, plen, ringid);
297 # define add_key missing_add_key
300 static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
301 # ifdef __NR_request_key
302 return syscall(__NR_request_key, type, description, callout_info, destringid);
308 # define request_key missing_request_key
312 /* ======================================================================= */
314 #if !HAVE_COPY_FILE_RANGE
315 # ifndef __NR_copy_file_range
316 # if defined(__x86_64__)
317 # define __NR_copy_file_range 326
318 # elif defined(__i386__)
319 # define __NR_copy_file_range 377
320 # elif defined __s390__
321 # define __NR_copy_file_range 375
322 # elif defined __arm__
323 # define __NR_copy_file_range 391
324 # elif defined __aarch64__
325 # define __NR_copy_file_range 285
326 # elif defined __powerpc__
327 # define __NR_copy_file_range 379
328 # elif defined __arc__
329 # define __NR_copy_file_range 285
331 # warning "__NR_copy_file_range not defined for your architecture"
335 static inline ssize_t missing_copy_file_range(int fd_in, loff_t *off_in,
336 int fd_out, loff_t *off_out,
338 unsigned int flags) {
339 # ifdef __NR_copy_file_range
340 return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags);
347 # define copy_file_range missing_copy_file_range
350 /* ======================================================================= */
354 # if defined __i386__
355 # define __NR_bpf 357
356 # elif defined __x86_64__
357 # define __NR_bpf 321
358 # elif defined __aarch64__
359 # define __NR_bpf 280
360 # elif defined __arm__
361 # define __NR_bpf 386
362 # elif defined __sparc__
363 # define __NR_bpf 349
364 # elif defined __s390__
365 # define __NR_bpf 351
366 # elif defined __tilegx__
367 # define __NR_bpf 280
369 # warning "__NR_bpf not defined for your architecture"
375 static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) {
377 return (int) syscall(__NR_bpf, cmd, attr, size);
384 # define bpf missing_bpf
387 /* ======================================================================= */
389 #ifndef __IGNORE_pkey_mprotect
390 # ifndef __NR_pkey_mprotect
391 # if defined __i386__
392 # define __NR_pkey_mprotect 380
393 # elif defined __x86_64__
394 # define __NR_pkey_mprotect 329
395 # elif defined __arm__
396 # define __NR_pkey_mprotect 394
397 # elif defined __aarch64__
398 # define __NR_pkey_mprotect 394
399 # elif defined _MIPS_SIM
400 # if _MIPS_SIM == _MIPS_SIM_ABI32
401 # define __NR_pkey_mprotect 4363
403 # if _MIPS_SIM == _MIPS_SIM_NABI32
404 # define __NR_pkey_mprotect 6327
406 # if _MIPS_SIM == _MIPS_SIM_ABI64
407 # define __NR_pkey_mprotect 5323
410 # warning "__NR_pkey_mprotect not defined for your architecture"
415 /* ======================================================================= */
419 # if defined __i386__
420 # define __NR_statx 383
421 # elif defined __x86_64__
422 # define __NR_statx 332
424 # warning "__NR_statx not defined for your architecture"
431 /* This typedef is supposed to be always defined. */
432 typedef struct statx struct_statx;
435 static inline ssize_t missing_statx(int dfd, const char *filename, unsigned flags, unsigned int mask, struct statx *buffer) {
437 return syscall(__NR_statx, dfd, filename, flags, mask, buffer);
444 # define statx missing_statx