mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:34:59 +00:00
Kernel+LibC+LibELF: Set stack size based on PT_GNU_STACK during execve
Some programs explicitly ask for a different initial stack size than what the OS provides. This is implemented in ELF by having a PT_GNU_STACK header which has its p_memsz set to the amount that the program requires. This commit implements this policy by reading the p_memsz of the header and setting the main thread stack size to that. ELF::Image::validate_program_headers ensures that the size attribute is a reasonable value.
This commit is contained in:
parent
3275015786
commit
ef6921d7c7
9 changed files with 43 additions and 7 deletions
|
@ -34,7 +34,6 @@ using PthreadAttrImpl = Syscall::SC_create_thread_params;
|
|||
|
||||
static constexpr size_t required_stack_alignment = 4 * MiB;
|
||||
static constexpr size_t highest_reasonable_guard_size = 32 * PAGE_SIZE;
|
||||
static constexpr size_t highest_reasonable_stack_size = 8 * MiB; // That's the default in Ubuntu?
|
||||
|
||||
__thread void* s_stack_location;
|
||||
__thread size_t s_stack_size;
|
||||
|
@ -467,7 +466,7 @@ int pthread_attr_setstacksize(pthread_attr_t* attributes, size_t stack_size)
|
|||
if (!attributes_impl)
|
||||
return EINVAL;
|
||||
|
||||
if ((stack_size < PTHREAD_STACK_MIN) || stack_size > highest_reasonable_stack_size)
|
||||
if (stack_size < PTHREAD_STACK_MIN || stack_size > PTHREAD_STACK_MAX)
|
||||
return EINVAL;
|
||||
|
||||
attributes_impl->stack_size = stack_size;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue