From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7927 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Moving forward with sh2/nommu Date: Fri, 12 Jun 2015 02:37:44 -0400 Message-ID: <20150612063744.GE17573@brightrain.aerifal.cx> References: <20150601151107.GA20759@brightrain.aerifal.cx> <20150610033050.GS17573@brightrain.aerifal.cx> <5579085B.5090407@landley.net> <20150611151252.GW17573@brightrain.aerifal.cx> <20150611172227.GY17573@brightrain.aerifal.cx> <87mw055z74.wl-ysato@users.sourceforge.jp> <20150612043555.GD17573@brightrain.aerifal.cx> <4817AF88-3C84-4EE1-A043-99D498B59A87@uClinux.org> 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 1434091091 26234 80.91.229.3 (12 Jun 2015 06:38:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 12 Jun 2015 06:38:11 +0000 (UTC) Cc: Yoshinori Sato , "musl@lists.openwall.com" , "shumpei.kawasaki@swhwc.com" To: "uClinux.org" Original-X-From: musl-return-7941-gllmg-musl=m.gmane.org@lists.openwall.com Fri Jun 12 08:38:08 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Z3IbQ-0002uf-3k for gllmg-musl@m.gmane.org; Fri, 12 Jun 2015 08:38:08 +0200 Original-Received: (qmail 26070 invoked by uid 550); 12 Jun 2015 06:38:05 -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 25998 invoked from network); 12 Jun 2015 06:38:04 -0000 Content-Disposition: inline In-Reply-To: <4817AF88-3C84-4EE1-A043-99D498B59A87@uClinux.org> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:7927 Archived-At: On Fri, Jun 12, 2015 at 01:49:28PM +0900, uClinux.org wrote: > Rich, > > This isn't necessary. The child in a nommu system -must never- > return from the function that called vfork. The reason is there is > only one stack, and so that stack must not be corrupted (not the > pointer, the actual call frame) or as you mention the parent cannot > continue execution. > > This is not a nommu uClinux thing, it is a restriction we inherited > from BSD vfork(). It makes things much simpler (read: tractable at > all), actually. I'm not talking about returning from the function that called vfork. This is about returning from vfork itself, to the caller of vfork. Rich > > On Jun 12, 2015, at 13:35, Rich Felker wrote: > > > >> On Fri, Jun 12, 2015 at 01:26:55PM +0900, Yoshinori Sato wrote: > >> On Fri, 12 Jun 2015 02:22:27 +0900, > >> Rich Felker wrote: > >>> > >>> On Thu, Jun 11, 2015 at 11:12:52AM -0400, Rich Felker wrote: > >>>>>>> 3. We need sh/vfork.s since the default vfork.c just uses fork, which > >>>>>>> won't work. I have a version locally but it doesn't make sense to > >>>>>>> commit without runtime trap number selection. > >>>>>> > >>>>>> Done and updated to use runtime selection in the (ugly) patch. > >>>>> > >>>>> If they ask for vfork() they should get vfork()...? > >>>> > >>>> Yes. The "runtime selection" is about the syscall trap number, not > >>>> whether or not to use vfork. I committed vfork to upstream musl now, > >>>> but with a SH3/4 trap number to be consistent with the code that's > >>>> upstream now. Later I'll either convert them all to trap 31 (0x1f) if > >>>> that ends up being acceptable, or merge the runtime-selection code, > >>>> but I think it makes sense to make the change across all files at > >>>> once, whichever way it's done. > >>> > >>> Ah, maybe I misunderstood. If you were asking abaout the original > >>> remark that the default vfork.c uses fork, the reason is simply that > >>> you can't write vfork() in C. The return from vfork() in the child > >>> will clobber vfork's stack frame, which may contain the return address > >>> or saved registers, and then when the parent resumes, very bad things > >>> will happen. vfork() has to be implemented in asm to ensure that any > >>> state it needs to be able to return in the parent is kept in registers > >>> rather than memory. Thus, each arch needs an arch-specific version, > >>> and we just hadn't gotten around to adding the sh version yet. > >> > >> No. vfork kept only last return address. > >> It isn't necessary to preserve the value of anything but that. > >> Child process can't return caller routine. > > > > vfork still has to follow the normal function call ABI of preserving > > call-saved registers. For example, if you (or the compiler) wrote > > vfork by spilling some or all of the call-saved registers to the > > stack, clobbering them (e.g. for stack-protector work, or profiling > > counters, or PIC-related purposes, or for no reason at all), and then > > restoring them at return time, you'd be in trouble. The first return > > (in the child) would properly restore these registers, but subsequent > > execution in the child (in the function that called vfork, e.g. when > > it sets up the stack for a call to execl) could clobber the locations > > where they were saved on the stack, and when the parent resumed > > execution, it vfork would restore the wrong values, and very bad > > things could happen in the caller (e.g. the GOT register used for > > loading string literal args to exec*() might be wrong). > > > > Rich