From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/5174 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [UGLY PATCH v3] Support for no-legacy-syscalls archs Date: Tue, 27 May 2014 15:01:34 -0400 Message-ID: <20140527190134.GD507@brightrain.aerifal.cx> References: <20140525054237.GA18085@brightrain.aerifal.cx> <20140527052625.GC507@brightrain.aerifal.cx> <20140527112954.GL12324@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1401217317 1792 80.91.229.3 (27 May 2014 19:01:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 27 May 2014 19:01:57 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-5179-gllmg-musl=m.gmane.org@lists.openwall.com Tue May 27 21:01:51 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1WpMdB-0004VT-2d for gllmg-musl@plane.gmane.org; Tue, 27 May 2014 21:01:49 +0200 Original-Received: (qmail 30082 invoked by uid 550); 27 May 2014 19:01:48 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 30074 invoked from network); 27 May 2014 19:01:47 -0000 Content-Disposition: inline In-Reply-To: <20140527112954.GL12324@port70.net> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:5174 Archived-At: On Tue, May 27, 2014 at 01:29:54PM +0200, Szabolcs Nagy wrote: > * Rich Felker [2014-05-27 01:26:25 -0400]: > > In the case of epoll, etc. I reworked the code to always prefer the > > new syscalls and only fallback to the old ones if (1) they exist, and > > (2) the new one returned ENOSYS. signalfd already has fallback code > > that handles FD_CLOEXEC as best it can when the new syscall is not > > available, but the others seem to be lacking the proper fallback code > > so I should perhaps add that too. > > SOCK_CLOEXEC and SOCK_NONBLOCK fallbacks for socketpair are missing too I thought I'd already added them, but you're right. Perhaps if we're emulating the fallback cases we should go ahead and make it race-free. This can be done by a combination of locking and signal masking that prevents fork, posix_spawn, and exec* during the interval where the close-on-exec flag is not yet set on the new fd. It would basically look like: __block_app_sigs(&set); __lock(cloexec_lock); [do fallback work here] __restore_sigs(&set); This would not work if the fallback work were supposed to be interruptible by signals; I'm not sure if any such cases would need to be considered. Our fork and posix_spawn implementations already run with all signals blocked, so all that would need to be added to them is the locking. Adding the code to exec* would incur some additional cost, and I'm actually not sure how to do it right without the new program inheriting the all-blocked signal mask. > > +#ifdef SYS_pausex > > + __syscall(SYS_pause); > > +#else > > + __syscall(SYS_futex, &lock, FUTEX_WAIT, 1, 0); > > +#endif > > pausex typo Actually it was my cheap test of the fallback case that I forgot to remove. :) Fixed. BTW do you have any better ideas for a fallback here? Maybe some sleep variant? I just want something that will avoid spinning and consuming cpu while we wait for exit to finish. Rich