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

LibPthread: implicitly call pthread_exit on return from start routine.

Previously, when returning from a pthread's start_routine, we would
segfault. Now we instead implicitly call pthread_exit as specified in
the standard.

pthread_create now creates a thread running the new
pthread_create_helper, which properly manages the calling and exiting
of the start_routine supplied to pthread_create. To accomplish this,
the thread's stack initialization has been moved out of
sys$create_thread and into the userspace function create_thread.
This commit is contained in:
Drew Stratford 2020-04-25 22:20:44 +12:00 committed by Andreas Kling
parent 4cb765e520
commit 4a37362249
3 changed files with 32 additions and 8 deletions

View file

@ -3754,7 +3754,7 @@ void Process::send_signal(u8 signal, Process* sender)
thread->send_signal(signal, sender);
}
int Process::sys$create_thread(void* (*entry)(void*), void* argument, const Syscall::SC_create_thread_params* user_params)
int Process::sys$create_thread(void* (*entry)(void*), const Syscall::SC_create_thread_params* user_params)
{
REQUIRE_PROMISE(thread);
if (!validate_read((const void*)entry, sizeof(void*)))
@ -3806,10 +3806,6 @@ int Process::sys$create_thread(void* (*entry)(void*), void* argument, const Sysc
tss.cr3 = page_directory().cr3();
tss.esp = user_stack_address;
// NOTE: The stack needs to be 16-byte aligned.
thread->push_value_on_stack((FlatPtr)argument);
thread->push_value_on_stack(0);
thread->make_thread_specific_region({});
thread->set_state(Thread::State::Runnable);
return thread->tid();