execute a user process in the kernel

Robert Watson rwatson at freebsd.org
Fri Sep 24 11:12:13 PDT 2004


On Fri, 24 Sep 2004, Dag-Erling Smørgrav wrote:

> execve(2) assumes you already have a process.  You get a process by
> forking another process.  The only process we ever create from scratch
> is init(8), and that takes a s**tload of work (see kern/init_main.c). 
> This is why we have stuff like nfsiod(8) which does nothing but provide
> the kernel with a process context it can use for other stuff. 
> 
> You could, of course, write a kernel API for creating processes from
> scratch.  They'd still need a parent, but you can use init(8) (pid 1) 
> for that. 

Well, we have kproc/kthread APIs, but none of that is semantically
compatible with the notion of execve(), which is a very user-centric
concept ("replace the address space with a mapping of binary <x>").  You
could fudge together a related notion, though, involving loadable kernel
modules that have a main() routine run from a thread.  That said, the
notion of simply running user code in kernel (as has been pointed out) is
fraught with peril, primarily because the kernel is basically one big
program with many special requirements, and user applications are written
with the assumption that they are the only program, not running in the
context of another program.

Robert N M Watson             FreeBSD Core Team, TrustedBSD Projects
robert at fledge.watson.org      Principal Research Scientist, McAfee Research




More information about the freebsd-hackers mailing list