|
|
Message-ID: <1a031bfa79a.708b2f30505443.2262318146289684019@soss.website>
Date: Sun, 23 Aug 2026 22:10:39 -0500
From: Skye Soss <skye@...s.website>
To: "musl" <musl@...ts.openwall.com>
Subject: [PATCH] add linux-specific close_range syscall wrapper
This patch adds the close_range syscall wrapper.
The syscall was added in Linux 5.9.
There was prior discussion more than 4 years ago on this addition. This patch
is slightly modified to put the CLOSE_RANGE_UNSHARE macro definition inside
the _GNU_SOURCE section, as FreeBSD defines *_CLOEXEC but not *_UNSHARE.
The Linux syscall accepts the flags parameter as unsigned, but glibc's wrapper
uses a signed integer. The cast makes that reinterpretation explicit, but is
not strictly necessary.
This operation is important to support for popular software such as Python 3,
as fallback mechanisms are much slower (https://bugs.python.org/issue38061).
Because function availability is often checked via HAVE_ macros, this needs
to be exposed as a wrapper function; forcing users to use syscall() is not
good enough for configure-time detection (as done by GLib).
---
include/unistd.h | 3 +++
src/linux/close_range.c | 8 ++++++++
2 files changed, 11 insertions(+)
create mode 100644 src/linux/close_range.c
diff --git a/include/unistd.h b/include/unistd.h
index 42b0e82b..01138594 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -160,6 +160,7 @@ unsigned ualarm(unsigned, unsigned);
#define L_SET 0
#define L_INCR 1
#define L_XTND 2
+#define CLOSE_RANGE_CLOEXEC 0x02
int brk(void *);
void *sbrk(intptr_t);
pid_t vfork(void);
@@ -182,9 +183,11 @@ int execvpe(const char *, char *const [], char *const []);
int issetugid(void);
int getentropy(void *, size_t);
extern int optreset;
+int close_range(unsigned, unsigned, int);
#endif
#ifdef _GNU_SOURCE
+#define CLOSE_RANGE_UNSHARE 0x01
extern char **environ;
int setresuid(uid_t, uid_t, uid_t);
int setresgid(gid_t, gid_t, gid_t);
diff --git a/src/linux/close_range.c b/src/linux/close_range.c
new file mode 100644
index 00000000..ab44411a
--- /dev/null
+++ b/src/linux/close_range.c
@@ -0,0 +1,8 @@
+#define _GNU_SOURCE
+#include <unistd.h>
+#include "syscall.h"
+
+int close_range(unsigned first, unsigned last, int flags)
+{
+ return syscall(SYS_close_range, first, last, (unsigned)flags);
+}
--
2.55.0
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.