]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/missing_syscall.h
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
7 Copyright 2016 Zbigniew Jędrzejewski-Szmek
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 /* Missing glibc definitions to access certain kernel APIs */
25 #include <sys/types.h>
28 static inline int pivot_root(const char *new_root
, const char *put_old
) {
29 return syscall(SYS_pivot_root
, new_root
, put_old
);
33 /* ======================================================================= */
35 #if !HAVE_MEMFD_CREATE
36 # ifndef __NR_memfd_create
37 # if defined __x86_64__
38 # define __NR_memfd_create 319
39 # elif defined __arm__
40 # define __NR_memfd_create 385
41 # elif defined __aarch64__
42 # define __NR_memfd_create 279
43 # elif defined __s390__
44 # define __NR_memfd_create 350
45 # elif defined _MIPS_SIM
46 # if _MIPS_SIM == _MIPS_SIM_ABI32
47 # define __NR_memfd_create 4354
49 # if _MIPS_SIM == _MIPS_SIM_NABI32
50 # define __NR_memfd_create 6318
52 # if _MIPS_SIM == _MIPS_SIM_ABI64
53 # define __NR_memfd_create 5314
55 # elif defined __i386__
56 # define __NR_memfd_create 356
57 # elif defined __arc__
58 # define __NR_memfd_create 279
60 # warning "__NR_memfd_create unknown for your architecture"
64 static inline int memfd_create(const char *name
, unsigned int flags
) {
65 # ifdef __NR_memfd_create
66 return syscall(__NR_memfd_create
, name
, flags
);
74 /* ======================================================================= */
77 # ifndef __NR_getrandom
78 # if defined __x86_64__
79 # define __NR_getrandom 318
80 # elif defined(__i386__)
81 # define __NR_getrandom 355
82 # elif defined(__arm__)
83 # define __NR_getrandom 384
84 # elif defined(__aarch64__)
85 # define __NR_getrandom 278
86 # elif defined(__ia64__)
87 # define __NR_getrandom 1339
88 # elif defined(__m68k__)
89 # define __NR_getrandom 352
90 # elif defined(__s390x__)
91 # define __NR_getrandom 349
92 # elif defined(__powerpc__)
93 # define __NR_getrandom 359
94 # elif defined _MIPS_SIM
95 # if _MIPS_SIM == _MIPS_SIM_ABI32
96 # define __NR_getrandom 4353
98 # if _MIPS_SIM == _MIPS_SIM_NABI32
99 # define __NR_getrandom 6317
101 # if _MIPS_SIM == _MIPS_SIM_ABI64
102 # define __NR_getrandom 5313
104 # elif defined(__arc__)
105 # define __NR_getrandom 278
107 # warning "__NR_getrandom unknown for your architecture"
111 static inline int getrandom(void *buffer
, size_t count
, unsigned flags
) {
112 # ifdef __NR_getrandom
113 return syscall(__NR_getrandom
, buffer
, count
, flags
);
121 /* ======================================================================= */
124 static inline pid_t
gettid(void) {
125 return (pid_t
) syscall(SYS_gettid
);
129 /* ======================================================================= */
131 #if !HAVE_NAME_TO_HANDLE_AT
132 # ifndef __NR_name_to_handle_at
133 # if defined(__x86_64__)
134 # define __NR_name_to_handle_at 303
135 # elif defined(__i386__)
136 # define __NR_name_to_handle_at 341
137 # elif defined(__arm__)
138 # define __NR_name_to_handle_at 370
139 # elif defined(__powerpc__)
140 # define __NR_name_to_handle_at 345
141 # elif defined(__arc__)
142 # define __NR_name_to_handle_at 264
144 # error "__NR_name_to_handle_at is not defined"
149 unsigned int handle_bytes
;
151 unsigned char f_handle
[0];
154 static inline int name_to_handle_at(int fd
, const char *name
, struct file_handle
*handle
, int *mnt_id
, int flags
) {
155 # ifdef __NR_name_to_handle_at
156 return syscall(__NR_name_to_handle_at
, fd
, name
, handle
, mnt_id
, flags
);
164 /* ======================================================================= */
168 # if defined(__x86_64__)
169 # define __NR_setns 308
170 # elif defined(__i386__)
171 # define __NR_setns 346
172 # elif defined(__arc__)
173 # define __NR_setns 268
175 # error "__NR_setns is not defined"
179 static inline int setns(int fd
, int nstype
) {
181 return syscall(__NR_setns
, fd
, nstype
);
189 /* ======================================================================= */
191 static inline pid_t
raw_getpid(void) {
192 #if defined(__alpha__)
193 return (pid_t
) syscall(__NR_getxpid
);
195 return (pid_t
) syscall(__NR_getpid
);
199 /* ======================================================================= */
202 # ifndef __NR_renameat2
203 # if defined __x86_64__
204 # define __NR_renameat2 316
205 # elif defined __arm__
206 # define __NR_renameat2 382
207 # elif defined __aarch64__
208 # define __NR_renameat2 276
209 # elif defined _MIPS_SIM
210 # if _MIPS_SIM == _MIPS_SIM_ABI32
211 # define __NR_renameat2 4351
213 # if _MIPS_SIM == _MIPS_SIM_NABI32
214 # define __NR_renameat2 6315
216 # if _MIPS_SIM == _MIPS_SIM_ABI64
217 # define __NR_renameat2 5311
219 # elif defined __i386__
220 # define __NR_renameat2 353
221 # elif defined __powerpc64__
222 # define __NR_renameat2 357
223 # elif defined __s390__ || defined __s390x__
224 # define __NR_renameat2 347
225 # elif defined __arc__
226 # define __NR_renameat2 276
228 # warning "__NR_renameat2 unknown for your architecture"
232 static inline int renameat2(int oldfd
, const char *oldname
, int newfd
, const char *newname
, unsigned flags
) {
233 # ifdef __NR_renameat2
234 return syscall(__NR_renameat2
, oldfd
, oldname
, newfd
, newname
, flags
);
242 /* ======================================================================= */
245 static inline int kcmp(pid_t pid1
, pid_t pid2
, int type
, unsigned long idx1
, unsigned long idx2
) {
247 return syscall(__NR_kcmp
, pid1
, pid2
, type
, idx1
, idx2
);
255 /* ======================================================================= */
258 static inline long keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
, unsigned long arg4
,unsigned long arg5
) {
260 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
267 static inline key_serial_t
add_key(const char *type
, const char *description
, const void *payload
, size_t plen
, key_serial_t ringid
) {
269 return syscall(__NR_add_key
, type
, description
, payload
, plen
, ringid
);
276 static inline key_serial_t
request_key(const char *type
, const char *description
, const char * callout_info
, key_serial_t destringid
) {
277 # ifdef __NR_request_key
278 return syscall(__NR_request_key
, type
, description
, callout_info
, destringid
);
286 /* ======================================================================= */
288 #if !HAVE_COPY_FILE_RANGE
289 # ifndef __NR_copy_file_range
290 # if defined(__x86_64__)
291 # define __NR_copy_file_range 326
292 # elif defined(__i386__)
293 # define __NR_copy_file_range 377
294 # elif defined __s390__
295 # define __NR_copy_file_range 375
296 # elif defined __arm__
297 # define __NR_copy_file_range 391
298 # elif defined __aarch64__
299 # define __NR_copy_file_range 285
300 # elif defined __powerpc__
301 # define __NR_copy_file_range 379
302 # elif defined __arc__
303 # define __NR_copy_file_range 285
305 # warning "__NR_copy_file_range not defined for your architecture"
309 static inline ssize_t
copy_file_range(int fd_in
, loff_t
*off_in
,
310 int fd_out
, loff_t
*off_out
,
312 unsigned int flags
) {
313 # ifdef __NR_copy_file_range
314 return syscall(__NR_copy_file_range
, fd_in
, off_in
, fd_out
, off_out
, len
, flags
);
324 # if defined __i386__
325 # define __NR_bpf 357
326 # elif defined __x86_64__
327 # define __NR_bpf 321
328 # elif defined __aarch64__
329 # define __NR_bpf 280
330 # elif defined __sparc__
331 # define __NR_bpf 349
332 # elif defined __s390__
333 # define __NR_bpf 351
335 # warning "__NR_bpf not defined for your architecture"
341 static inline int bpf(int cmd
, union bpf_attr
*attr
, size_t size
) {
343 return (int) syscall(__NR_bpf
, cmd
, attr
, size
);