Skip to content
Snippets Groups Projects
Commit 202b294e authored by Colin Walters's avatar Colin Walters
Browse files

Merge branch 'wip/smcv/closefrom' into 'master'

Fixes for g_closefrom() backport

See merge request GNOME/libglnx!54
parents c2c6c950 e4beedc0
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,7 @@
#include "libglnx-config.h"
#include "glnx-backports.h"
#include "glnx-missing.h"
#include <dirent.h>
#include <errno.h>
......
......@@ -32,6 +32,7 @@
*/
#include "libglnx-config.h"
#include <glib.h>
#if !HAVE_DECL_RENAMEAT2
# ifndef __NR_renameat2
......@@ -155,3 +156,83 @@ static inline ssize_t missing_copy_file_range(int fd_in, loff_t *off_in,
# define copy_file_range missing_copy_file_range
#endif
#ifndef __IGNORE_close_range
# if defined(__aarch64__)
# define systemd_NR_close_range 436
# elif defined(__alpha__)
# define systemd_NR_close_range 546
# elif defined(__arc__) || defined(__tilegx__)
# define systemd_NR_close_range 436
# elif defined(__arm__)
# define systemd_NR_close_range 436
# elif defined(__i386__)
# define systemd_NR_close_range 436
# elif defined(__ia64__)
# define systemd_NR_close_range 1460
# elif defined(__loongarch_lp64)
# define systemd_NR_close_range 436
# elif defined(__m68k__)
# define systemd_NR_close_range 436
# elif defined(_MIPS_SIM)
# if _MIPS_SIM == _MIPS_SIM_ABI32
# define systemd_NR_close_range 4436
# elif _MIPS_SIM == _MIPS_SIM_NABI32
# define systemd_NR_close_range 6436
# elif _MIPS_SIM == _MIPS_SIM_ABI64
# define systemd_NR_close_range 5436
# else
# error "Unknown MIPS ABI"
# endif
# elif defined(__hppa__)
# define systemd_NR_close_range 436
# elif defined(__powerpc__)
# define systemd_NR_close_range 436
# elif defined(__riscv)
# if __riscv_xlen == 32
# define systemd_NR_close_range 436
# elif __riscv_xlen == 64
# define systemd_NR_close_range 436
# else
# error "Unknown RISC-V ABI"
# endif
# elif defined(__s390__)
# define systemd_NR_close_range 436
# elif defined(__sparc__)
# define systemd_NR_close_range 436
# elif defined(__x86_64__)
# if defined(__ILP32__)
# define systemd_NR_close_range (436 | /* __X32_SYSCALL_BIT */ 0x40000000)
# else
# define systemd_NR_close_range 436
# endif
# elif !defined(missing_arch_template)
# warning "close_range() syscall number is unknown for your architecture"
# endif
/* may be an (invalid) negative number due to libseccomp, see PR 13319 */
# if defined __NR_close_range && __NR_close_range >= 0
# if defined systemd_NR_close_range
G_STATIC_ASSERT(__NR_close_range == systemd_NR_close_range);
# endif
# else
# if defined __NR_close_range
# undef __NR_close_range
# endif
# if defined systemd_NR_close_range && systemd_NR_close_range >= 0
# define __NR_close_range systemd_NR_close_range
# endif
# endif
#endif
#if !defined(HAVE_CLOSE_RANGE) && defined(__NR_close_range)
static inline int
inline_close_range (unsigned int low,
unsigned int high,
int flags)
{
return syscall (__NR_close_range, low, high, flags);
}
#define close_range(low, high, flags) inline_close_range(low, high, flags)
#define HAVE_CLOSE_RANGE
#endif
......@@ -92,4 +92,12 @@
#define MFD_CLOEXEC 0x0001U
#endif
#ifndef CLOSE_RANGE_UNSHARE
#define CLOSE_RANGE_UNSHARE (1U << 1)
#endif
#ifndef CLOSE_RANGE_CLOEXEC
#define CLOSE_RANGE_CLOEXEC (1U << 2)
#endif
#include "glnx-missing-syscall.h"
......@@ -4,6 +4,7 @@
AC_DEFUN([LIBGLNX_CONFIGURE],
[
dnl This defines HAVE_DECL_FOO to 1 if found or 0 if not
AC_CHECK_DECLS([
renameat2,
memfd_create,
......@@ -19,6 +20,9 @@ AC_CHECK_DECLS([
#include <linux/random.h>
#include <sys/mman.h>
]])
dnl This defines HAVE_FOO to 1 if found, or leaves it undefined if not:
dnl not the same!
AC_CHECK_FUNCS([close_range])
AC_ARG_ENABLE(otmpfile,
[AS_HELP_STRING([--disable-otmpfile],
......
......@@ -49,16 +49,16 @@ foreach check_function : check_functions
)
conf.set10('HAVE_DECL_' + check_function.underscorify().to_upper(), have_it)
endforeach
config_h = configure_file(
output : 'libglnx-config.h',
configuration : conf,
)
check_functions = [
'close_range',
]
foreach check_function : check_functions
if cc.has_function(check_function)
conf.set('HAVE_' + check_function.underscorify().to_upper(), 1)
endif
endforeach
config_h = configure_file(
output : 'libglnx-config.h',
configuration : conf,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment