[kernel] Stop creating user stacks in the kernel

Stop creating stacks in user space for user threads, that should be done
by the thread's creator. This change adds process and stack_top
arguments to the thread_create syscall, so that threads can be created
in other processes, and given a stack address.

Also included is a fix in add_thunk_user due to the r11/flags change.

THIS COMMIT BREAKS USERSPACE. See subsequent commits for the user side
changes related to this change.
This commit is contained in:
Justin C. Miller
2021-12-26 15:36:59 -08:00
parent cade24a7ce
commit 300bf9c2c5
6 changed files with 24 additions and 27 deletions

View File

@@ -9,19 +9,22 @@
namespace syscalls {
j6_status_t
thread_create(j6_handle_t *handle, uintptr_t entrypoint)
thread_create(j6_handle_t *handle, j6_handle_t proc, uintptr_t stack_top, uintptr_t entrypoint)
{
thread &parent = thread::current();
process &p = parent.parent();
thread &parent_th = thread::current();
process &parent_pr = parent_th.parent();
thread *child = p.create_thread();
process *owner = get_handle<process>(proc);
if (!owner) return j6_err_invalid_arg;
thread *child = owner->create_thread(stack_top);
child->add_thunk_user(entrypoint);
*handle = child->self_handle();
child->clear_state(thread::state::loading);
child->set_state(thread::state::ready);
log::debug(logs::task, "Thread %llx spawned new thread %llx, handle %d",
parent.koid(), child->koid(), *handle);
log::debug(logs::task, "Thread %llx:%llx spawned new thread %llx:%llx",
parent_pr.koid(), parent_th.koid(), owner->koid(), child->koid());
return j6_status_ok;
}