1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 18:05:07 +00:00

Kernel: Make sure we free the thread stack on thread exit

This adds two new arguments to the thread_exit system call which let
a thread unmap an arbitrary VM range on thread exit. LibPthread
uses this functionality to unmap the thread stack.

Fixes #7267.
This commit is contained in:
Gunnar Beutner 2021-05-28 11:20:22 +02:00 committed by Andreas Kling
parent 95c2166ca9
commit 42d667645d
4 changed files with 22 additions and 9 deletions

View file

@ -78,7 +78,7 @@ KResultOr<int> Process::sys$create_thread(void* (*entry)(void*), Userspace<const
return thread->tid().value();
}
void Process::sys$exit_thread(Userspace<void*> exit_value)
void Process::sys$exit_thread(Userspace<void*> exit_value, Userspace<void*> stack_location, size_t stack_size)
{
REQUIRE_PROMISE(thread);
@ -90,6 +90,12 @@ void Process::sys$exit_thread(Userspace<void*> exit_value)
auto current_thread = Thread::current();
PerformanceManager::add_thread_exit_event(*current_thread);
if (stack_location) {
auto unmap_result = space().unmap_mmap_range(VirtualAddress { stack_location }, stack_size);
if (unmap_result.is_error())
dbgln("Failed to unmap thread stack, terminating thread anyway. Error code: {}", unmap_result.error());
}
current_thread->exit(reinterpret_cast<void*>(exit_value.ptr()));
VERIFY_NOT_REACHED();
}