]> git.proxmox.com Git - mirror_lxc.git/commitdiff
syscall_wrappers: move memfd_create()
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 3 Oct 2018 10:49:46 +0000 (12:49 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 3 Oct 2018 10:49:46 +0000 (12:49 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/ringbuf.c
src/lxc/syscall_wrappers.h
src/lxc/utils.h

index 1d5cfe9161e6be512a11414899796d80e85cbe26..97f68539f4ea264cd96b052546ad9d7d339e0d0e 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "config.h"
 #include "ringbuf.h"
+#include "syscall_wrappers.h"
 #include "utils.h"
 
 int lxc_ringbuf_create(struct lxc_ringbuf *buf, size_t size)
index a6c7694d908db29a25c05a1fd322b13a4026f8a5..da376d58903092e391b0ee9a1904ba9cc4999912 100644 (file)
 
 #include "config.h"
 
+#ifdef HAVE_LINUX_MEMFD_H
+#include <linux/memfd.h>
+#endif
+
 typedef int32_t key_serial_t;
 
 #if !HAVE_KEYCTL
@@ -48,6 +52,50 @@ static inline long __keyctl(int cmd, unsigned long arg2, unsigned long arg3,
 #define keyctl __keyctl
 #endif
 
+#ifndef HAVE_MEMFD_CREATE
+static inline int memfd_create(const char *name, unsigned int flags) {
+       #ifndef __NR_memfd_create
+               #if defined __i386__
+                       #define __NR_memfd_create 356
+               #elif defined __x86_64__
+                       #define __NR_memfd_create 319
+               #elif defined __arm__
+                       #define __NR_memfd_create 385
+               #elif defined __aarch64__
+                       #define __NR_memfd_create 279
+               #elif defined __s390__
+                       #define __NR_memfd_create 350
+               #elif defined __powerpc__
+                       #define __NR_memfd_create 360
+               #elif defined __sparc__
+                       #define __NR_memfd_create 348
+               #elif defined __blackfin__
+                       #define __NR_memfd_create 390
+               #elif defined __ia64__
+                       #define __NR_memfd_create 1340
+               #elif defined _MIPS_SIM
+                       #if _MIPS_SIM == _MIPS_SIM_ABI32
+                               #define __NR_memfd_create 4354
+                       #endif
+                       #if _MIPS_SIM == _MIPS_SIM_NABI32
+                               #define __NR_memfd_create 6318
+                       #endif
+                       #if _MIPS_SIM == _MIPS_SIM_ABI64
+                               #define __NR_memfd_create 5314
+                       #endif
+               #endif
+       #endif
+       #ifdef __NR_memfd_create
+       return syscall(__NR_memfd_create, name, flags);
+       #else
+       errno = ENOSYS;
+       return -1;
+       #endif
+}
+#else
+extern int memfd_create(const char *name, unsigned int flags);
+#endif
+
 #if !HAVE_PIVOT_ROOT
 static int pivot_root(const char *new_root, const char *put_old)
 {
index 7bb361cfbeaec9f07b35fc3969b14b3164f4a40c..8c5914de7221441b846b5d04a553c4e732015388 100644 (file)
 #include "raw_syscalls.h"
 #include "string_utils.h"
 
-#ifdef HAVE_LINUX_MEMFD_H
-#include <linux/memfd.h>
-#endif
-
 /* returns 1 on success, 0 if there were any failures */
 extern int lxc_rmdir_onedev(const char *path, const char *exclude);
 extern int get_u16(unsigned short *val, const char *arg, int base);
@@ -199,50 +195,6 @@ static inline int signalfd(int fd, const sigset_t *mask, int flags)
 }
 #endif
 
-#ifndef HAVE_MEMFD_CREATE
-static inline int memfd_create(const char *name, unsigned int flags) {
-       #ifndef __NR_memfd_create
-               #if defined __i386__
-                       #define __NR_memfd_create 356
-               #elif defined __x86_64__
-                       #define __NR_memfd_create 319
-               #elif defined __arm__
-                       #define __NR_memfd_create 385
-               #elif defined __aarch64__
-                       #define __NR_memfd_create 279
-               #elif defined __s390__
-                       #define __NR_memfd_create 350
-               #elif defined __powerpc__
-                       #define __NR_memfd_create 360
-               #elif defined __sparc__
-                       #define __NR_memfd_create 348
-               #elif defined __blackfin__
-                       #define __NR_memfd_create 390
-               #elif defined __ia64__
-                       #define __NR_memfd_create 1340
-               #elif defined _MIPS_SIM
-                       #if _MIPS_SIM == _MIPS_SIM_ABI32
-                               #define __NR_memfd_create 4354
-                       #endif
-                       #if _MIPS_SIM == _MIPS_SIM_NABI32
-                               #define __NR_memfd_create 6318
-                       #endif
-                       #if _MIPS_SIM == _MIPS_SIM_ABI64
-                               #define __NR_memfd_create 5314
-                       #endif
-               #endif
-       #endif
-       #ifdef __NR_memfd_create
-       return syscall(__NR_memfd_create, name, flags);
-       #else
-       errno = ENOSYS;
-       return -1;
-       #endif
-}
-#else
-extern int memfd_create(const char *name, unsigned int flags);
-#endif
-
 static inline int lxc_set_cloexec(int fd)
 {
        return fcntl(fd, F_SETFD, FD_CLOEXEC);