]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
process_utils: add clone3() support
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 15 May 2020 11:42:56 +0000 (13:42 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 15 May 2020 11:42:56 +0000 (13:42 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
configure.ac
src/lxc/process_utils.h

index 7f589f9405e88d96d3f56346145631678720ff05..4e11254b5b44b6af112cc3b97275ab3d70d12ad6 100644 (file)
@@ -622,7 +622,11 @@ AC_CHECK_HEADER([ifaddrs.h],
 AC_HEADER_MAJOR
 
 # Check for some syscalls functions
-AC_CHECK_FUNCS([setns pivot_root sethostname unshare rand_r confstr faccessat gettid memfd_create move_mount open_tree execveat])
+AC_CHECK_FUNCS([setns pivot_root sethostname unshare rand_r confstr faccessat gettid memfd_create move_mount open_tree execveat clone3])
+# HAVE_STRUCT_CLONE_ARGS={0,1}
+AC_CHECK_TYPES([struct clone_args], [], [], [[#include <linux/sched.h>]])
+AC_CHECK_MEMBERS([struct clone_args.set_tid],[],[],[[#include <linux/sched.h>]])
+AC_CHECK_MEMBERS([struct clone_args.cgroup],[],[],[[#include <linux/sched.h>]])
 
 # Check for strerror_r() support. Defines:
 # - HAVE_STRERROR_R if available
@@ -761,7 +765,7 @@ AX_CHECK_COMPILE_FLAG([-Wstringop-overflow], [CFLAGS="$CFLAGS -Wstringop-overflo
 AX_CHECK_LINK_FLAG([-z relro], [LDFLAGS="$LDFLAGS -z relro"],,[])
 AX_CHECK_LINK_FLAG([-z now], [LDFLAGS="$LDFLAGS -z now"],,[])
 
-CFLAGS="$CFLAGS -Wvla -std=gnu11"
+CFLAGS="$CFLAGS -Wvla -std=gnu11 -fms-extensions"
 if test "x$enable_werror" = "xyes"; then
        CFLAGS="$CFLAGS -Werror"
 fi
index 6016f792ef5a025908e428b2686a8de713acdd12..8795247596880040f74be823eef9ec4aa2041d57 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE 1
 #endif
+#include <linux/sched.h>
 #include <sched.h>
 #include <signal.h>
 #include <stdbool.h>
@@ -14,6 +15,9 @@
 #include <sys/syscall.h>
 #include <unistd.h>
 
+#include "config.h"
+#include "syscall_numbers.h"
+
 #ifndef CSIGNAL
 #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
 #endif
 #define P_PIDFD 3
 #endif
 
+#ifndef CLONE_ARGS_SIZE_VER0
+#define CLONE_ARGS_SIZE_VER0 64 /* sizeof first published struct */
+#endif
+
+#ifndef CLONE_ARGS_SIZE_VER1
+#define CLONE_ARGS_SIZE_VER1 80 /* sizeof second published struct */
+#endif
+
+#ifndef CLONE_ARGS_SIZE_VER2
+#define CLONE_ARGS_SIZE_VER2 88 /* sizeof third published struct */
+#endif
+
+#ifndef HAVE_STRUCT_CLONE_ARGS
+struct clone_args {
+       __aligned_u64 flags;
+       __aligned_u64 pidfd;
+       __aligned_u64 child_tid;
+       __aligned_u64 parent_tid;
+       __aligned_u64 exit_signal;
+       __aligned_u64 stack;
+       __aligned_u64 stack_size;
+       __aligned_u64 tls;
+       __aligned_u64 set_tid;
+       __aligned_u64 set_tid_size;
+       __aligned_u64 cgroup;
+};
+#endif
+
+struct lxc_clone_args {
+       struct clone_args;
+#ifndef HAVE_STRUCT_CLONE_ARGS_SET_TID
+       __aligned_u64 set_tid;
+       __aligned_u64 set_tid_size;
+#endif
+#ifndef HAVE_STRUCT_CLONE_ARGS_CGROUP
+       __aligned_u64 cgroup;
+#endif
+};
+
+static inline pid_t lxc_clone3(struct lxc_clone_args *args, size_t size)
+{
+       return syscall(__NR_clone3, (struct clone_args *)args, size);
+}
 
 #if defined(__ia64__)
 int __clone2(int (*__fn)(void *__arg), void *__child_stack_base,