From e555b3c5901dc495e683529b663eab8ff0f36482 Mon Sep 17 00:00:00 2001
From: Ian Moffett <ian@osmora.org>
Date: Wed, 10 Apr 2024 16:37:18 -0400
Subject: kernel: sched: Lock thread upon sched_exit()

Signed-off-by: Ian Moffett <ian@osmora.org>
---
 sys/kern/kern_sched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c
index 4eb0cf3..afaf6a8 100644
--- a/sys/kern/kern_sched.c
+++ b/sys/kern/kern_sched.c
@@ -318,8 +318,8 @@ sched_exit(void)
     struct vas kvas = vm_get_kvas();
 
     intr_mask();
-
     td = this_td();
+    spinlock_acquire(&td->lock);    /* Never release */
 
     /* Switch back to the kernel address space and destroy ourself */
     pmap_switch_vas(vm_get_ctx(), kvas);
-- 
cgit v1.2.3