Kernel: Move userspace entry functions to Process instead of Thread

This commit is contained in:
Bananymous
2023-05-31 19:25:53 +03:00
parent dcb23f686f
commit 5fb69300ca
4 changed files with 23 additions and 19 deletions

View File

@@ -94,13 +94,18 @@ namespace Kernel
char** argv = nullptr;
{
PageTableScope _(process->page_table());
argv = (char**)MUST(process->allocate(sizeof(char**) * 1));
argv = (char**)MUST(process->allocate(sizeof(char**) * 2));
argv[0] = (char*)MUST(process->allocate(path.size() + 1));
memcpy(argv[0], path.data(), path.size());
argv[0][path.size()] = '\0';
argv[1] = nullptr;
}
auto* thread = MUST(Thread::create_userspace(elf_file_header.e_entry, process, 1, argv));
process->m_userspace_entry.argc = 1;
process->m_userspace_entry.argv = argv;
process->m_userspace_entry.entry = elf_file_header.e_entry;
auto* thread = MUST(Thread::create_userspace(process));
process->add_thread(thread);
delete elf;
@@ -198,6 +203,8 @@ namespace Kernel
forked->m_open_files = m_open_files;
forked->m_userspace_entry = m_userspace_entry;
for (auto* mapped_range : m_mapped_ranges)
MUST(forked->m_mapped_ranges.push_back(mapped_range->clone(forked->page_table())));

View File

@@ -43,7 +43,7 @@ namespace Kernel
return thread;
}
BAN::ErrorOr<Thread*> Thread::create_userspace(uintptr_t entry, Process* process, int argc, char** argv)
BAN::ErrorOr<Thread*> Thread::create_userspace(Process* process)
{
ASSERT(process);
@@ -69,13 +69,11 @@ namespace Kernel
return BAN::Error::from_errno(ENOMEM);
}
thread->m_userspace_entry = { .entry = entry, .argc = argc, .argv = argv };
// Setup registers and entry
static entry_t entry_trampoline(
[](void*)
{
userspace_entry_t& entry = Thread::current().m_userspace_entry;
const auto& entry = Process::current().userspace_entry();
thread_userspace_trampoline(Thread::current().rsp(), entry.entry, entry.argc, entry.argv);
ASSERT_NOT_REACHED();
}
@@ -140,8 +138,6 @@ namespace Kernel
thread->m_rip = rip;
thread->m_rsp = rsp;
thread->m_userspace_entry = {};
return thread;
}