mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:57:35 +00:00
Kernel: Unwind kernel stacks before dying
While executing in the kernel, a thread can acquire various resources that need cleanup, such as locks and references to RefCounted objects. This cleanup normally happens on the exit path, such as in destructors for various RAII guards. But we weren't calling those exit paths when killing threads that have been executing in the kernel, such as threads blocked on reading or sleeping, thus causing leaks. This commit changes how killing threads works. Now, instead of killing a thread directly, one is supposed to call thread->set_should_die(), which will unblock it and make it unwind the stack if it is blocked in the kernel. Then, just before returning to the userspace, the thread will automatically die.
This commit is contained in:
parent
00e56cda0c
commit
1e1ddce9d8
4 changed files with 58 additions and 7 deletions
|
@ -276,6 +276,11 @@ public:
|
|||
|
||||
void unblock();
|
||||
|
||||
// Tell this thread to unblock if needed,
|
||||
// gracefully unwind the stack and die.
|
||||
void set_should_die();
|
||||
void die_if_needed();
|
||||
|
||||
const FarPtr& far_ptr() const { return m_far_ptr; }
|
||||
|
||||
bool tick();
|
||||
|
@ -356,6 +361,7 @@ private:
|
|||
ThreadPriority m_priority { ThreadPriority::Normal };
|
||||
bool m_has_used_fpu { false };
|
||||
bool m_dump_backtrace_on_finalization { false };
|
||||
bool m_should_die { false };
|
||||
|
||||
void block_helper();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue