Created
June 5, 2009 23:35
-
-
Save nall/124575 to your computer and use it in GitHub Desktop.
x86 stack change code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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