]>
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 pivot_root(const char *new_root
, const char *put_old
) {
30 return syscall(SYS_pivot_root
, new_root
, put_old
);
34 /* ======================================================================= */
36 #if !HAVE_MEMFD_CREATE
37 # ifndef __NR_memfd_create
38 # if defined __x86_64__
39 # define __NR_memfd_create 319
40 # elif defined __arm__
41 # define __NR_memfd_create 385
42 # elif defined __aarch64__
43 # define __NR_memfd_create 279
44 # elif defined __s390__
45 # define __NR_memfd_create 350
46 # elif defined _MIPS_SIM
47 # if _MIPS_SIM == _MIPS_SIM_ABI32
48 # define __NR_memfd_create 4354
50 # if _MIPS_SIM == _MIPS_SIM_NABI32
51 # define __NR_memfd_create 6318
53 # if _MIPS_SIM == _MIPS_SIM_ABI64
54 # define __NR_memfd_create 5314
56 # elif defined __i386__
57 # define __NR_memfd_create 356
58 # elif defined __arc__
59 # define __NR_memfd_create 279
61 # warning "__NR_memfd_create unknown for your architecture"
65 static inline int memfd_create(const char *name
, unsigned int flags
) {
66 # ifdef __NR_memfd_create
67 return syscall(__NR_memfd_create
, name
, flags
);
75 /* ======================================================================= */
78 # ifndef __NR_getrandom
79 # if defined __x86_64__
80 # define __NR_getrandom 318
81 # elif defined(__i386__)
82 # define __NR_getrandom 355
83 # elif defined(__arm__)
84 # define __NR_getrandom 384
85 # elif defined(__aarch64__)
86 # define __NR_getrandom 278
87 # elif defined(__ia64__)
88 # define __NR_getrandom 1339
89 # elif defined(__m68k__)
90 # define __NR_getrandom 352
91 # elif defined(__s390x__)
92 # define __NR_getrandom 349
93 # elif defined(__powerpc__)
94 # define __NR_getrandom 359
95 # elif defined _MIPS_SIM
96 # if _MIPS_SIM == _MIPS_SIM_ABI32
97 # define __NR_getrandom 4353
99 # if _MIPS_SIM == _MIPS_SIM_NABI32
100 # define __NR_getrandom 6317
102 # if _MIPS_SIM == _MIPS_SIM_ABI64
103 # define __NR_getrandom 5313
105 # elif defined(__arc__)
106 # define __NR_getrandom 278
108 # warning "__NR_getrandom unknown for your architecture"
112 static inline int getrandom(void *buffer
, size_t count
, unsigned flags
) {
113 # ifdef __NR_getrandom
114 return syscall(__NR_getrandom
, buffer
, count
, flags
);
122 /* ======================================================================= */
125 static inline pid_t
gettid(void) {
126 return (pid_t
) syscall(SYS_gettid
);
130 /* ======================================================================= */
132 #if !HAVE_NAME_TO_HANDLE_AT
133 # ifndef __NR_name_to_handle_at
134 # if defined(__x86_64__)
135 # define __NR_name_to_handle_at 303
136 # elif defined(__i386__)
137 # define __NR_name_to_handle_at 341
138 # elif defined(__arm__)
139 # define __NR_name_to_handle_at 370
140 # elif defined(__powerpc__)
141 # define __NR_name_to_handle_at 345
142 # elif defined(__arc__)
143 # define __NR_name_to_handle_at 264
145 # error "__NR_name_to_handle_at is not defined"
150 unsigned int handle_bytes
;
152 unsigned char f_handle
[0];
155 static inline int name_to_handle_at(int fd
, const char *name
, struct file_handle
*handle
, int *mnt_id
, int flags
) {
156 # ifdef __NR_name_to_handle_at
157 return syscall(__NR_name_to_handle_at
, fd
, name
, handle
, mnt_id
, flags
);
165 /* ======================================================================= */
169 # if defined(__x86_64__)
170 # define __NR_setns 308
171 # elif defined(__i386__)
172 # define __NR_setns 346
173 # elif defined(__arc__)
174 # define __NR_setns 268
176 # error "__NR_setns is not defined"
180 static inline int setns(int fd
, int nstype
) {
182 return syscall(__NR_setns
, fd
, nstype
);
190 /* ======================================================================= */
192 static inline pid_t
raw_getpid(void) {
193 #if defined(__alpha__)
194 return (pid_t
) syscall(__NR_getxpid
);
196 return (pid_t
) syscall(__NR_getpid
);
200 /* ======================================================================= */
203 # ifndef __NR_renameat2
204 # if defined __x86_64__
205 # define __NR_renameat2 316
206 # elif defined __arm__
207 # define __NR_renameat2 382
208 # elif defined __aarch64__
209 # define __NR_renameat2 276
210 # elif defined _MIPS_SIM
211 # if _MIPS_SIM == _MIPS_SIM_ABI32
212 # define __NR_renameat2 4351
214 # if _MIPS_SIM == _MIPS_SIM_NABI32
215 # define __NR_renameat2 6315
217 # if _MIPS_SIM == _MIPS_SIM_ABI64
218 # define __NR_renameat2 5311
220 # elif defined __i386__
221 # define __NR_renameat2 353
222 # elif defined __powerpc64__
223 # define __NR_renameat2 357
224 # elif defined __s390__ || defined __s390x__
225 # define __NR_renameat2 347
226 # elif defined __arc__
227 # define __NR_renameat2 276
229 # warning "__NR_renameat2 unknown for your architecture"
233 static inline int renameat2(int oldfd
, const char *oldname
, int newfd
, const char *newname
, unsigned flags
) {
234 # ifdef __NR_renameat2
235 return syscall(__NR_renameat2
, oldfd
, oldname
, newfd
, newname
, flags
);
243 /* ======================================================================= */
246 static inline int kcmp(pid_t pid1
, pid_t pid2
, int type
, unsigned long idx1
, unsigned long idx2
) {
248 return syscall(__NR_kcmp
, pid1
, pid2
, type
, idx1
, idx2
);
256 /* ======================================================================= */
259 static inline long keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
, unsigned long arg4
,unsigned long arg5
) {
261 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
268 static inline key_serial_t
add_key(const char *type
, const char *description
, const void *payload
, size_t plen
, key_serial_t ringid
) {
270 return syscall(__NR_add_key
, type
, description
, payload
, plen
, ringid
);
277 static inline key_serial_t
request_key(const char *type
, const char *description
, const char * callout_info
, key_serial_t destringid
) {
278 # ifdef __NR_request_key
279 return syscall(__NR_request_key
, type
, description
, callout_info
, destringid
);
287 /* ======================================================================= */
289 #if !HAVE_COPY_FILE_RANGE
290 # ifndef __NR_copy_file_range
291 # if defined(__x86_64__)
292 # define __NR_copy_file_range 326
293 # elif defined(__i386__)
294 # define __NR_copy_file_range 377
295 # elif defined __s390__
296 # define __NR_copy_file_range 375
297 # elif defined __arm__
298 # define __NR_copy_file_range 391
299 # elif defined __aarch64__
300 # define __NR_copy_file_range 285
301 # elif defined __powerpc__
302 # define __NR_copy_file_range 379
303 # elif defined __arc__
304 # define __NR_copy_file_range 285
306 # warning "__NR_copy_file_range not defined for your architecture"
310 static inline ssize_t
copy_file_range(int fd_in
, loff_t
*off_in
,
311 int fd_out
, loff_t
*off_out
,
313 unsigned int flags
) {
314 # ifdef __NR_copy_file_range
315 return syscall(__NR_copy_file_range
, fd_in
, off_in
, fd_out
, off_out
, len
, flags
);
323 /* ======================================================================= */
327 # if defined __i386__
328 # define __NR_bpf 357
329 # elif defined __x86_64__
330 # define __NR_bpf 321
331 # elif defined __aarch64__
332 # define __NR_bpf 280
333 # elif defined __arm__
334 # define __NR_bpf 386
335 # elif defined __sparc__
336 # define __NR_bpf 349
337 # elif defined __s390__
338 # define __NR_bpf 351
339 # elif defined __tilegx__
340 # define __NR_bpf 280
342 # warning "__NR_bpf not defined for your architecture"
348 static inline int bpf(int cmd
, union bpf_attr
*attr
, size_t size
) {
350 return (int) syscall(__NR_bpf
, cmd
, attr
, size
);
359 /* ======================================================================= */
361 #ifndef __IGNORE_pkey_mprotect
362 # ifndef __NR_pkey_mprotect
363 # if defined __i386__
364 # define __NR_pkey_mprotect 380
365 # elif defined __x86_64__
366 # define __NR_pkey_mprotect 329
367 # elif defined __arm__
368 # define __NR_pkey_mprotect 394
369 # elif defined __aarch64__
370 # define __NR_pkey_mprotect 394
371 # elif defined _MIPS_SIM
372 # if _MIPS_SIM == _MIPS_SIM_ABI32
373 # define __NR_pkey_mprotect 4363
375 # if _MIPS_SIM == _MIPS_SIM_NABI32
376 # define __NR_pkey_mprotect 6327
378 # if _MIPS_SIM == _MIPS_SIM_ABI64
379 # define __NR_pkey_mprotect 5323
382 # warning "__NR_pkey_mprotect not defined for your architecture"
389 # if defined __i386__
390 # define __NR_bpf 383
391 # elif defined __x86_64__
392 # define __NR_bpf 332
394 # warning "__NR_statx not defined for your architecture"
400 static inline ssize_t
statx(int dfd
, const char *filename
, unsigned flags
, unsigned int mask
, struct statx
*buffer
) {
402 return syscall(__NR_statx
, dfd
, filename
, flags
, mask
, buffer
);