]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/syscall_wrappers.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #ifndef __LXC_SYSCALL_WRAPPER_H
4 #define __LXC_SYSCALL_WRAPPER_H
9 #include <asm/unistd.h>
11 #include <linux/keyctl.h>
14 #include <sys/syscall.h>
15 #include <sys/types.h>
20 #ifdef HAVE_LINUX_MEMFD_H
21 #include <linux/memfd.h>
24 #ifdef HAVE_SYS_SIGNALFD_H
25 #include <sys/signalfd.h>
28 typedef int32_t key_serial_t
;
31 static inline long __keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
,
32 unsigned long arg4
, unsigned long arg5
)
35 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
41 #define keyctl __keyctl
44 #ifndef F_LINUX_SPECIFIC_BASE
45 #define F_LINUX_SPECIFIC_BASE 1024
48 #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
49 #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
52 #define F_SEAL_SEAL 0x0001
53 #define F_SEAL_SHRINK 0x0002
54 #define F_SEAL_GROW 0x0004
55 #define F_SEAL_WRITE 0x0008
58 #ifndef HAVE_MEMFD_CREATE
59 static inline int memfd_create_lxc(const char *name
, unsigned int flags
) {
60 #ifndef __NR_memfd_create
62 #define __NR_memfd_create 356
63 #elif defined __x86_64__
64 #define __NR_memfd_create 319
66 #define __NR_memfd_create 385
67 #elif defined __aarch64__
68 #define __NR_memfd_create 279
69 #elif defined __s390__
70 #define __NR_memfd_create 350
71 #elif defined __powerpc__
72 #define __NR_memfd_create 360
73 #elif defined __sparc__
74 #define __NR_memfd_create 348
75 #elif defined __blackfin__
76 #define __NR_memfd_create 390
77 #elif defined __ia64__
78 #define __NR_memfd_create 1340
79 #elif defined _MIPS_SIM
80 #if _MIPS_SIM == _MIPS_SIM_ABI32
81 #define __NR_memfd_create 4354
83 #if _MIPS_SIM == _MIPS_SIM_NABI32
84 #define __NR_memfd_create 6318
86 #if _MIPS_SIM == _MIPS_SIM_ABI64
87 #define __NR_memfd_create 5314
91 #ifdef __NR_memfd_create
92 return syscall(__NR_memfd_create
, name
, flags
);
98 #define memfd_create memfd_create_lxc
100 extern int memfd_create(const char *name
, unsigned int flags
);
104 static int pivot_root(const char *new_root
, const char *put_old
)
106 #ifdef __NR_pivot_root
107 return syscall(__NR_pivot_root
, new_root
, put_old
);
114 extern int pivot_root(const char *new_root
, const char *put_old
);
117 #if !defined(__NR_setns) && !defined(__NR_set_ns)
118 #if defined(__x86_64__)
119 #define __NR_setns 308
120 #elif defined(__i386__)
121 #define __NR_setns 346
122 #elif defined(__arm__)
123 #define __NR_setns 375
124 #elif defined(__aarch64__)
125 #define __NR_setns 375
126 #elif defined(__powerpc__)
127 #define __NR_setns 350
128 #elif defined(__s390__)
129 #define __NR_setns 339
133 /* Define sethostname() if missing from the C library */
134 #ifndef HAVE_SETHOSTNAME
135 static inline int sethostname(const char *name
, size_t len
)
137 #ifdef __NR_sethostname
138 return syscall(__NR_sethostname
, name
, len
);
146 /* Define setns() if missing from the C library */
148 static inline int setns(int fd
, int nstype
)
151 return syscall(__NR_setns
, fd
, nstype
);
152 #elif defined(__NR_set_ns)
153 return syscall(__NR_set_ns
, fd
, nstype
);
161 #ifndef HAVE_SYS_SIGNALFD_H
162 struct signalfd_siginfo
{
171 uint32_t ssi_overrun
;
182 #ifndef __NR_signalfd4
183 /* assume kernel headers are too old */
185 #define __NR_signalfd4 327
187 #define __NR_signalfd4 289
189 #define __NR_signalfd4 313
191 #define __NR_signalfd4 322
193 #define __NR_signalfd4 355
194 #elif __mips__ && _MIPS_SIM == _ABIO32
195 #define __NR_signalfd4 4324
196 #elif __mips__ && _MIPS_SIM == _ABI64
197 #define __NR_signalfd4 5283
198 #elif __mips__ && _MIPS_SIM == _ABIN32
199 #define __NR_signalfd4 6287
203 #ifndef __NR_signalfd
204 /* assume kernel headers are too old */
206 #define __NR_signalfd 321
208 #define __NR_signalfd 282
210 #define __NR_signalfd 305
212 #define __NR_signalfd 316
214 #define __NR_signalfd 349
215 #elif __mips__ && _MIPS_SIM == _ABIO32
216 #define __NR_signalfd 4317
217 #elif __mips__ && _MIPS_SIM == _ABI64
218 #define __NR_signalfd 5276
219 #elif __mips__ && _MIPS_SIM == _ABIN32
220 #define __NR_signalfd 6280
224 static inline int signalfd(int fd
, const sigset_t
*mask
, int flags
)
228 retval
= syscall(__NR_signalfd4
, fd
, mask
, _NSIG
/ 8, flags
);
229 if (errno
== ENOSYS
&& flags
== 0)
230 retval
= syscall(__NR_signalfd
, fd
, mask
, _NSIG
/ 8);
236 /* Define unshare() if missing from the C library */
238 static inline int unshare(int flags
)
241 return syscall(__NR_unshare
, flags
);
248 extern int unshare(int);
251 #endif /* __LXC_SYSCALL_WRAPPER_H */