tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Potential new syscall



I'm writing a userland emulator - basically, a hardware emulator,
except that it just runs userland; instructions that would trap to
privileged mode are instead handled by the emulator.

While doing this, I ran into a problem: vfork.  Most syscalls are
fairly straightforward, but vfork is a problem.  Most of the problems
I've dealt with easily enough, but there is one that I feel a need for
a new syscall for.  I had a look at the modern vfork(2) manpage via the
web interface, and the SEE ALSO section gives me no reason to think
such a thing exists even in modern NetBSD.  (I could just implement
vfork as fork, but I'd prefer to be a faithful emulation if I can.)

Basically, what I want is a syscall that a vfork()ed child can call to
have the unsharing effects of execve(2) or _exit(2) (return the vmspace
to the parent and let the it continue), while the child carries on with
a clone of the vmspace without actually doing an exec or exit.  This is
because the emulator does not exec in the hosting-OS sense when the
emulated process execs; I have found no other way to get the vfork
semantics right without forking-and-exiting, and that gets process
parenting wrong.  (This would be fixable by adding a manager process,
with everything for which parenting is relevant going via it, or by
having a single emulator process timeshare among all simulated
processes.  A new syscall seems cleaner to me, especially as it fills a
gap in the OS semantics.)

It looks to me as though there is uvm support for the concept, in the
form of vmspace_unshare(), in the version I'm working with; a little
searching makes it appear it's been diked out of uvm_map.c more
recently.  The syscall wrapper around it is only a few lines, basically
just uvmspace_unshare() plus, if PPWAIT is set, kicking the parent.

I offer for consideration the thought that something of the sort might
be worth adding.  I have code written, but I don't yet know whether
what I have works right - a test build is running as I type this - and
it's for a version years behind -current.

Thoughts?  (Not restricted to just the above details; thoughts on the
general idea would also be interesting to me.)

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML		mouse%rodents-montreal.org@localhost
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index