Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposition: Stack bending #4654

Open
krwq opened this issue Nov 8, 2015 · 0 comments
Open

Proposition: Stack bending #4654

krwq opened this issue Nov 8, 2015 · 0 comments
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI enhancement Product code improvement that does NOT require public API changes/additions hard-problem
Milestone

Comments

@krwq
Copy link
Member

krwq commented Nov 8, 2015

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

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 30, 2020
@msftgits msftgits added this to the Future milestone Jan 30, 2020
@BruceForstall BruceForstall added the JitUntriaged CLR JIT issues needing additional triage label Oct 28, 2020
@BruceForstall BruceForstall removed the JitUntriaged CLR JIT issues needing additional triage label Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI enhancement Product code improvement that does NOT require public API changes/additions hard-problem
Projects
None yet
Development

No branches or pull requests

4 participants