From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 21705 invoked from network); 18 Aug 2022 10:11:53 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 18 Aug 2022 10:11:53 -0000 Received: (qmail 21864 invoked by uid 550); 18 Aug 2022 10:11:49 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 21832 invoked from network); 18 Aug 2022 10:11:48 -0000 X-Virus-Scanned: SPAM Filter at disroot.org Mime-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1660817496; bh=LkXetFBv9wH8RGaJcLaPNdLa4si8ApAQa72WYi9QGMo=; h=Date:Subject:From:To:References:In-Reply-To; b=LzSdt89U1a6oTuv623BImAXJEnWGgIxAmZqs8+1HUDQZRAK9Y2Ga4qc6P+bbJ9z1t CJze3fyZY+sUnqWC7LTFv4yahdM4Zq0luSje7Xvjjh/MHoY2yvfFMg+A4ZnCpB1Ww9 9iZl+oOVfg7YrwPdGIXrFkI6JI2ay3x/nX8584JkFco1+QbTOCoE3K29xMu93FF13o eC1iUbzHG6x0+nPQT/nA8B61J6q2hnj523iiAFctCK1hamVxi8jStA2wucuW5VKAtQ Io8H5Y1nL+7F7aeLUfdqUutydWPF+RpcP4d/sIr6dSFQkmKhdaDXI6Z/qjg5CG1B3s jvBHSBk+0gC2A== Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 18 Aug 2022 07:11:31 -0300 Message-Id: From: =?utf-8?q?=C3=89rico_Nogueira?= To: , "Guilherme Janczak" References: <20220810130311.dwk7zxwkz32igrdm@yandex.com> <20220818003531.GG7074@brightrain.aerifal.cx> In-Reply-To: <20220818003531.GG7074@brightrain.aerifal.cx> Subject: Re: [musl] [PATCH] add close_range() syscall wrapper On Wed Aug 17, 2022 at 9:35 PM -03, Rich Felker wrote: > On Wed, Aug 10, 2022 at 01:03:11PM +0000, Guilherme Janczak wrote: > > close_range() is a syscall present in FreeBSD 8.0 and Linux 5.9. glibc > > 2.34 added a wrapper. > > --- > > The existence of this operation has been controversial, and it's > arguable that it should be excluded by policy not to support UB (it's > UB to close fds you don't own that might be used internally by the > implementation) though I'm not sure it really helps since folks who > want to use it will just make the syscall directly. We should probably > at least consider it for inclusion. I remember an idea to implement fallback logic, in case the syscall is unavailable, had been mentioned. It would then avoid whatever fallback code the application tried to implement, which might not be as relevant, now that opendir() can be called in a forked child. And I don't know if there's interest in implementing anything more complex at all. > > > > include/unistd.h | 3 +++ > > src/linux/close_range.c | 8 ++++++++ > > 2 files changed, 11 insertions(+) > > create mode 100644 src/linux/close_range.c > >=20 > > diff --git a/include/unistd.h b/include/unistd.h > > index 80be3b26..e4b8cbb1 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 0x01 > > +#define CLOSE_RANGE_CLOEXEC 0x02 > > +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..4c5cd68c > > --- /dev/null > > +++ b/src/linux/close_range.c > > @@ -0,0 +1,8 @@ > > +#define _GNU_SOURCE > > This should probably be _BSD_SOURCE if it's exposed under _BSD_SOURCE. > > > +#include > > +#include "syscall.h" > > + > > +int close_range(unsigned int first, unsigned int last, int flags) > > +{ > > + return syscall(SYS_close_range, first, last, (unsigned int)flags); > > +} > > --=20 > > 2.35.1 > > Can you elaborate on what the cast to unsigned is for? > > Rich