ps: fix stack freeing bug

The thread could still be running on its stack whenever the stack ends
up getting reaped, which would free and reuse the stack before it
stops being used. Lock and unlock the thread to wait until it finishes
switching.
This commit is contained in:
Loïc Grégoire
2026-08-02 21:45:47 -04:00
parent e36416304b
commit 312902931f
+5
View File
@@ -25,6 +25,11 @@ fn reap_thread(obj: *anyopaque, _: ?*anyopaque) void {
// Bleh
const entry: *rtl.List.Entry = @fieldParentPtr("next", link);
const ketd: *ke.Thread = @fieldParentPtr("runq_link", entry);
// Wait until the thread finishes switching off its stack.
const ipl = ketd.lock.acquire();
ketd.lock.release(ipl);
const td: *Thread = @fieldParentPtr("kern", ketd);
psp.turnstile_zone.destroy(td.kern.turnstile);