Date: Wed, 25 Oct 1995 14:43:02 -0400 (EDT) From: "Ron G. Minnich" <rminnich@Sarnoff.COM> To: Theo de Raadt <deraadt@theos.com>, hackers@freebsd.org Subject: anatomy of rfork, part 1: minherit Message-ID: <Pine.SUN.3.91.951025143802.28686A-100000@terra>
next in thread | raw e-mail | index | archive | help
i've had enough q's on this, and time is tight, so i thought i'd just put out a few messages on how to do rfork. The code is small, so bear with me. To do rfork as i needed it, you really need two parts to start with: a way to share data after fork and a way to share file tables after fork. AIX/370 implemented DCE threads with these two things. I thought i'd show minherit first. I don't know the plan9 environment erasing stuff, although that is pretty easy to add -- could be useful. minherit is shown below. Calls are much like mprotect: minherit(caddr, len, new inherit values) Look in vm/vm_inherit.h All you need to do is take the mprotect call code and redo it just a bit so it calls vm_map_inherit. Here we go: struct mprotect_args { caddr_t addr; int len; int inherit; }; int minherit(p, uap, retval) struct proc *p; struct mprotect_args *uap; int *retval; { vm_offset_t addr; vm_size_t size; register vm_inherit_t inherit; #ifdef DEBUG printf("minherit(%d): addr %x len %x prot %d\n", p->p_pid, uap->addr, uap->len, uap->inherit); #endif addr = (vm_offset_t)uap->addr; if ((addr & PAGE_MASK) || uap->len < 0) return(EINVAL); size = (vm_size_t)uap->len; inherit = uap->inherit; switch (vm_map_inherit(&p->p_vmspace->vm_map, addr, addr+size, inherit)) { case KERN_SUCCESS: #ifdef DEBUG printf("works\n"); #endif return (0); case KERN_PROTECTION_FAILURE: #ifdef DEBUG printf("fails\n"); #endif return (EACCES); } #ifdef DEBUG printf("return einval\n"); #endif return (EINVAL); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SUN.3.91.951025143802.28686A-100000>