Created
November 20, 2013 03:45
-
-
Save Preetam/7557364 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
OUTPUT: | |
x: 0x9cb010 | |
a: 0x7fff40fe88e0 | |
0x7fff40fe88e0 | |
Current stack pointer address: 0x7fff40fe88e0 with value 0x17e | |
Current stack pointer address: 0x7fff40fe88e1 with value 0x1000000001000001 | |
Current stack pointer address: 0x7fff40fe88e2 with value 0xb010000000020000 | |
Current stack pointer address: 0x7fff40fe88e3 with value 0x9cb0100000000300 | |
Current stack pointer address: 0x7fff40fe88e4 with value 0x9cb01000000004 | |
Current stack pointer address: 0x7fff40fe88e5 with value 0x9cb010000000 | |
Current stack pointer address: 0x7fff40fe88e6 with value 0x9cb0100000 | |
Current stack pointer address: 0x7fff40fe88e7 with value 0x9cb01000 | |
Current stack pointer address: 0x7fff40fe88e8 with value 0x9cb010 | |
Found it at 8! | |
*/ | |
#include <stdlib.h> | |
#include <stdio.h> | |
void* gc_malloc(int size){ | |
return malloc(size); | |
} | |
int main() { | |
register void* stack asm("esp"); | |
int* x = gc_malloc(1); | |
if (x == NULL) { | |
return 1; | |
} | |
int a = 382; | |
printf("x: %p\n", x); | |
printf("a: %p\n", &a); | |
printf("%p\n", stack); | |
int i; | |
for(i = 0; i < 8192; i++) { | |
printf("Current stack pointer address: %p with value %p\n", (stack+i), *(void**)(stack+i)); | |
if((stack+i) == &x) { | |
printf("Found it at %d!\n", i); | |
break; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment