]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/syscall_wrappers.h
3 * Copyright © 2018 Christian Brauner <christian.brauner@ubuntu.com>.
4 * Copyright © 2018 Canonical Ltd.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef __LXC_SYSCALL_WRAPPER_H
22 #define __LXC_SYSCALL_WRAPPER_H
27 #include <asm/unistd.h>
29 #include <linux/keyctl.h>
32 #include <sys/syscall.h>
33 #include <sys/types.h>
38 #ifdef HAVE_LINUX_MEMFD_H
39 #include <linux/memfd.h>
42 #ifdef HAVE_SYS_SIGNALFD_H
43 #include <sys/signalfd.h>
46 typedef int32_t key_serial_t
;
49 static inline long __keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
,
50 unsigned long arg4
, unsigned long arg5
)
53 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
59 #define keyctl __keyctl
62 #ifndef F_LINUX_SPECIFIC_BASE
63 #define F_LINUX_SPECIFIC_BASE 1024
66 #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
67 #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
70 #define F_SEAL_SEAL 0x0001
71 #define F_SEAL_SHRINK 0x0002
72 #define F_SEAL_GROW 0x0004
73 #define F_SEAL_WRITE 0x0008
76 #ifndef HAVE_MEMFD_CREATE
77 static inline int memfd_create(const char *name
, unsigned int flags
) {
78 #ifndef __NR_memfd_create
80 #define __NR_memfd_create 356
81 #elif defined __x86_64__
82 #define __NR_memfd_create 319
84 #define __NR_memfd_create 385
85 #elif defined __aarch64__
86 #define __NR_memfd_create 279
87 #elif defined __s390__
88 #define __NR_memfd_create 350
89 #elif defined __powerpc__
90 #define __NR_memfd_create 360
91 #elif defined __sparc__
92 #define __NR_memfd_create 348
93 #elif defined __blackfin__
94 #define __NR_memfd_create 390
95 #elif defined __ia64__
96 #define __NR_memfd_create 1340
97 #elif defined _MIPS_SIM
98 #if _MIPS_SIM == _MIPS_SIM_ABI32
99 #define __NR_memfd_create 4354
101 #if _MIPS_SIM == _MIPS_SIM_NABI32
102 #define __NR_memfd_create 6318
104 #if _MIPS_SIM == _MIPS_SIM_ABI64
105 #define __NR_memfd_create 5314
109 #ifdef __NR_memfd_create
110 return syscall(__NR_memfd_create
, name
, flags
);
117 extern int memfd_create(const char *name
, unsigned int flags
);
121 static int pivot_root(const char *new_root
, const char *put_old
)
123 #ifdef __NR_pivot_root
124 return syscall(__NR_pivot_root
, new_root
, put_old
);
131 extern int pivot_root(const char *new_root
, const char *put_old
);
134 #if !defined(__NR_setns) && !defined(__NR_set_ns)
135 #if defined(__x86_64__)
136 #define __NR_setns 308
137 #elif defined(__i386__)
138 #define __NR_setns 346
139 #elif defined(__arm__)
140 #define __NR_setns 375
141 #elif defined(__aarch64__)
142 #define __NR_setns 375
143 #elif defined(__powerpc__)
144 #define __NR_setns 350
145 #elif defined(__s390__)
146 #define __NR_setns 339
150 /* Define sethostname() if missing from the C library */
151 #ifndef HAVE_SETHOSTNAME
152 static inline int sethostname(const char *name
, size_t len
)
154 #ifdef __NR_sethostname
155 return syscall(__NR_sethostname
, name
, len
);
163 /* Define setns() if missing from the C library */
165 static inline int setns(int fd
, int nstype
)
168 return syscall(__NR_setns
, fd
, nstype
);
169 #elif defined(__NR_set_ns)
170 return syscall(__NR_set_ns
, fd
, nstype
);
178 #ifndef HAVE_SYS_SIGNALFD_H
179 struct signalfd_siginfo
{
188 uint32_t ssi_overrun
;
199 #ifndef __NR_signalfd4
200 /* assume kernel headers are too old */
202 #define __NR_signalfd4 327
204 #define __NR_signalfd4 289
206 #define __NR_signalfd4 313
208 #define __NR_signalfd4 322
210 #define __NR_signalfd4 355
211 #elif __mips__ && _MIPS_SIM == _ABIO32
212 #define __NR_signalfd4 4324
213 #elif __mips__ && _MIPS_SIM == _ABI64
214 #define __NR_signalfd4 5283
215 #elif __mips__ && _MIPS_SIM == _ABIN32
216 #define __NR_signalfd4 6287
220 #ifndef __NR_signalfd
221 /* assume kernel headers are too old */
223 #define __NR_signalfd 321
225 #define __NR_signalfd 282
227 #define __NR_signalfd 305
229 #define __NR_signalfd 316
231 #define __NR_signalfd 349
232 #elif __mips__ && _MIPS_SIM == _ABIO32
233 #define __NR_signalfd 4317
234 #elif __mips__ && _MIPS_SIM == _ABI64
235 #define __NR_signalfd 5276
236 #elif __mips__ && _MIPS_SIM == _ABIN32
237 #define __NR_signalfd 6280
241 static inline int signalfd(int fd
, const sigset_t
*mask
, int flags
)
245 retval
= syscall(__NR_signalfd4
, fd
, mask
, _NSIG
/ 8, flags
);
246 if (errno
== ENOSYS
&& flags
== 0)
247 retval
= syscall(__NR_signalfd
, fd
, mask
, _NSIG
/ 8);
253 /* Define unshare() if missing from the C library */
255 static inline int unshare(int flags
)
258 return syscall(__NR_unshare
, flags
);
265 extern int unshare(int);
268 #endif /* __LXC_SYSCALL_WRAPPER_H */