Kernel: Fix Thread destruction after sys_exit

This had undefined behaviour as Thread's (Processes's) PageTable was
destroyed before Thread had the change to destroy its own stacks that
lived on the PageTable.
This commit is contained in:
Bananymous 2024-11-26 00:59:34 +02:00
parent 48e030bca3
commit 88a86a9927
3 changed files with 6 additions and 4 deletions

View File

@ -47,7 +47,7 @@ namespace Kernel
static Process* create_kernel(entry_t, void*);
static BAN::ErrorOr<Process*> create_userspace(const Credentials&, BAN::StringView path, BAN::Span<BAN::StringView> arguments);
~Process();
void cleanup_function();
void cleanup_function(Thread*);
void register_to_scheduler();
void exit(int status, int signal);

View File

@ -208,7 +208,7 @@ namespace Kernel
{
ASSERT(m_threads.empty());
ASSERT(m_mapped_regions.empty());
ASSERT(&PageTable::current() != m_page_table.ptr());
ASSERT(!m_page_table);
}
void Process::add_thread(Thread* thread)
@ -217,7 +217,7 @@ namespace Kernel
MUST(m_threads.push_back(thread));
}
void Process::cleanup_function()
void Process::cleanup_function(Thread* thread)
{
{
SpinLockGuard _(s_process_lock);
@ -238,6 +238,8 @@ namespace Kernel
// NOTE: We must unmap ranges while the page table is still alive
m_mapped_regions.clear();
thread->give_keep_alive_page_table(BAN::move(m_page_table));
}
bool Process::on_thread_exit(Thread& thread)

View File

@ -242,7 +242,7 @@ namespace Kernel
ASSERT(thread->m_process == process);
process->cleanup_function();
process->cleanup_function(thread);
thread->m_delete_process = true;