Skip to content

Commit 202b294

Browse files
committed
Merge branch 'wip/smcv/closefrom' into 'master'
Fixes for g_closefrom() backport See merge request GNOME/libglnx!54
2 parents c2c6c95 + e4beedc commit 202b294

5 files changed

Lines changed: 98 additions & 4 deletions

File tree

glnx-backports.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "libglnx-config.h"
3737

3838
#include "glnx-backports.h"
39+
#include "glnx-missing.h"
3940

4041
#include <dirent.h>
4142
#include <errno.h>

glnx-missing-syscall.h

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*/
3333

3434
#include "libglnx-config.h"
35+
#include <glib.h>
3536

3637
#if !HAVE_DECL_RENAMEAT2
3738
# ifndef __NR_renameat2
@@ -155,3 +156,83 @@ static inline ssize_t missing_copy_file_range(int fd_in, loff_t *off_in,
155156

156157
# define copy_file_range missing_copy_file_range
157158
#endif
159+
160+
#ifndef __IGNORE_close_range
161+
# if defined(__aarch64__)
162+
# define systemd_NR_close_range 436
163+
# elif defined(__alpha__)
164+
# define systemd_NR_close_range 546
165+
# elif defined(__arc__) || defined(__tilegx__)
166+
# define systemd_NR_close_range 436
167+
# elif defined(__arm__)
168+
# define systemd_NR_close_range 436
169+
# elif defined(__i386__)
170+
# define systemd_NR_close_range 436
171+
# elif defined(__ia64__)
172+
# define systemd_NR_close_range 1460
173+
# elif defined(__loongarch_lp64)
174+
# define systemd_NR_close_range 436
175+
# elif defined(__m68k__)
176+
# define systemd_NR_close_range 436
177+
# elif defined(_MIPS_SIM)
178+
# if _MIPS_SIM == _MIPS_SIM_ABI32
179+
# define systemd_NR_close_range 4436
180+
# elif _MIPS_SIM == _MIPS_SIM_NABI32
181+
# define systemd_NR_close_range 6436
182+
# elif _MIPS_SIM == _MIPS_SIM_ABI64
183+
# define systemd_NR_close_range 5436
184+
# else
185+
# error "Unknown MIPS ABI"
186+
# endif
187+
# elif defined(__hppa__)
188+
# define systemd_NR_close_range 436
189+
# elif defined(__powerpc__)
190+
# define systemd_NR_close_range 436
191+
# elif defined(__riscv)
192+
# if __riscv_xlen == 32
193+
# define systemd_NR_close_range 436
194+
# elif __riscv_xlen == 64
195+
# define systemd_NR_close_range 436
196+
# else
197+
# error "Unknown RISC-V ABI"
198+
# endif
199+
# elif defined(__s390__)
200+
# define systemd_NR_close_range 436
201+
# elif defined(__sparc__)
202+
# define systemd_NR_close_range 436
203+
# elif defined(__x86_64__)
204+
# if defined(__ILP32__)
205+
# define systemd_NR_close_range (436 | /* __X32_SYSCALL_BIT */ 0x40000000)
206+
# else
207+
# define systemd_NR_close_range 436
208+
# endif
209+
# elif !defined(missing_arch_template)
210+
# warning "close_range() syscall number is unknown for your architecture"
211+
# endif
212+
213+
/* may be an (invalid) negative number due to libseccomp, see PR 13319 */
214+
# if defined __NR_close_range && __NR_close_range >= 0
215+
# if defined systemd_NR_close_range
216+
G_STATIC_ASSERT(__NR_close_range == systemd_NR_close_range);
217+
# endif
218+
# else
219+
# if defined __NR_close_range
220+
# undef __NR_close_range
221+
# endif
222+
# if defined systemd_NR_close_range && systemd_NR_close_range >= 0
223+
# define __NR_close_range systemd_NR_close_range
224+
# endif
225+
# endif
226+
#endif
227+
228+
#if !defined(HAVE_CLOSE_RANGE) && defined(__NR_close_range)
229+
static inline int
230+
inline_close_range (unsigned int low,
231+
unsigned int high,
232+
int flags)
233+
{
234+
return syscall (__NR_close_range, low, high, flags);
235+
}
236+
#define close_range(low, high, flags) inline_close_range(low, high, flags)
237+
#define HAVE_CLOSE_RANGE
238+
#endif

glnx-missing.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,12 @@
9292
#define MFD_CLOEXEC 0x0001U
9393
#endif
9494

95+
#ifndef CLOSE_RANGE_UNSHARE
96+
#define CLOSE_RANGE_UNSHARE (1U << 1)
97+
#endif
98+
99+
#ifndef CLOSE_RANGE_CLOEXEC
100+
#define CLOSE_RANGE_CLOEXEC (1U << 2)
101+
#endif
102+
95103
#include "glnx-missing-syscall.h"

libglnx.m4

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
AC_DEFUN([LIBGLNX_CONFIGURE],
66
[
7+
dnl This defines HAVE_DECL_FOO to 1 if found or 0 if not
78
AC_CHECK_DECLS([
89
renameat2,
910
memfd_create,
@@ -19,6 +20,9 @@ AC_CHECK_DECLS([
1920
#include <linux/random.h>
2021
#include <sys/mman.h>
2122
]])
23+
dnl This defines HAVE_FOO to 1 if found, or leaves it undefined if not:
24+
dnl not the same!
25+
AC_CHECK_FUNCS([close_range])
2226
2327
AC_ARG_ENABLE(otmpfile,
2428
[AS_HELP_STRING([--disable-otmpfile],

meson.build

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ foreach check_function : check_functions
4949
)
5050
conf.set10('HAVE_DECL_' + check_function.underscorify().to_upper(), have_it)
5151
endforeach
52-
config_h = configure_file(
53-
output : 'libglnx-config.h',
54-
configuration : conf,
55-
)
5652

5753
check_functions = [
5854
'close_range',
5955
]
6056
foreach check_function : check_functions
57+
if cc.has_function(check_function)
58+
conf.set('HAVE_' + check_function.underscorify().to_upper(), 1)
59+
endif
6160
endforeach
61+
6262
config_h = configure_file(
6363
output : 'libglnx-config.h',
6464
configuration : conf,

0 commit comments

Comments
 (0)