buggy stack --- #include "malloc.h" void ctx_start(void** old_sp, void* new_sp); void ctx_switch(void** old_sp, void* new_sp); #define FRAME 0x30 void foo(int i) { int stack = 0; printf("[%d] stack addr: %p\n", i, &stack); if (FRAME * i >= 2048) { printf("DONE\n"); return; } else foo(i+1); } void ctx_entry(void){ foo(0); FATAL("die"); } int main(int args, char **argv) { void * old_sp; void *new_sp = malloc(4096); // <--- BUG printf("new_sp: %p\n", new_sp); ctx_start(&old_sp, new_sp); }