As hinted from my title, I am interested if it would be possible to allocate a C array, and make it behave like a stack by pointing ESP register to it accordingly.
Some code example...
void foo(){ int x = 99; int y = 89; return;}char myStack[1024];void main(){ int main_num = 66; __asm volatile("movl %0, %%esp": : "rm" (&myStack+1)); //Move ESP to the end of the array foo(); return 0;}
The idea behind this code would be to create sort of a separate stack, specifically for foo() by first pointing ESP to the end of myStack array (since stack would grow towards the lower addresses) and then have foo() called, have its return address and local variables now stored on this new stack (our C array).
I am wondering is such approach even possible? And if so how to achieve it?
While trying to implement above code I ran GDB just to see some info about my stack (ex: info stack command in GDB), I kept getting "No Stack" which probably means stack pointer was sent into abyss.
PS: I am implementing this as a kernel-level code