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 pivot_root(const char *new_root, const char *put_old) {
31 return syscall(SYS_pivot_root, new_root, put_old);
36 /* ======================================================================= */
38 #if !HAVE_MEMFD_CREATE
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
52 # if _MIPS_SIM == _MIPS_SIM_NABI32
53 # define __NR_memfd_create 6318
55 # if _MIPS_SIM == _MIPS_SIM_ABI64
56 # define __NR_memfd_create 5314
58 # elif defined __i386__
59 # define __NR_memfd_create 356
60 # elif defined __arc__
61 # define __NR_memfd_create 279
63 # warning "__NR_memfd_create unknown for your architecture"
67 static inline int memfd_create(const char *name, unsigned int flags) {
68 # ifdef __NR_memfd_create
69 return syscall(__NR_memfd_create, name, flags);
77 /* ======================================================================= */
80 # ifndef __NR_getrandom
81 # if defined __x86_64__
82 # define __NR_getrandom 318
83 # elif defined(__i386__)
84 # define __NR_getrandom 355
85 # elif defined(__arm__)
86 # define __NR_getrandom 384
87 # elif defined(__aarch64__)
88 # define __NR_getrandom 278
89 # elif defined(__ia64__)
90 # define __NR_getrandom 1339
91 # elif defined(__m68k__)
92 # define __NR_getrandom 352
93 # elif defined(__s390x__)
94 # define __NR_getrandom 349
95 # elif defined(__powerpc__)
96 # define __NR_getrandom 359
97 # elif defined _MIPS_SIM
98 # if _MIPS_SIM == _MIPS_SIM_ABI32
99 # define __NR_getrandom 4353
101 # if _MIPS_SIM == _MIPS_SIM_NABI32
102 # define __NR_getrandom 6317
104 # if _MIPS_SIM == _MIPS_SIM_ABI64
105 # define __NR_getrandom 5313
107 # elif defined(__arc__)
108 # define __NR_getrandom 278
110 # warning "__NR_getrandom unknown for your architecture"
114 static inline int getrandom(void *buffer, size_t count, unsigned flags) {
115 # ifdef __NR_getrandom
116 return syscall(__NR_getrandom, buffer, count, flags);
124 /* ======================================================================= */
127 static inline pid_t gettid(void) {
128 return (pid_t) syscall(SYS_gettid);
132 /* ======================================================================= */
134 #if !HAVE_NAME_TO_HANDLE_AT
135 # ifndef __NR_name_to_handle_at
136 # if defined(__x86_64__)
137 # define __NR_name_to_handle_at 303
138 # elif defined(__i386__)
139 # define __NR_name_to_handle_at 341
140 # elif defined(__arm__)
141 # define __NR_name_to_handle_at 370
142 # elif defined(__powerpc__)
143 # define __NR_name_to_handle_at 345
144 # elif defined(__arc__)
145 # define __NR_name_to_handle_at 264
147 # error "__NR_name_to_handle_at is not defined"
152 unsigned int handle_bytes;
154 unsigned char f_handle[0];
157 static inline int name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
158 # ifdef __NR_name_to_handle_at
159 return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
167 /* ======================================================================= */
171 # if defined(__x86_64__)
172 # define __NR_setns 308
173 # elif defined(__i386__)
174 # define __NR_setns 346
175 # elif defined(__arc__)
176 # define __NR_setns 268
178 # error "__NR_setns is not defined"
182 static inline int setns(int fd, int nstype) {
184 return syscall(__NR_setns, fd, nstype);
192 /* ======================================================================= */
194 static inline pid_t raw_getpid(void) {
195 #if defined(__alpha__)
196 return (pid_t) syscall(__NR_getxpid);
198 return (pid_t) syscall(__NR_getpid);
202 /* ======================================================================= */
205 # ifndef __NR_renameat2
206 # if defined __x86_64__
207 # define __NR_renameat2 316
208 # elif defined __arm__
209 # define __NR_renameat2 382
210 # elif defined __aarch64__
211 # define __NR_renameat2 276
212 # elif defined _MIPS_SIM
213 # if _MIPS_SIM == _MIPS_SIM_ABI32
214 # define __NR_renameat2 4351
216 # if _MIPS_SIM == _MIPS_SIM_NABI32
217 # define __NR_renameat2 6315
219 # if _MIPS_SIM == _MIPS_SIM_ABI64
220 # define __NR_renameat2 5311
222 # elif defined __i386__
223 # define __NR_renameat2 353
224 # elif defined __powerpc64__
225 # define __NR_renameat2 357
226 # elif defined __s390__ || defined __s390x__
227 # define __NR_renameat2 347
228 # elif defined __arc__
229 # define __NR_renameat2 276
231 # warning "__NR_renameat2 unknown for your architecture"
235 static inline int renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
236 # ifdef __NR_renameat2
237 return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
245 /* ======================================================================= */
248 static inline int kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
250 return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
258 /* ======================================================================= */
261 static inline long keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4,unsigned long arg5) {
263 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
270 static inline key_serial_t add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
272 return syscall(__NR_add_key, type, description, payload, plen, ringid);
279 static inline key_serial_t request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
280 # ifdef __NR_request_key
281 return syscall(__NR_request_key, type, description, callout_info, destringid);
289 /* ======================================================================= */
291 #if !HAVE_COPY_FILE_RANGE
292 # ifndef __NR_copy_file_range
293 # if defined(__x86_64__)
294 # define __NR_copy_file_range 326
295 # elif defined(__i386__)
296 # define __NR_copy_file_range 377
297 # elif defined __s390__
298 # define __NR_copy_file_range 375
299 # elif defined __arm__
300 # define __NR_copy_file_range 391
301 # elif defined __aarch64__
302 # define __NR_copy_file_range 285
303 # elif defined __powerpc__
304 # define __NR_copy_file_range 379
305 # elif defined __arc__
306 # define __NR_copy_file_range 285
308 # warning "__NR_copy_file_range not defined for your architecture"
312 static inline ssize_t copy_file_range(int fd_in, loff_t *off_in,
313 int fd_out, loff_t *off_out,
315 unsigned int flags) {
316 # ifdef __NR_copy_file_range
317 return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags);
325 /* ======================================================================= */
329 # if defined __i386__
330 # define __NR_bpf 357
331 # elif defined __x86_64__
332 # define __NR_bpf 321
333 # elif defined __aarch64__
334 # define __NR_bpf 280
335 # elif defined __arm__
336 # define __NR_bpf 386
337 # elif defined __sparc__
338 # define __NR_bpf 349
339 # elif defined __s390__
340 # define __NR_bpf 351
341 # elif defined __tilegx__
342 # define __NR_bpf 280
344 # warning "__NR_bpf not defined for your architecture"
350 static inline int bpf(int cmd, union bpf_attr *attr, size_t size) {
352 return (int) syscall(__NR_bpf, cmd, attr, size);
361 /* ======================================================================= */
363 #ifndef __IGNORE_pkey_mprotect
364 # ifndef __NR_pkey_mprotect
365 # if defined __i386__
366 # define __NR_pkey_mprotect 380
367 # elif defined __x86_64__
368 # define __NR_pkey_mprotect 329
369 # elif defined __arm__
370 # define __NR_pkey_mprotect 394
371 # elif defined __aarch64__
372 # define __NR_pkey_mprotect 394
373 # elif defined _MIPS_SIM
374 # if _MIPS_SIM == _MIPS_SIM_ABI32
375 # define __NR_pkey_mprotect 4363
377 # if _MIPS_SIM == _MIPS_SIM_NABI32
378 # define __NR_pkey_mprotect 6327
380 # if _MIPS_SIM == _MIPS_SIM_ABI64
381 # define __NR_pkey_mprotect 5323
384 # warning "__NR_pkey_mprotect not defined for your architecture"
391 # if defined __i386__
392 # define __NR_bpf 383
393 # elif defined __x86_64__
394 # define __NR_bpf 332
396 # warning "__NR_statx not defined for your architecture"
402 static inline ssize_t statx(int dfd, const char *filename, unsigned flags, unsigned int mask, struct statx *buffer) {
404 return syscall(__NR_statx, dfd, filename, flags, mask, buffer);