From: Christian Brauner Date: Wed, 3 Feb 2021 08:45:30 +0000 (+0100) Subject: syscalls: add close_range() X-Git-Tag: lxc-5.0.0~303^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8aaef81592f4399b2cd6431476abe264d967394;p=thirdparty%2Flxc.git syscalls: add close_range() Signed-off-by: Christian Brauner --- diff --git a/configure.ac b/configure.ac index 4f31d94ac..60d7a91e6 100644 --- a/configure.ac +++ b/configure.ac @@ -644,7 +644,7 @@ 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 clone3 fsopen fspick fsconfig fsmount, openat2]) +AC_CHECK_FUNCS([setns pivot_root sethostname unshare rand_r confstr faccessat gettid memfd_create move_mount open_tree execveat clone3 fsopen fspick fsconfig fsmount, openat2, close_range]) AC_CHECK_TYPES([struct open_how], [], [], [[#include ]]) AC_CHECK_TYPES([struct clone_args], [], [], [[#include ]]) AC_CHECK_MEMBERS([struct clone_args.set_tid],[],[],[[#include ]]) diff --git a/src/lxc/syscall_numbers.h b/src/lxc/syscall_numbers.h index 8305173d6..0bc5efe3d 100644 --- a/src/lxc/syscall_numbers.h +++ b/src/lxc/syscall_numbers.h @@ -660,4 +660,24 @@ #endif #endif +#ifndef __NR_close_range + #if defined __alpha__ + #define __NR_close_range 546 + #elif defined _MIPS_SIM + #if _MIPS_SIM == _MIPS_SIM_ABI32 /* o32 */ + #define __NR_close_range (436 + 4000) + #endif + #if _MIPS_SIM == _MIPS_SIM_NABI32 /* n32 */ + #define __NR_close_range (436 + 6000) + #endif + #if _MIPS_SIM == _MIPS_SIM_ABI64 /* n64 */ + #define __NR_close_range (436 + 5000) + #endif + #elif defined __ia64__ + #define __NR_close_range (436 + 1024) + #else + #define __NR_close_range 436 + #endif +#endif + #endif /* __LXC_SYSCALL_NUMBERS_H */ diff --git a/src/lxc/syscall_wrappers.h b/src/lxc/syscall_wrappers.h index de931a351..757f370f8 100644 --- a/src/lxc/syscall_wrappers.h +++ b/src/lxc/syscall_wrappers.h @@ -282,4 +282,19 @@ static inline int openat2(int dfd, const char *filename, struct lxc_open_how *ho } #endif /* HAVE_OPENAT2 */ +#ifndef CLOSE_RANGE_UNSHARE +#define CLOSE_RANGE_UNSHARE (1U << 1) +#endif + +#ifndef CLOSE_RANGE_CLOEXEC +#define CLOSE_RANGE_CLOEXEC (1U << 2) +#endif + +#ifndef HAVE_CLOSE_RANGE +static inline int close_range(unsigned int fd, unsigned int max_fd, unsigned int flags) +{ + return syscall(__NR_close_range, fd, max_fd, flags); +} +#endif + #endif /* __LXC_SYSCALL_WRAPPER_H */