Remove dead process from it's suspension queues
This commit is contained in:
@@ -184,10 +184,35 @@ struct proc* proc_clone (struct proc* proto, uintptr_t vstack_top, size_t stack_
|
||||
|
||||
void proc_cleanup (struct proc* proc) {
|
||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||
spin_lock_ctx_t ctxprpd;
|
||||
spin_lock_ctx_t ctxprpd, ctxsq, ctxpr;
|
||||
|
||||
spin_lock (&proc->lock, &ctxpr);
|
||||
|
||||
/* clean suspension queue entries */
|
||||
struct list_node_link *sq_link, *sq_link_tmp;
|
||||
list_foreach (proc->sq_entries, sq_link, sq_link_tmp) {
|
||||
struct proc_sq_entry* sq_entry = list_entry (sq_link, struct proc_sq_entry, proc_link);
|
||||
struct proc_suspension_q* sq = sq_entry->sq;
|
||||
|
||||
spin_lock (&sq->lock, &ctxsq);
|
||||
|
||||
/* remove from sq's list */
|
||||
list_remove (sq->proc_list, &sq_entry->sq_link);
|
||||
|
||||
/* remove from proc's list */
|
||||
list_remove (proc->sq_entries, &sq_entry->proc_link);
|
||||
|
||||
spin_unlock (&sq->lock, &ctxsq);
|
||||
|
||||
free (sq_entry);
|
||||
}
|
||||
|
||||
spin_unlock (&proc->lock, &ctxpr);
|
||||
|
||||
/* clean resources */
|
||||
proc_cleanup_resources (proc);
|
||||
|
||||
/* clean virtual address space */
|
||||
if (atomic_fetch_sub (&proc->pd->refs, 1) == 1) {
|
||||
DEBUG ("PID %d Free virtual address space\n", proc->pid);
|
||||
struct list_node_link *mapping_link, *mapping_link_tmp;
|
||||
@@ -206,13 +231,16 @@ void proc_cleanup (struct proc* proc) {
|
||||
free (proc->pd);
|
||||
}
|
||||
|
||||
/* clean kstack */
|
||||
pmm_free (proc->pdata.kernel_stack - (uintptr_t)hhdm->offset - KSTACK_SIZE,
|
||||
KSTACK_SIZE / PAGE_SIZE);
|
||||
|
||||
/* clean ustack */
|
||||
if ((proc->flags & PROC_USTK_PREALLOC))
|
||||
pmm_free (proc->pdata.user_stack, USTACK_SIZE / PAGE_SIZE);
|
||||
|
||||
DEBUG ("PID %d Free stacks\n", proc->pid);
|
||||
|
||||
/* clean the process */
|
||||
free (proc);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user