mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 08:36:15 +00:00
Kernel: Move E2BIG calculation from Thread to Process
Thread::make_userspace_stack_for_main_thread is only ever called from Process::do_exec, after all the fun ELF loading and TSS setup has occured. The calculations in there that check if the combined argv + envp size will exceed the default stack size are not used in the rest of the stack setup. So, it should be safe to move this to the beginning of do_exec and bail early with -E2BIG, just like the man pages say. Additionally, advertise this limit in limits.h to be a good POSIX.1 citizen. :)
This commit is contained in:
committed by
Andreas Kling
parent
3014fdf3bd
commit
98c86e5109
@@ -33,6 +33,7 @@
|
||||
#include <Kernel/StdLib.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
#include <Kernel/TTY/MasterPTY.h>
|
||||
#include <Kernel/Thread.h>
|
||||
#include <Kernel/VM/InodeVMObject.h>
|
||||
#include <LibC/errno_numbers.h>
|
||||
#include <LibC/signal_numbers.h>
|
||||
@@ -379,6 +380,18 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
size_t total_blob_size = 0;
|
||||
for (auto& a : arguments)
|
||||
total_blob_size += a.length() + 1;
|
||||
for (auto& e : environment)
|
||||
total_blob_size += e.length() + 1;
|
||||
|
||||
size_t total_meta_size = sizeof(char*) * (arguments.size() + 1) + sizeof(char*) * (environment.size() + 1);
|
||||
|
||||
// FIXME: How much stack space does process startup need?
|
||||
if ((total_blob_size + total_meta_size) >= Thread::default_userspace_stack_size)
|
||||
return -E2BIG;
|
||||
|
||||
auto parts = path.split('/');
|
||||
if (parts.is_empty())
|
||||
return -ENOENT;
|
||||
|
||||
Reference in New Issue
Block a user