- vrelvm();
- } else {
- p->p_flag &= ~SVFORK;
- wakeup((caddr_t)p);
- while ((p->p_flag & SVFDONE) == 0)
- sleep((caddr_t)p, PZERO - 1);
- p->p_flag &= ~SVFDONE;
- }
- for (i = 0; i <= u.u_lastfile; i++) {
- struct file *f;
+ /*
+ * Release user portion of address space.
+ * This releases references to vnodes,
+ * which could cause I/O if the file has been unlinked.
+ * Need to do this early enough that we can still sleep.
+ * Can't free the entire vmspace as the kernel stack
+ * may be mapped within that space also.
+ */
+ if (p->p_vmspace->vm_refcnt == 1)
+ (void) vm_map_remove(&p->p_vmspace->vm_map, VM_MIN_ADDRESS,
+ VM_MAXUSER_ADDRESS);