base: reduce size of initial stack from 32K to 4K

The initial stack is solely used to initialize the Genode environment
along with the application stack located in the stack area. It never
executes application code. Hence, we can make it small. To check that it
is not dimensioned too small, the patch introduces a sanity check right
before switching to the application stack.
This commit is contained in:
Norman Feske
2016-12-02 11:56:06 +01:00
parent 92460cdab7
commit 28f5688dcf
7 changed files with 44 additions and 12 deletions

View File

@ -40,6 +40,12 @@ enum { MAIN_THREAD_STACK_SIZE = 16UL * 1024 * sizeof(Genode::addr_t) };
extern "C" void init_rtld() __attribute__((weak));
void init_rtld() { }
/**
* Lower bound of the stack, solely used for sanity checking
*/
extern unsigned char __initial_stack_base[];
/**
* The first thread in a program
*/
@ -101,8 +107,24 @@ extern "C" void init_main_thread()
* The new stack pointer enables the caller to switch from its current
* environment to the those that the thread object provides.
*/
addr_t sp = reinterpret_cast<addr_t>(main_thread()->stack_top());
addr_t const sp = reinterpret_cast<addr_t>(main_thread()->stack_top());
init_main_thread_result = sp;
/*
* Sanity check for the usage of the initial stack
*
* Because the initial stack is located in the BSS, it is zero-initialized.
* We check that the stack still contains zeros at its lower boundary after
* executing all the initialization code.
*/
enum { STACK_PAD = 256U };
for (unsigned i = 0; i < STACK_PAD; i++) {
if (__initial_stack_base[i] == 0)
continue;
error("initial stack overflow detected");
for (;;);
}
}

View File

@ -57,7 +57,9 @@
/* stack of the temporary initial environment */
.p2align 4
.space 32 * 1024
.global __initial_stack_base
__initial_stack_base:
.space 4*1024
_stack_high:
/* initial value of the SP register */

View File

@ -90,7 +90,9 @@
/* stack of the temporary initial environment */
.p2align 4
.space 32 * 1024
.global __initial_stack_base
__initial_stack_base:
.space 4*1024
_stack_high:
/* initial value of the ESP, EAX and EDI register */

View File

@ -89,16 +89,18 @@
/* stack of the temporary initial environment */
.p2align 8
.space 32 * 1024
.global __initial_stack_base
__initial_stack_base:
.space 8*1024
_stack_high:
/* initial value of the RSP, RAX and RDI register */
.globl __initial_sp
.global __initial_sp
__initial_sp:
.space 8
.globl __initial_ax
.global __initial_ax
__initial_ax:
.space 8
.globl __initial_di
.global __initial_di
__initial_di:
.space 8