From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/5161 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [UGLY PATCH] Support for no-legacy-syscalls archs Date: Sun, 25 May 2014 07:45:15 -0400 Message-ID: <20140525114515.GX507@brightrain.aerifal.cx> References: <20140525054237.GA18085@brightrain.aerifal.cx> <20140525095257.GI12324@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 1401018335 22514 80.91.229.3 (25 May 2014 11:45:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 25 May 2014 11:45:35 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-5166-gllmg-musl=m.gmane.org@lists.openwall.com Sun May 25 13:45:29 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 1WoWro-0007BQ-Oy for gllmg-musl@plane.gmane.org; Sun, 25 May 2014 13:45:28 +0200 Original-Received: (qmail 19515 invoked by uid 550); 25 May 2014 11:45:27 -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 19507 invoked from network); 25 May 2014 11:45:27 -0000 Content-Disposition: inline In-Reply-To: <20140525095257.GI12324@port70.net> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:5161 Archived-At: On Sun, May 25, 2014 at 11:52:57AM +0200, Szabolcs Nagy wrote: > * Rich Felker [2014-05-25 01:42:37 -0400]: > > Here's a proposed next phase for supporting no-legacy-syscall archs > > (aarch64 and or1k, among others). It's not complete but I think it > > covers most of the important syscalls for standard functionality (not > > linux-specific stuff tho). Some of them might be missing some error > > cases or otherwise buggy so I'm sending the patch for review before > > committing. > .... > > +#ifdef SYS_poll > > __syscall(SYS_poll, pfd, 3, 0); > > +#else > > + __syscall(SYS_ppoll, pfd, 3, 0, 0, _NSIG/8); > > +#endif > > cant it be done the other way around so new syscalls > are tried and then the classic ones are just fallbacks? The "legacy" (I like the word "classic" better here, actually) syscalls are actually preferred when available. Not only is there the natural small amount of bloat decrease (fewer args, less chance of having to shuffle the stack and spill registers in the caller, etc.), and the consideration that using the new syscalls by default would require fallback code for the ENOSYS case, but in some cases emulating the behavior of the simpler function with the "general purpose" syscall is actually expensive and error-prone. I thought getpgid was an example of this (see the patch, which uses 4 syscalls instead of 1 to avoid a race reading the pid then using it, which can race with fork from a signal handler) but it turned out an argument of 0 to the syscall yields the getpgrp behavior, so I'm updating that aspect of the patch. An example that can't be optimized away is dup2, where special logic is needed to deal with the case that dup3 treats differently. BTW, the use of dup2 in posix_spawn also needs attention; I'm fixing it now but the fix is rather ugly. > and what will happen with SYS_open? Already committed what seems to be the least invasive at both the source and binary level. See the commit message; other approaches had me worried that it might be too easy to break things (e.g. posix_spawn where the child is sharing memory with the parent and thus can't touch errno, cancellation state, etc.). Rich