kernel: Move copy_string_vector_to_userspace to ThreadImage
This commit is contained in:
parent
b22bea84ec
commit
3a70accdeb
@ -31,21 +31,6 @@ static Result<Vector<String>> copy_string_vector_from_userspace(u64 address)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result<u64> copy_string_vector_to_userspace(const Vector<String>& vec, ThreadImage& image)
|
|
||||||
{
|
|
||||||
Vector<u64> user_vec;
|
|
||||||
for (const auto& item : vec)
|
|
||||||
{
|
|
||||||
// Copy each individual string and retrieve a userspace pointer to said copy
|
|
||||||
u64 addr = TRY(image.push_mem_on_stack((const u8*)item.chars(), item.length() + 1));
|
|
||||||
TRY(user_vec.try_append(addr));
|
|
||||||
}
|
|
||||||
|
|
||||||
TRY(user_vec.try_append((u64) nullptr));
|
|
||||||
// Copy the actual vector of userspace pointers to the stack
|
|
||||||
return TRY(image.push_mem_on_stack((u8*)user_vec.data(), user_vec.size() * sizeof(u64)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<u64> sys_exec(Registers* regs, SyscallArgs args)
|
Result<u64> sys_exec(Registers* regs, SyscallArgs args)
|
||||||
{
|
{
|
||||||
auto path = TRY(MemoryManager::strdup_from_user(args[0]));
|
auto path = TRY(MemoryManager::strdup_from_user(args[0]));
|
||||||
@ -68,7 +53,7 @@ Result<u64> sys_exec(Registers* regs, SyscallArgs args)
|
|||||||
|
|
||||||
kdbgln("exec: copying argv to image memory (argc = %zu)", argv.size());
|
kdbgln("exec: copying argv to image memory (argc = %zu)", argv.size());
|
||||||
|
|
||||||
u64 user_argv = TRY(copy_string_vector_to_userspace(argv, *image));
|
u64 user_argv = TRY(image->push_string_vector_on_stack(argv));
|
||||||
usize user_argc = argv.size();
|
usize user_argc = argv.size();
|
||||||
|
|
||||||
// From now on, nothing should fail.
|
// From now on, nothing should fail.
|
||||||
|
@ -92,6 +92,21 @@ Result<u64> ThreadImage::push_mem_on_stack(const u8* mem, usize size)
|
|||||||
return m_sp;
|
return m_sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result<u64> ThreadImage::push_string_vector_on_stack(const Vector<String>& vec)
|
||||||
|
{
|
||||||
|
Vector<u64> user_vec;
|
||||||
|
for (const auto& item : vec)
|
||||||
|
{
|
||||||
|
// Copy each individual string and retrieve a userspace pointer to said copy
|
||||||
|
u64 addr = TRY(push_mem_on_stack((const u8*)item.chars(), item.length() + 1));
|
||||||
|
TRY(user_vec.try_append(addr));
|
||||||
|
}
|
||||||
|
|
||||||
|
TRY(user_vec.try_append((u64) nullptr));
|
||||||
|
// Copy the actual vector of userspace pointers to the stack
|
||||||
|
return TRY(push_mem_on_stack((u8*)user_vec.data(), user_vec.size() * sizeof(u64)));
|
||||||
|
}
|
||||||
|
|
||||||
void ThreadImage::apply(Thread* thread)
|
void ThreadImage::apply(Thread* thread)
|
||||||
{
|
{
|
||||||
thread->init_regs_user();
|
thread->init_regs_user();
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <luna/OwnedPtr.h>
|
#include <luna/OwnedPtr.h>
|
||||||
#include <luna/Result.h>
|
#include <luna/Result.h>
|
||||||
#include <luna/Stack.h>
|
#include <luna/Stack.h>
|
||||||
|
#include <luna/Vector.h>
|
||||||
|
|
||||||
class Thread;
|
class Thread;
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ class ThreadImage
|
|||||||
static Result<OwnedPtr<ThreadImage>> clone_from_thread(Thread* parent);
|
static Result<OwnedPtr<ThreadImage>> clone_from_thread(Thread* parent);
|
||||||
|
|
||||||
Result<u64> push_mem_on_stack(const u8* mem, usize size);
|
Result<u64> push_mem_on_stack(const u8* mem, usize size);
|
||||||
|
Result<u64> push_string_vector_on_stack(const Vector<String>& vec);
|
||||||
|
|
||||||
void apply(Thread* thread);
|
void apply(Thread* thread);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user