]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/missing_syscall.h
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 #include <sys/types.h>
29 static inline int missing_pivot_root(const char *new_root
, const char *put_old
) {
30 return syscall(__NR_pivot_root
, new_root
, put_old
);
33 # define pivot_root missing_pivot_root
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 missing_memfd_create(const char *name
, unsigned int flags
) {
68 # ifdef __NR_memfd_create
69 return syscall(__NR_memfd_create
, name
, flags
);
76 # define memfd_create missing_memfd_create
79 /* ======================================================================= */
82 # ifndef __NR_getrandom
83 # if defined __x86_64__
84 # define __NR_getrandom 318
85 # elif defined(__i386__)
86 # define __NR_getrandom 355
87 # elif defined(__arm__)
88 # define __NR_getrandom 384
89 # elif defined(__aarch64__)
90 # define __NR_getrandom 278
91 # elif defined(__ia64__)
92 # define __NR_getrandom 1339
93 # elif defined(__m68k__)
94 # define __NR_getrandom 352
95 # elif defined(__s390x__)
96 # define __NR_getrandom 349
97 # elif defined(__powerpc__)
98 # define __NR_getrandom 359
99 # elif defined _MIPS_SIM
100 # if _MIPS_SIM == _MIPS_SIM_ABI32
101 # define __NR_getrandom 4353
103 # if _MIPS_SIM == _MIPS_SIM_NABI32
104 # define __NR_getrandom 6317
106 # if _MIPS_SIM == _MIPS_SIM_ABI64
107 # define __NR_getrandom 5313
109 # elif defined(__arc__)
110 # define __NR_getrandom 278
112 # warning "__NR_getrandom unknown for your architecture"
116 static inline int missing_getrandom(void *buffer
, size_t count
, unsigned flags
) {
117 # ifdef __NR_getrandom
118 return syscall(__NR_getrandom
, buffer
, count
, flags
);
125 # define getrandom missing_getrandom
128 /* ======================================================================= */
131 static inline pid_t
missing_gettid(void) {
132 return (pid_t
) syscall(__NR_gettid
);
135 # define gettid missing_gettid
138 /* ======================================================================= */
140 #if !HAVE_NAME_TO_HANDLE_AT
141 # ifndef __NR_name_to_handle_at
142 # if defined(__x86_64__)
143 # define __NR_name_to_handle_at 303
144 # elif defined(__i386__)
145 # define __NR_name_to_handle_at 341
146 # elif defined(__arm__)
147 # define __NR_name_to_handle_at 370
148 # elif defined(__powerpc__)
149 # define __NR_name_to_handle_at 345
150 # elif defined(__arc__)
151 # define __NR_name_to_handle_at 264
153 # error "__NR_name_to_handle_at is not defined"
158 unsigned int handle_bytes
;
160 unsigned char f_handle
[0];
163 static inline int missing_name_to_handle_at(int fd
, const char *name
, struct file_handle
*handle
, int *mnt_id
, int flags
) {
164 # ifdef __NR_name_to_handle_at
165 return syscall(__NR_name_to_handle_at
, fd
, name
, handle
, mnt_id
, flags
);
172 # define name_to_handle_at missing_name_to_handle_at
175 /* ======================================================================= */
179 # if defined(__x86_64__)
180 # define __NR_setns 308
181 # elif defined(__i386__)
182 # define __NR_setns 346
183 # elif defined(__arc__)
184 # define __NR_setns 268
186 # error "__NR_setns is not defined"
190 static inline int missing_setns(int fd
, int nstype
) {
192 return syscall(__NR_setns
, fd
, nstype
);
199 # define setns missing_setns
202 /* ======================================================================= */
204 static inline pid_t
raw_getpid(void) {
205 #if defined(__alpha__)
206 return (pid_t
) syscall(__NR_getxpid
);
208 return (pid_t
) syscall(__NR_getpid
);
212 /* ======================================================================= */
215 # ifndef __NR_renameat2
216 # if defined __x86_64__
217 # define __NR_renameat2 316
218 # elif defined __arm__
219 # define __NR_renameat2 382
220 # elif defined __aarch64__
221 # define __NR_renameat2 276
222 # elif defined _MIPS_SIM
223 # if _MIPS_SIM == _MIPS_SIM_ABI32
224 # define __NR_renameat2 4351
226 # if _MIPS_SIM == _MIPS_SIM_NABI32
227 # define __NR_renameat2 6315
229 # if _MIPS_SIM == _MIPS_SIM_ABI64
230 # define __NR_renameat2 5311
232 # elif defined __i386__
233 # define __NR_renameat2 353
234 # elif defined __powerpc64__
235 # define __NR_renameat2 357
236 # elif defined __s390__ || defined __s390x__
237 # define __NR_renameat2 347
238 # elif defined __arc__
239 # define __NR_renameat2 276
241 # warning "__NR_renameat2 unknown for your architecture"
245 static inline int missing_renameat2(int oldfd
, const char *oldname
, int newfd
, const char *newname
, unsigned flags
) {
246 # ifdef __NR_renameat2
247 return syscall(__NR_renameat2
, oldfd
, oldname
, newfd
, newname
, flags
);
254 # define renameat2 missing_renameat2
257 /* ======================================================================= */
260 static inline int missing_kcmp(pid_t pid1
, pid_t pid2
, int type
, unsigned long idx1
, unsigned long idx2
) {
262 return syscall(__NR_kcmp
, pid1
, pid2
, type
, idx1
, idx2
);
269 # define kcmp missing_kcmp
273 /* ======================================================================= */
276 static inline long missing_keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
, unsigned long arg4
,unsigned long arg5
) {
278 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
284 # define keyctl missing_keyctl
287 static inline key_serial_t
missing_add_key(const char *type
, const char *description
, const void *payload
, size_t plen
, key_serial_t ringid
) {
289 return syscall(__NR_add_key
, type
, description
, payload
, plen
, ringid
);
295 # define add_key missing_add_key
298 static inline key_serial_t
missing_request_key(const char *type
, const char *description
, const char * callout_info
, key_serial_t destringid
) {
299 # ifdef __NR_request_key
300 return syscall(__NR_request_key
, type
, description
, callout_info
, destringid
);
306 # define request_key missing_request_key
310 /* ======================================================================= */
312 #if !HAVE_COPY_FILE_RANGE
313 # ifndef __NR_copy_file_range
314 # if defined(__x86_64__)
315 # define __NR_copy_file_range 326
316 # elif defined(__i386__)
317 # define __NR_copy_file_range 377
318 # elif defined __s390__
319 # define __NR_copy_file_range 375
320 # elif defined __arm__
321 # define __NR_copy_file_range 391
322 # elif defined __aarch64__
323 # define __NR_copy_file_range 285
324 # elif defined __powerpc__
325 # define __NR_copy_file_range 379
326 # elif defined __arc__
327 # define __NR_copy_file_range 285
329 # warning "__NR_copy_file_range not defined for your architecture"
333 static inline ssize_t
missing_copy_file_range(int fd_in
, loff_t
*off_in
,
334 int fd_out
, loff_t
*off_out
,
336 unsigned int flags
) {
337 # ifdef __NR_copy_file_range
338 return syscall(__NR_copy_file_range
, fd_in
, off_in
, fd_out
, off_out
, len
, flags
);
345 # define copy_file_range missing_copy_file_range
348 /* ======================================================================= */
352 # if defined __i386__
353 # define __NR_bpf 357
354 # elif defined __x86_64__
355 # define __NR_bpf 321
356 # elif defined __aarch64__
357 # define __NR_bpf 280
358 # elif defined __arm__
359 # define __NR_bpf 386
360 # elif defined __sparc__
361 # define __NR_bpf 349
362 # elif defined __s390__
363 # define __NR_bpf 351
364 # elif defined __tilegx__
365 # define __NR_bpf 280
367 # warning "__NR_bpf not defined for your architecture"
373 static inline int missing_bpf(int cmd
, union bpf_attr
*attr
, size_t size
) {
375 return (int) syscall(__NR_bpf
, cmd
, attr
, size
);
382 # define bpf missing_bpf
385 /* ======================================================================= */
387 #ifndef __IGNORE_pkey_mprotect
388 # ifndef __NR_pkey_mprotect
389 # if defined __i386__
390 # define __NR_pkey_mprotect 380
391 # elif defined __x86_64__
392 # define __NR_pkey_mprotect 329
393 # elif defined __arm__
394 # define __NR_pkey_mprotect 394
395 # elif defined __aarch64__
396 # define __NR_pkey_mprotect 394
397 # elif defined _MIPS_SIM
398 # if _MIPS_SIM == _MIPS_SIM_ABI32
399 # define __NR_pkey_mprotect 4363
401 # if _MIPS_SIM == _MIPS_SIM_NABI32
402 # define __NR_pkey_mprotect 6327
404 # if _MIPS_SIM == _MIPS_SIM_ABI64
405 # define __NR_pkey_mprotect 5323
408 # warning "__NR_pkey_mprotect not defined for your architecture"
413 /* ======================================================================= */
417 # if defined __i386__
418 # define __NR_statx 383
419 # elif defined __x86_64__
420 # define __NR_statx 332
422 # warning "__NR_statx not defined for your architecture"
429 /* This typedef is supposed to be always defined. */
430 typedef struct statx struct_statx
;
433 static inline ssize_t
missing_statx(int dfd
, const char *filename
, unsigned flags
, unsigned int mask
, struct statx
*buffer
) {
435 return syscall(__NR_statx
, dfd
, filename
, flags
, mask
, buffer
);
442 # define statx missing_statx