only delete space used by inode, on inode deletion; required
[unix-history] / usr / src / sys / kern / kern_exit.c
index 384d807..a86e27b 100644 (file)
@@ -4,18 +4,18 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)kern_exit.c 7.38 (Berkeley) %G%
+ *     @(#)kern_exit.c 7.43 (Berkeley) %G%
  */
 
 #include "param.h"
 #include "systm.h"
 #include "map.h"
 #include "ioctl.h"
  */
 
 #include "param.h"
 #include "systm.h"
 #include "map.h"
 #include "ioctl.h"
+#include "proc.h"
 #include "tty.h"
 #include "time.h"
 #include "resource.h"
 #include "kernel.h"
 #include "tty.h"
 #include "time.h"
 #include "resource.h"
 #include "kernel.h"
-#include "proc.h"
 #include "buf.h"
 #include "wait.h"
 #include "file.h"
 #include "buf.h"
 #include "wait.h"
 #include "file.h"
@@ -61,6 +61,7 @@ exit(p, rv)
 {
        register struct proc *q, *nq;
        register struct proc **pp;
 {
        register struct proc *q, *nq;
        register struct proc **pp;
+       register struct vmspace *vm;
        int s;
 
 #ifdef PGINPROF
        int s;
 
 #ifdef PGINPROF
@@ -85,8 +86,9 @@ exit(p, rv)
        fdfree(p);
 
        /* The next two chunks should probably be moved to vmspace_exit. */
        fdfree(p);
 
        /* The next two chunks should probably be moved to vmspace_exit. */
+       vm = p->p_vmspace;
 #ifdef SYSVSHM
 #ifdef SYSVSHM
-       if (p->p_vmspace->vm_shm)
+       if (vm->vm_shm)
                shmexit(p);
 #endif
        /*
                shmexit(p);
 #endif
        /*
@@ -97,8 +99,8 @@ exit(p, rv)
         * Can't free the entire vmspace as the kernel stack
         * may be mapped within that space also.
         */
         * 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,
+       if (vm->vm_refcnt == 1)
+               (void) vm_map_remove(&vm->vm_map, VM_MIN_ADDRESS,
                    VM_MAXUSER_ADDRESS);
 
        if (p->p_pid == 1)
                    VM_MAXUSER_ADDRESS);
 
        if (p->p_pid == 1)
@@ -136,18 +138,10 @@ exit(p, rv)
        /* 
         * release trace file
         */
        /* 
         * release trace file
         */
+       p->p_traceflag = 0;     /* don't trace the vrele() */
        if (p->p_tracep)
                vrele(p->p_tracep);
 #endif
        if (p->p_tracep)
                vrele(p->p_tracep);
 #endif
-       /*
-        * Clear curproc after we've done all operations
-        * that could block, and before tearing down
-        * the rest of the process state.
-        */
-       curproc = NULL;
-       if (--p->p_limit->p_refcnt == 0)
-               FREE(p->p_limit, M_SUBPROC);
-
        /*
         * Remove proc from allproc queue and pidhash chain.
         * Place onto zombproc.  Unlink from parent's child list.
        /*
         * Remove proc from allproc queue and pidhash chain.
         * Place onto zombproc.  Unlink from parent's child list.
@@ -159,6 +153,7 @@ exit(p, rv)
        p->p_prev = &zombproc;
        zombproc = p;
        p->p_stat = SZOMB;
        p->p_prev = &zombproc;
        zombproc = p;
        p->p_stat = SZOMB;
+
        for (pp = &pidhash[PIDHASH(p->p_pid)]; *pp; pp = &(*pp)->p_hash)
                if (*pp == p) {
                        *pp = p->p_hash;
        for (pp = &pidhash[PIDHASH(p->p_pid)]; *pp; pp = &(*pp)->p_hash)
                if (*pp == p) {
                        *pp = p->p_hash;
@@ -210,6 +205,20 @@ done:
        /* move this to cpu_exit */
        p->p_addr->u_pcb.pcb_savacc.faddr = (float *)NULL;
 #endif
        /* move this to cpu_exit */
        p->p_addr->u_pcb.pcb_savacc.faddr = (float *)NULL;
 #endif
+       /*
+        * Clear curproc after we've done all operations
+        * that could block, and before tearing down the rest
+        * of the process state that might be used from clock, etc.
+        * Also, can't clear curproc while we're still runnable,
+        * as we're not on a run queue (we are current, just not
+        * a proper proc any longer!).
+        *
+        * Other substructures are freed from wait().
+        */
+       curproc = NULL;
+       if (--p->p_limit->p_refcnt == 0)
+               FREE(p->p_limit, M_SUBPROC);
+
        /*
         * Finally, call machine-dependent code to release the remaining
         * resources including address space, the kernel stack and pcb.
        /*
         * Finally, call machine-dependent code to release the remaining
         * resources including address space, the kernel stack and pcb.
@@ -237,12 +246,12 @@ owait(p, uap, retval)
 {
 
 #ifdef PSL_ALLCC
 {
 
 #ifdef PSL_ALLCC
-       if ((p->p_regs[PS] & PSL_ALLCC) != PSL_ALLCC) {
+       if ((p->p_md.md_regs[PS] & PSL_ALLCC) != PSL_ALLCC) {
                uap->options = 0;
                uap->rusage = 0;
        } else {
                uap->options = 0;
                uap->rusage = 0;
        } else {
-               uap->options = p->p_regs[R0];
-               uap->rusage = (struct rusage *)p->p_regs[R1];
+               uap->options = p->p_md.md_regs[R0];
+               uap->rusage = (struct rusage *)p->p_md.md_regs[R1];
        }
 #else
        uap->options = 0;
        }
 #else
        uap->options = 0;