Skip to content

Commit

Permalink
Merge branch 'wip/smcv/closefrom' into 'master'
Browse files Browse the repository at this point in the history
Fixes for g_closefrom() backport

See merge request GNOME/libglnx!54
  • Loading branch information
cgwalters committed Feb 9, 2024
2 parents c2c6c95 + e4beedc commit 202b294
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 4 deletions.
1 change: 1 addition & 0 deletions glnx-backports.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "libglnx-config.h"

#include "glnx-backports.h"
#include "glnx-missing.h"

#include <dirent.h>
#include <errno.h>
Expand Down
81 changes: 81 additions & 0 deletions glnx-missing-syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/

#include "libglnx-config.h"
#include <glib.h>

#if !HAVE_DECL_RENAMEAT2
# ifndef __NR_renameat2
Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions glnx-missing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 4 additions & 0 deletions libglnx.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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],
Expand Down
8 changes: 4 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 202b294

Please sign in to comment.