mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: musl@lists.openwall.com, "D. Jeff Dionne" <Jeff@uClinux.org>,
	shumpei.kawasaki@swhwc.com
Subject: Re: Moving forward with sh2/nommu
Date: Fri, 12 Jun 2015 00:35:55 -0400	[thread overview]
Message-ID: <20150612043555.GD17573@brightrain.aerifal.cx> (raw)
In-Reply-To: <87mw055z74.wl-ysato@users.sourceforge.jp>

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


  reply	other threads:[~2015-06-12  4:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-01 15:11 Rich Felker
2015-06-02  6:09 ` Rob Landley
2015-06-02 16:45   ` Rich Felker
2015-06-02 23:49     ` Rich Felker
2015-06-10  3:30 ` Rich Felker
2015-06-11  4:02   ` Rob Landley
2015-06-11 15:12     ` Rich Felker
2015-06-11 17:22       ` Rich Felker
2015-06-12  4:26         ` Yoshinori Sato
2015-06-12  4:35           ` Rich Felker [this message]
2015-06-12  4:49             ` uClinux.org
2015-06-12  6:37               ` Rich Felker
2015-06-12  6:46                 ` D. Jeff Dionne
2015-06-12  4:08       ` Yoshinori Sato
2015-06-12  4:28         ` Rich Felker
2015-06-16  6:38           ` Yoshinori Sato
2015-06-16  7:02             ` Rich Felker

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=20150612043555.GD17573@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=Jeff@uClinux.org \
    --cc=musl@lists.openwall.com \
    --cc=shumpei.kawasaki@swhwc.com \
    --cc=ysato@users.sourceforge.jp \
    /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).