]>
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 program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef __LXC_SYSCALL_WRAPPER_H
21 #define __LXC_SYSCALL_WRAPPER_H
26 #include <asm/unistd.h>
28 #include <linux/keyctl.h>
31 #include <sys/syscall.h>
32 #include <sys/types.h>
37 #ifdef HAVE_LINUX_MEMFD_H
38 #include <linux/memfd.h>
41 #ifdef HAVE_SYS_SIGNALFD_H
42 #include <sys/signalfd.h>
45 typedef int32_t key_serial_t
;
48 static inline long __keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
,
49 unsigned long arg4
, unsigned long arg5
)
52 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
58 #define keyctl __keyctl
61 #ifndef HAVE_MEMFD_CREATE
62 static inline int memfd_create(const char *name
, unsigned int flags
) {
63 #ifndef __NR_memfd_create
65 #define __NR_memfd_create 356
66 #elif defined __x86_64__
67 #define __NR_memfd_create 319
69 #define __NR_memfd_create 385
70 #elif defined __aarch64__
71 #define __NR_memfd_create 279
72 #elif defined __s390__
73 #define __NR_memfd_create 350
74 #elif defined __powerpc__
75 #define __NR_memfd_create 360
76 #elif defined __sparc__
77 #define __NR_memfd_create 348
78 #elif defined __blackfin__
79 #define __NR_memfd_create 390
80 #elif defined __ia64__
81 #define __NR_memfd_create 1340
82 #elif defined _MIPS_SIM
83 #if _MIPS_SIM == _MIPS_SIM_ABI32
84 #define __NR_memfd_create 4354
86 #if _MIPS_SIM == _MIPS_SIM_NABI32
87 #define __NR_memfd_create 6318
89 #if _MIPS_SIM == _MIPS_SIM_ABI64
90 #define __NR_memfd_create 5314
94 #ifdef __NR_memfd_create
95 return syscall(__NR_memfd_create
, name
, flags
);
102 extern int memfd_create(const char *name
, unsigned int flags
);
106 static int pivot_root(const char *new_root
, const char *put_old
)
108 #ifdef __NR_pivot_root
109 return syscall(__NR_pivot_root
, new_root
, put_old
);
116 extern int pivot_root(const char *new_root
, const char *put_old
);
119 #if !defined(__NR_setns) && !defined(__NR_set_ns)
120 #if defined(__x86_64__)
121 #define __NR_setns 308
122 #elif defined(__i386__)
123 #define __NR_setns 346
124 #elif defined(__arm__)
125 #define __NR_setns 375
126 #elif defined(__aarch64__)
127 #define __NR_setns 375
128 #elif defined(__powerpc__)
129 #define __NR_setns 350
130 #elif defined(__s390__)
131 #define __NR_setns 339
135 /* Define sethostname() if missing from the C library */
136 #ifndef HAVE_SETHOSTNAME
137 static inline int sethostname(const char *name
, size_t len
)
139 #ifdef __NR_sethostname
140 return syscall(__NR_sethostname
, name
, len
);
148 /* Define setns() if missing from the C library */
150 static inline int setns(int fd
, int nstype
)
153 return syscall(__NR_setns
, fd
, nstype
);
154 #elif defined(__NR_set_ns)
155 return syscall(__NR_set_ns
, fd
, nstype
);
163 #ifndef HAVE_SYS_SIGNALFD_H
164 struct signalfd_siginfo
{
173 uint32_t ssi_overrun
;
184 #ifndef __NR_signalfd4
185 /* assume kernel headers are too old */
187 #define __NR_signalfd4 327
189 #define __NR_signalfd4 289
191 #define __NR_signalfd4 313
193 #define __NR_signalfd4 322
195 #define __NR_signalfd4 355
196 #elif __mips__ && _MIPS_SIM == _ABIO32
197 #define __NR_signalfd4 4324
198 #elif __mips__ && _MIPS_SIM == _ABI64
199 #define __NR_signalfd4 5283
200 #elif __mips__ && _MIPS_SIM == _ABIN32
201 #define __NR_signalfd4 6287
205 #ifndef __NR_signalfd
206 /* assume kernel headers are too old */
208 #define __NR_signalfd 321
210 #define __NR_signalfd 282
212 #define __NR_signalfd 305
214 #define __NR_signalfd 316
216 #define __NR_signalfd 349
217 #elif __mips__ && _MIPS_SIM == _ABIO32
218 #define __NR_signalfd 4317
219 #elif __mips__ && _MIPS_SIM == _ABI64
220 #define __NR_signalfd 5276
221 #elif __mips__ && _MIPS_SIM == _ABIN32
222 #define __NR_signalfd 6280
226 static inline int signalfd(int fd
, const sigset_t
*mask
, int flags
)
230 retval
= syscall(__NR_signalfd4
, fd
, mask
, _NSIG
/ 8, flags
);
231 if (errno
== ENOSYS
&& flags
== 0)
232 retval
= syscall(__NR_signalfd
, fd
, mask
, _NSIG
/ 8);
238 /* Define unshare() if missing from the C library */
240 static inline int unshare(int flags
)
243 return syscall(__NR_unshare
, flags
);
250 extern int unshare(int);
253 #endif /* __LXC_SYSCALL_WRAPPER_H */