Description
Currently standard call (simplified: no params) looks more or less like this in the assembly code:
Subroutine/Function:
push ebp ; save current stack base on the stack
mov ebp, esp ; make current stack position a stack base
;; code here
pop ebp ; restore previous stack base
ret ; pop caller's address from the stack and jump there
Function call:
call address ; push next's instruction address to stack and jump to address
Currently by default we support stack of only 1MB size and there is no way of dynamically controlling the size.
My proposition is to allow local dynamic stack growing (without need to create a new thread).
How would that work - simplest example (+ some syntax sugar on top of that):
magic_call_explained_below void call_with_different_stack(void* stackEndAddress, Action a)
{
a();
}
In this context a's code would have a completely new stack
calling a() would need to look something like this (let's assume stackEndAddress is at ebp+12, and function to call address at ebp+8) (sudo-asm):
push ebp ; save current stack base at old stack
mov ([ebp+12] - 4), [ebp+8] ; save function address at new stack
mov ([ebp+12] - 8), esp ; save current stack pointer at new stack
mov ebp, ([ebp+12] - 8) ; make provided stack a new stack base (- 8 as old esp and function pointer are params)
mov esp, ebp ; switch stack
// this will be executed within context of the new stack
call [ebp + 4] ; call function
pop esp ; come back to previous stack
pop ebp ; restore stack base
This way you can fake resize stack dynamically within a certain context (so only when this is needed - i.e. you want to do some really complex graph analysis but you don't always want to pay cost for that). Of course some stack overflow protection would need to be added etc. etc.
category:proposal
theme:runtime
skill-level:expert
cost:extra-large
impact:small