1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-29 01:42:11 +00:00

Kernel+LibC: Add a simple create_thread() syscall.

It takes two parameters, a function pointer for the entry function,
and a void* argument to be passed to that function on the new thread.
This commit is contained in:
Andreas Kling 2019-03-23 22:59:08 +01:00
parent 7f1757b16c
commit e561ab1b0b
10 changed files with 45 additions and 5 deletions

View file

@ -406,7 +406,7 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
main_thread().m_tss.gs = 0x23;
main_thread().m_tss.ss = 0x23;
main_thread().m_tss.cr3 = page_directory().cr3();
main_thread().make_userspace_stack(move(arguments), move(environment));
main_thread().make_userspace_stack_for_main_thread(move(arguments), move(environment));
main_thread().m_tss.ss0 = 0x10;
main_thread().m_tss.esp0 = old_esp0;
main_thread().m_tss.ss2 = m_pid;
@ -2452,3 +2452,18 @@ int Process::thread_count() const
});
return count;
}
int Process::sys$create_thread(int(*entry)(void*), void* argument)
{
if (!validate_read((const void*)entry, sizeof(void*)))
return -EFAULT;
auto* thread = new Thread(*this);
auto& tss = thread->tss();
tss.eip = (dword)entry;
tss.eflags = 0x0202;
tss.cr3 = page_directory().cr3();
thread->make_userspace_stack_for_secondary_thread(argument);
thread->set_state(Thread::State::Runnable);
return 0;
}