From: Alexey Izbyshev <izbyshev@ispras.ru>
To: musl@lists.openwall.com
Cc: Natanael Copa <ncopa@alpinelinux.org>
Subject: Re: [musl] [PATCH v2] add close_range() syscall wrapper
Date: Thu, 01 Aug 2024 12:43:00 +0300 [thread overview]
Message-ID: <6e084b55f3f0fc02b1a8e1b3997e5d81@ispras.ru> (raw)
In-Reply-To: <20230901145913.28307-1-ncopa@alpinelinux.org>
On 2023-09-01 17:58, Natanael Copa wrote:
> close_range() is a syscall present in FreeBSD 8.0 and Linux 5.9. glibc
> 2.34 added a wrapper.
>
> Expose it under _GNU_SOURCE similar to what GNU libc does. Also expose
> it under _BSD_SOURCE since it is also a FreeBSD function.
> ---
>
> v2: use syscall without __syscall_ret
>
> 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 5bc7f798..d89e3d4c 100644
> --- a/include/unistd.h
> +++ b/include/unistd.h
> @@ -161,6 +161,9 @@ unsigned ualarm(unsigned, unsigned);
> #define L_INCR 1
> #define L_XTND 2
> int brk(void *);
> +#define CLOSE_RANGE_UNSHARE (1U << 1)
> +#define CLOSE_RANGE_CLOEXEC (1U << 2)
> +int close_range(unsigned int, unsigned int, int);
> void *sbrk(intptr_t);
> pid_t vfork(void);
> int vhangup(void);
> diff --git a/src/linux/close_range.c b/src/linux/close_range.c
> new file mode 100644
> index 00000000..3f1378a0
> --- /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 int first, unsigned int last, int flags)
> +{
> + return syscall(SYS_close_range, first, last, flags);
> +}
Regarding FreeBSD, close_range was added not in 8.0, but in 13.0 [1],
and also backported to 12.2 [2].
Otherwise, this patch looks good to me.
Rich, is it possible to consider close_range wrapper inclusion again?
Apart from FreeBSD and glibc, bionic has it too. A cursory Debian code
search shows that close_range libc wrapper can be used at least by
openssh, libvirt, network-manager, openrc, qemu, lxc, rsyslog packages
(in addition to CPython that I mentioned ealier).
As for having a fallback in case the syscall is unavailable, I'm not
aware of anybody implementing it, so I'd expect all close_range users to
implement their own fallback/error handling. For example, Debian's
openssh migrated from closefrom to close_range with their own fallback
because of too aggressive closefrom fallback in glibc[3].
Thanks,
Alexey
[1]
https://cgit.freebsd.org/src/commit/?h=releng/13.0&id=472ced39efb537374068f06b348fe5dac389c45a
[2]
https://cgit.freebsd.org/src/commit/?h=releng/12.2&id=a80adba5ab46ba6d44d5abfc9b7f3b6de8afda55
[3]
https://sources.debian.org/src/openssh/1%3A9.8p1-1/debian/changelog/#L895
next prev parent reply other threads:[~2024-08-01 9:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-01 8:02 [musl] [PATCH] " Natanael Copa
2023-09-01 13:57 ` Rich Felker
2023-09-01 14:55 ` Natanael Copa
2023-09-01 15:06 ` Rich Felker
2023-09-01 14:58 ` [musl] [PATCH v2] " Natanael Copa
2024-08-01 9:43 ` Alexey Izbyshev [this message]
2024-08-01 16:25 ` Rich Felker
2024-08-01 20:24 ` Alexey Izbyshev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6e084b55f3f0fc02b1a8e1b3997e5d81@ispras.ru \
--to=izbyshev@ispras.ru \
--cc=musl@lists.openwall.com \
--cc=ncopa@alpinelinux.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).