Skip to content

Instantly share code, notes, and snippets.

@nall
Created June 5, 2009 23:35
Show Gist options
  • Save nall/124575 to your computer and use it in GitHub Desktop.
Save nall/124575 to your computer and use it in GitHub Desktop.
x86 stack change code
// Program to demonstrate how to change to a new stack section on x86
#include <stdlib.h>
#include <stdio.h>
#define ALTSTACK
void* altStack = 0;
void core()
{
char dummy;
printf("in core! [dummy = %p]\n", &dummy);
}
void test()
{
#ifdef ALTSTACK
// Setup the alternate stack and call core
void* oldStack = 0;
__asm__("movl %%esp, %[oldstack]\n\
movl %[altstack], %%esp"
: [oldstack] "=m" (oldStack)
: [altstack] "m" (altStack));
#endif
core();
#ifdef ALTSTACK
__asm__("movl %[oldstack], %%esp"
: /* no outputs */
: [oldstack] "m" (oldStack));
#endif
}
int main(int argc, char** argv)
{
altStack = malloc(1024000);
printf("altStack = %p\n", altStack);
test();
free(altStack);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment