summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-05-28 11:20:22 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-29 15:53:08 +0200
commit42d667645d750648949d18fe67fb09bf82d85a8c (patch)
tree577b75e72c81f29606996f28008ea37f95e691b6 /Kernel/Syscalls
parent95c2166ca985b4fad16eec070c45d7b36088029e (diff)
downloadserenity-42d667645d750648949d18fe67fb09bf82d85a8c.zip
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.
Diffstat (limited to 'Kernel/Syscalls')
-rw-r--r--Kernel/Syscalls/thread.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/Kernel/Syscalls/thread.cpp b/Kernel/Syscalls/thread.cpp
index 42acab2690..3dc4852ac4 100644
--- a/Kernel/Syscalls/thread.cpp
+++ b/Kernel/Syscalls/thread.cpp
@@ -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();
}