summaryrefslogtreecommitdiff
path: root/Kernel/Process.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-23 22:59:08 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-23 22:59:08 +0100
commite561ab1b0b0c3e37d729ce6620f375ac8fefc0b6 (patch)
tree630600533980f9873370d35f0e286504dbcaa9a8 /Kernel/Process.cpp
parent7f1757b16c82f7398e2386d84d9bae877d5fc39b (diff)
downloadserenity-e561ab1b0b0c3e37d729ce6620f375ac8fefc0b6.zip
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.
Diffstat (limited to 'Kernel/Process.cpp')
-rw-r--r--Kernel/Process.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 4ac23417ad..6f771297d1 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -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;
+}