Compare commits
No commits in common. "58eb2d7703d306195d8f563642f0ea17f50d4faa" and "3eb78aa5f34398d65fad56e6fe66b19b29401c3b" have entirely different histories.
58eb2d7703
...
3eb78aa5f3
@ -31,37 +31,16 @@ static Result<Vector<String>> copy_string_vector_from_userspace(u64 address)
|
||||
return result;
|
||||
}
|
||||
|
||||
static u64 calculate_userspace_stack_size(const Vector<String>& v)
|
||||
{
|
||||
u64 total { 0 };
|
||||
|
||||
for (const auto& str : v)
|
||||
{
|
||||
// The string's byte count + a terminating NUL byte.
|
||||
total += str.length() + 1;
|
||||
// The pointer to said string in the userspace array.
|
||||
total += sizeof(char*);
|
||||
}
|
||||
|
||||
// The NULL pointer at the end of the userspace array.
|
||||
total += sizeof(char*);
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
static constexpr usize MAX_ARGV_STACK_SIZE = 2 * ARCH_PAGE_SIZE;
|
||||
|
||||
Result<u64> sys_execve(Registers* regs, SyscallArgs args)
|
||||
{
|
||||
auto path = TRY(MemoryManager::strdup_from_user(args[0]));
|
||||
auto argv = TRY(copy_string_vector_from_userspace(args[1]));
|
||||
auto envp = TRY(copy_string_vector_from_userspace(args[2]));
|
||||
|
||||
if ((calculate_userspace_stack_size(argv) + calculate_userspace_stack_size(envp)) > MAX_ARGV_STACK_SIZE)
|
||||
return err(E2BIG);
|
||||
|
||||
auto current = Scheduler::current();
|
||||
|
||||
// FIXME: Make sure argv & envp are not too big.
|
||||
|
||||
auto inode = TRY(VFS::resolve_path(path.chars(), current->auth, current->current_directory));
|
||||
|
||||
if (!VFS::can_execute(inode, current->auth)) return err(EACCES);
|
||||
|
@ -3,15 +3,11 @@
|
||||
#include "thread/Thread.h"
|
||||
#include <luna/CString.h>
|
||||
|
||||
static constexpr usize DEFAULT_USER_STACK_PAGES = 6;
|
||||
static constexpr usize DEFAULT_USER_STACK_SIZE = DEFAULT_USER_STACK_PAGES * ARCH_PAGE_SIZE;
|
||||
|
||||
static Result<void> create_stacks(Stack& user_stack, Stack& kernel_stack)
|
||||
{
|
||||
const u64 THREAD_STACK_BASE = 0x10000;
|
||||
|
||||
TRY(MemoryManager::alloc_at_zeroed(THREAD_STACK_BASE, DEFAULT_USER_STACK_PAGES,
|
||||
MMU::ReadWrite | MMU::NoExecute | MMU::User));
|
||||
TRY(MemoryManager::alloc_at_zeroed(THREAD_STACK_BASE, 4, MMU::ReadWrite | MMU::NoExecute | MMU::User));
|
||||
|
||||
auto guard = make_scope_guard([&] { MemoryManager::unmap_owned(THREAD_STACK_BASE, 4); });
|
||||
|
||||
@ -19,7 +15,7 @@ static Result<void> create_stacks(Stack& user_stack, Stack& kernel_stack)
|
||||
|
||||
guard.deactivate();
|
||||
|
||||
user_stack = { THREAD_STACK_BASE, DEFAULT_USER_STACK_SIZE };
|
||||
user_stack = { THREAD_STACK_BASE, 4 * ARCH_PAGE_SIZE };
|
||||
kernel_stack = { kernel_stack_base, 4 * ARCH_PAGE_SIZE };
|
||||
|
||||
return {};
|
||||
|
@ -7,7 +7,8 @@ extern "C"
|
||||
{
|
||||
_weak [[noreturn]] void __assertion_failed(const char* file, int line, const char* function, const char* expr)
|
||||
{
|
||||
fprintf(stderr, "%s:%d: %s: Assertion '%s' failed.\n", file, line, function, expr);
|
||||
// FIXME: Output to standard error instead of standard output.
|
||||
printf("%s:%d: %s: Assertion '%s' failed.\n", file, line, function, expr);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
_weak [[noreturn]] bool __check_failed(SourceLocation location, const char* expr)
|
||||
{
|
||||
fprintf(stderr, "Check failed at %s:%d in %s: %s\n", location.file(), location.line(), location.function(), expr);
|
||||
// FIXME: Output to standard error instead of standard output.
|
||||
printf("Check failed at %s:%d in %s: %s\n", location.file(), location.line(), location.function(), expr);
|
||||
abort();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user