diff --git a/kernel/include/kernel/Process.h b/kernel/include/kernel/Process.h index 406561aedc..1014a64af8 100644 --- a/kernel/include/kernel/Process.h +++ b/kernel/include/kernel/Process.h @@ -47,7 +47,7 @@ namespace Kernel static Process* create_kernel(entry_t, void*); static BAN::ErrorOr create_userspace(const Credentials&, BAN::StringView path, BAN::Span arguments); ~Process(); - void cleanup_function(); + void cleanup_function(Thread*); void register_to_scheduler(); void exit(int status, int signal); diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index af3b139e7b..ff5faa6555 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -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) diff --git a/kernel/kernel/Thread.cpp b/kernel/kernel/Thread.cpp index 4533fbb46d..ef63b34ddb 100644 --- a/kernel/kernel/Thread.cpp +++ b/kernel/kernel/Thread.cpp @@ -242,7 +242,7 @@ namespace Kernel ASSERT(thread->m_process == process); - process->cleanup_function(); + process->cleanup_function(thread); thread->m_delete_process = true;