From ca77ee47c467f723ba9b1d6ca0bae5966c642492 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 28 May 2025 22:37:52 -0400 Subject: kernel: exit: Ensure curtd is NULL if killed If the current process is killed, make sure that we set the pointer to the currently running process to NULL. Signed-off-by: Ian Moffett --- sys/kern/kern_exit.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index da1e3cf..39fa96d 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -35,6 +35,7 @@ #include #include #include +#include #define pr_trace(fmt, ...) kprintf("exit: " fmt, ##__VA_ARGS__) #define pr_error(...) pr_trace(__VA_ARGS__) @@ -87,9 +88,11 @@ 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; @@ -134,8 +137,10 @@ exit1(struct proc *td, int flags) * If we are the thread exiting, reenter the scheduler * and do not return. */ - if (target_pid == curpid) + if (target_pid == curpid) { + ci->curtd = NULL; sched_enter(); + } return 0; } -- cgit v1.2.3