9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Alexander Viro <viro@math.psu.edu>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] rfork(), getss() etc etc
Date: Sat,  2 Sep 2000 05:31:28 -0400	[thread overview]
Message-ID: <Pine.GSO.4.10.10009020511350.9425-100000@weyl.math.psu.edu> (raw)
In-Reply-To: <Pine.GSO.4.10.10009020407570.9425-100000@weyl.math.psu.edu>



On Sat, 2 Sep 2000, I wrote:

> On Sat, 2 Sep 2000 nigel@9fs.org wrote:
> 
> > Now, what is the problem with this? Firslty, the only way to tell whether
> > you are parent or child after the split is to check the return result from
> > the system call. The inevitable conclusion is that assembly code is
> > required to establish a new stack. This is a retrograde step, and I am
> 
> 	Simply not true. Kernel is perfectly able to set the usermode ESP
> before returning to userland. Code that does transition from the kernel
> mode to user mode is in the kernel. Usually it's an assembler (check
> forkret() in /sys/src/9/pc/l.s for exact parallel). Picking the right ESP
> value happens in IRETL, same way on all systems in question. Nothing
> special in userland.

	Damn. Sorry, I've realized what you might mean right after sending
the reply ;-/ Yes, there is some userland trickery. Unlike other system
calls this beast does essentially

	register (int *)fn(void*) = _fn;
	register void *arg = _arg;
	register unsigned flagd = _flags;
	register int pid;

	/* new_sp ignored unless flags has CLONE_VM set */
	pid = _syscall2(__NR_CLONE, flags, new_sp);
	if ((flags & CLONE_VM) && pid == 0)
		exit((*fn)(arg));
	return pid;

with some gcc-isms to _force_ these variables to be in registers.

Since the thing is in the library _and_ contains the assembler anyway (as
any other system call wrapper, be it on Linux, Plan 9 or FreeBSD -
INTR is hardly pure C ;-)... Yes, you have some point, but not too
serious one. Ironic, since the unusual (compared to other system calls)
part doesn't require any assembler...



  reply	other threads:[~2000-09-02  9:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-09-02  7:50 nigel
2000-09-02  8:57 ` Alexander Viro
2000-09-02  9:31   ` Alexander Viro [this message]
2000-09-02  9:39     ` Alexander Viro
2000-09-02  9:49 nigel
2000-09-02 10:52 ` Alexander Viro
2000-09-03  2:51   ` Scott Schwartz
2000-09-03  3:03     ` Boyd Roberts
2000-09-05  5:32     ` Erik Theisen

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=Pine.GSO.4.10.10009020511350.9425-100000@weyl.math.psu.edu \
    --to=viro@math.psu.edu \
    --cc=9fans@cse.psu.edu \
    /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.
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).