]>
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_lxc(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
);
116 #define memfd_create memfd_create_lxc
118 extern int memfd_create(const char *name
, unsigned int flags
);
122 static int pivot_root(const char *new_root
, const char *put_old
)
124 #ifdef __NR_pivot_root
125 return syscall(__NR_pivot_root
, new_root
, put_old
);
132 extern int pivot_root(const char *new_root
, const char *put_old
);
135 #if !defined(__NR_setns) && !defined(__NR_set_ns)
136 #if defined(__x86_64__)
137 #define __NR_setns 308
138 #elif defined(__i386__)
139 #define __NR_setns 346
140 #elif defined(__arm__)
141 #define __NR_setns 375
142 #elif defined(__aarch64__)
143 #define __NR_setns 375
144 #elif defined(__powerpc__)
145 #define __NR_setns 350
146 #elif defined(__s390__)
147 #define __NR_setns 339
151 /* Define sethostname() if missing from the C library */
152 #ifndef HAVE_SETHOSTNAME
153 static inline int sethostname(const char *name
, size_t len
)
155 #ifdef __NR_sethostname
156 return syscall(__NR_sethostname
, name
, len
);
164 /* Define setns() if missing from the C library */
166 static inline int setns(int fd
, int nstype
)
169 return syscall(__NR_setns
, fd
, nstype
);
170 #elif defined(__NR_set_ns)
171 return syscall(__NR_set_ns
, fd
, nstype
);
179 #ifndef HAVE_SYS_SIGNALFD_H
180 struct signalfd_siginfo
{
189 uint32_t ssi_overrun
;
200 #ifndef __NR_signalfd4
201 /* assume kernel headers are too old */
203 #define __NR_signalfd4 327
205 #define __NR_signalfd4 289
207 #define __NR_signalfd4 313
209 #define __NR_signalfd4 322
211 #define __NR_signalfd4 355
212 #elif __mips__ && _MIPS_SIM == _ABIO32
213 #define __NR_signalfd4 4324
214 #elif __mips__ && _MIPS_SIM == _ABI64
215 #define __NR_signalfd4 5283
216 #elif __mips__ && _MIPS_SIM == _ABIN32
217 #define __NR_signalfd4 6287
221 #ifndef __NR_signalfd
222 /* assume kernel headers are too old */
224 #define __NR_signalfd 321
226 #define __NR_signalfd 282
228 #define __NR_signalfd 305
230 #define __NR_signalfd 316
232 #define __NR_signalfd 349
233 #elif __mips__ && _MIPS_SIM == _ABIO32
234 #define __NR_signalfd 4317
235 #elif __mips__ && _MIPS_SIM == _ABI64
236 #define __NR_signalfd 5276
237 #elif __mips__ && _MIPS_SIM == _ABIN32
238 #define __NR_signalfd 6280
242 static inline int signalfd(int fd
, const sigset_t
*mask
, int flags
)
246 retval
= syscall(__NR_signalfd4
, fd
, mask
, _NSIG
/ 8, flags
);
247 if (errno
== ENOSYS
&& flags
== 0)
248 retval
= syscall(__NR_signalfd
, fd
, mask
, _NSIG
/ 8);
254 /* Define unshare() if missing from the C library */
256 static inline int unshare(int flags
)
259 return syscall(__NR_unshare
, flags
);
266 extern int unshare(int);
269 #endif /* __LXC_SYSCALL_WRAPPER_H */