]>
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>
27 #include <linux/keyctl.h>
30 #include <sys/syscall.h>
31 #include <sys/types.h>
36 #ifdef HAVE_LINUX_MEMFD_H
37 #include <linux/memfd.h>
40 typedef int32_t key_serial_t
;
43 static inline long __keyctl(int cmd
, unsigned long arg2
, unsigned long arg3
,
44 unsigned long arg4
, unsigned long arg5
)
47 return syscall(__NR_keyctl
, cmd
, arg2
, arg3
, arg4
, arg5
);
53 #define keyctl __keyctl
56 #ifndef HAVE_MEMFD_CREATE
57 static inline int memfd_create(const char *name
, unsigned int flags
) {
58 #ifndef __NR_memfd_create
60 #define __NR_memfd_create 356
61 #elif defined __x86_64__
62 #define __NR_memfd_create 319
64 #define __NR_memfd_create 385
65 #elif defined __aarch64__
66 #define __NR_memfd_create 279
67 #elif defined __s390__
68 #define __NR_memfd_create 350
69 #elif defined __powerpc__
70 #define __NR_memfd_create 360
71 #elif defined __sparc__
72 #define __NR_memfd_create 348
73 #elif defined __blackfin__
74 #define __NR_memfd_create 390
75 #elif defined __ia64__
76 #define __NR_memfd_create 1340
77 #elif defined _MIPS_SIM
78 #if _MIPS_SIM == _MIPS_SIM_ABI32
79 #define __NR_memfd_create 4354
81 #if _MIPS_SIM == _MIPS_SIM_NABI32
82 #define __NR_memfd_create 6318
84 #if _MIPS_SIM == _MIPS_SIM_ABI64
85 #define __NR_memfd_create 5314
89 #ifdef __NR_memfd_create
90 return syscall(__NR_memfd_create
, name
, flags
);
97 extern int memfd_create(const char *name
, unsigned int flags
);
101 static int pivot_root(const char *new_root
, const char *put_old
)
103 #ifdef __NR_pivot_root
104 return syscall(__NR_pivot_root
, new_root
, put_old
);
111 extern int pivot_root(const char *new_root
, const char *put_old
);
114 #if !defined(__NR_setns) && !defined(__NR_set_ns)
115 #if defined(__x86_64__)
116 #define __NR_setns 308
117 #elif defined(__i386__)
118 #define __NR_setns 346
119 #elif defined(__arm__)
120 #define __NR_setns 375
121 #elif defined(__aarch64__)
122 #define __NR_setns 375
123 #elif defined(__powerpc__)
124 #define __NR_setns 350
125 #elif defined(__s390__)
126 #define __NR_setns 339
130 /* Define sethostname() if missing from the C library */
131 #ifndef HAVE_SETHOSTNAME
132 static inline int sethostname(const char *name
, size_t len
)
134 #ifdef __NR_sethostname
135 return syscall(__NR_sethostname
, name
, len
);
143 /* Define setns() if missing from the C library */
145 static inline int setns(int fd
, int nstype
)
148 return syscall(__NR_setns
, fd
, nstype
);
149 #elif defined(__NR_set_ns)
150 return syscall(__NR_set_ns
, fd
, nstype
);
158 /* Define unshare() if missing from the C library */
160 static inline int unshare(int flags
)
163 return syscall(__NR_unshare
, flags
);
170 extern int unshare(int);
173 #endif /* __LXC_SYSCALL_WRAPPER_H */