From cad354b671cc7fa783a3fd0631a0f85c40b69a0c Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 28 Apr 2022 19:59:37 +0200 Subject: kernel/proc: automatically free processes given the chance --- src/kernel/main.c | 5 ----- src/kernel/proc.c | 8 ++++++-- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/kernel') diff --git a/src/kernel/main.c b/src/kernel/main.c index 14514cb..a0fdd07 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -27,11 +27,6 @@ void shutdown(void) { for (size_t i = 0; i < sizeof(states) / sizeof(*states); i++) kprintf("state 0x%x: 0x%x\n", i, states[i]); - mem_debugprint(); - - // TODO generalize to process_cleanup - process_free(process_first); - mem_debugprint(); cpu_shutdown(); } diff --git a/src/kernel/proc.c b/src/kernel/proc.c index f17b94c..57b9669 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -86,7 +86,6 @@ void process_forget(struct process *p) { } void process_free(struct process *p) { - // TODO only attempt to free, return a bool bool valid = false; if (p->state == PS_DEADER) valid = true; if (p->state == PS_DEAD && (!p->parent @@ -121,7 +120,7 @@ static _Noreturn void process_idle(void) { if (len == 0) shutdown(); - if (process_first->state == PS_DEAD) { + if (process_first->state == PS_DEAD || process_first->state == PS_DEADER) { /* special case: if the system is about to shut off, stop waiting for IRQs * usually this would be an issue because it would let processes know if * they're using the kernel handler, but the system is shutting off anyways, @@ -305,6 +304,10 @@ int process_try2collect(struct process *dead) { assert(dead->state == PS_DEAD); + if (!parent) { + process_transition(dead, PS_DEADER); + return -1; + } switch (parent->state) { case PS_WAITS4CHILDDEATH: ret = dead->death_msg; @@ -316,6 +319,7 @@ int process_try2collect(struct process *dead) { case PS_DEAD: case PS_DEADER: + case PS_DUMMY: process_transition(dead, PS_DEADER); return -1; -- cgit v1.2.3