mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 09:17:45 +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
|
@ -487,7 +487,7 @@ typedef struct {
|
|||
|
||||
#define PT_GNU_EH_FRAME 0x6474e550 /* Exception handling info */
|
||||
#define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */
|
||||
#define PT_GNU_STACK 0x6474e551 /* Stack permissions info */
|
||||
#define PT_GNU_STACK 0x6474e551 /* Stack permissions & size info */
|
||||
|
||||
#define PT_OPENBSD_RANDOMIZE 0x65a3dbe6 /* fill with random data */
|
||||
#define PT_OPENBSD_WXNEEDED 0x65a3dbe7 /* program performs W^X violations */
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <Kernel/API/POSIX/sys/limits.h>
|
||||
#include <Kernel/API/serenity_limits.h>
|
||||
#include <bits/posix1_lim.h>
|
||||
#include <bits/stdint.h>
|
||||
#include <bits/wchar.h>
|
||||
|
@ -86,8 +87,6 @@
|
|||
|
||||
#define ARG_MAX 65536
|
||||
|
||||
#define PTHREAD_STACK_MIN 65536
|
||||
|
||||
#define SSIZE_MAX 2147483647
|
||||
|
||||
#define LINK_MAX 4096
|
||||
|
|
|
@ -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