mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-05 02:33:03 +00:00
Kernel+LibPthread+LibC: Create secondary thread stacks in userspace
Have pthread_create() allocate a stack and passing it to the kernel instead of this work happening in the kernel. The more of this we can do in userspace, the better. This patch also unexposes the raw create_thread() and exit_thread() syscalls since they are now only used by LibPthread anyway.
This commit is contained in:
parent
6685be36a0
commit
e34ed04d1e
Notes:
sideshowbarker
2024-07-19 11:10:50 +09:00
Author: https://github.com/awesomekling
Commit: e34ed04d1e
7 changed files with 30 additions and 33 deletions
|
@ -2861,16 +2861,23 @@ int Process::thread_count() const
|
|||
return count;
|
||||
}
|
||||
|
||||
int Process::sys$create_thread(void* (*entry)(void*), void* argument)
|
||||
int Process::sys$create_thread(void* (*entry)(void*), void* argument, void* stack)
|
||||
{
|
||||
if (!validate_read((const void*)entry, sizeof(void*)))
|
||||
return -EFAULT;
|
||||
if (!MM.validate_user_stack(*this, VirtualAddress(((u32)stack) - 4)))
|
||||
return -EFAULT;
|
||||
auto* thread = new Thread(*this);
|
||||
auto& tss = thread->tss();
|
||||
tss.eip = (u32)entry;
|
||||
tss.eflags = 0x0202;
|
||||
tss.cr3 = page_directory().cr3();
|
||||
thread->make_userspace_stack_for_secondary_thread(argument);
|
||||
tss.esp = (u32)stack;
|
||||
|
||||
// NOTE: The stack needs to be 16-byte aligned.
|
||||
thread->push_value_on_stack((u32)argument);
|
||||
thread->push_value_on_stack(0);
|
||||
|
||||
thread->make_thread_specific_region({});
|
||||
thread->set_state(Thread::State::Runnable);
|
||||
return thread->tid();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue