summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/include/sys/proc.h2
-rw-r--r--sys/kern/kern_exit.c42
2 files changed, 28 insertions, 16 deletions
diff --git a/sys/include/sys/proc.h b/sys/include/sys/proc.h
index 37cf413..25f5fd3 100644
--- a/sys/include/sys/proc.h
+++ b/sys/include/sys/proc.h
@@ -88,6 +88,8 @@ struct proc {
struct proc *this_td(void);
struct proc *get_child(struct proc *cur, pid_t pid);
+void proc_reap(struct proc *td);
+
int md_spawn(struct proc *p, struct proc *parent, uintptr_t ip);
scret_t sys_spawn(struct syscall_args *scargs);
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index 242b221..a421e52 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -78,6 +78,30 @@ unload_td(struct proc *td)
}
}
+void
+proc_reap(struct proc *td)
+{
+ struct pcb *pcbp;
+ uintptr_t stack;
+
+ pcbp = &td->pcb;
+ stack = td->stack_base;
+
+ /*
+ * If this is on the higher half, it is kernel
+ * mapped and we need to convert it to a physical
+ * address.
+ */
+ if (stack >= VM_HIGHER_HALF) {
+ stack -= VM_HIGHER_HALF;
+ }
+
+ unload_td(td);
+ vm_unmap(pcbp->addrsp, td->stack_base, PROC_STACK_SIZE);
+ vm_free_frame(stack, PROC_STACK_PAGES);
+ pmap_destroy_vas(pcbp->addrsp);
+}
+
/*
* Kill a thread and deallocate its resources.
*
@@ -86,19 +110,15 @@ unload_td(struct proc *td)
int
exit1(struct proc *td, int flags)
{
- struct pcb *pcbp;
struct proc *curtd, *procp;
struct cpu_info *ci;
- uintptr_t stack;
pid_t target_pid, curpid;
ci = this_cpu();
target_pid = td->pid;
curtd = this_td();
- pcbp = &td->pcb;
curpid = curtd->pid;
- stack = td->stack_base;
td->flags |= PROC_EXITING;
/* If we have any children, kill them too */
@@ -108,20 +128,10 @@ exit1(struct proc *td, int flags)
}
}
- /*
- * If this is on the higher half, it is kernel
- * mapped and we need to convert it to a physical
- * address.
- */
- if (stack >= VM_HIGHER_HALF) {
- stack -= VM_HIGHER_HALF;
+ if (target_pid != curpid) {
+ proc_reap(td);
}
- unload_td(td);
- vm_unmap(pcbp->addrsp, td->stack_base, PROC_STACK_SIZE);
- vm_free_frame(stack, PROC_STACK_PAGES);
- pmap_destroy_vas(pcbp->addrsp);
-
/*
* Only free the process structure if we aren't
* being waited on, otherwise let it be so the