From: Christian Brauner Date: Fri, 15 May 2020 11:42:56 +0000 (+0200) Subject: process_utils: add clone3() support X-Git-Tag: lxc-5.0.0~433^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96086a6b7b4f62c4f397de146b11456efa5327f7;p=thirdparty%2Flxc.git process_utils: add clone3() support Signed-off-by: Christian Brauner --- diff --git a/configure.ac b/configure.ac index 7f589f940..4e11254b5 100644 --- a/configure.ac +++ b/configure.ac @@ -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 ]]) +AC_CHECK_MEMBERS([struct clone_args.set_tid],[],[],[[#include ]]) +AC_CHECK_MEMBERS([struct clone_args.cgroup],[],[],[[#include ]]) # 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 diff --git a/src/lxc/process_utils.h b/src/lxc/process_utils.h index 6016f792e..879524759 100644 --- a/src/lxc/process_utils.h +++ b/src/lxc/process_utils.h @@ -6,6 +6,7 @@ #ifndef _GNU_SOURCE #define _GNU_SOURCE 1 #endif +#include #include #include #include @@ -14,6 +15,9 @@ #include #include +#include "config.h" +#include "syscall_numbers.h" + #ifndef CSIGNAL #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */ #endif @@ -136,6 +140,49 @@ #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,