Last active
December 23, 2015 17:59
-
-
Save submachine/6673118 to your computer and use it in GitHub Desktop.
Keep pushing till we run out of stack area.
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
#include <stdio.h> | |
#include <string.h> | |
unsigned int stack_size; | |
struct huge_argument /* Not the verbal kind ;). */ | |
{ | |
char x[512]; | |
}; | |
void | |
push (struct huge_argument arg, char * base) | |
{ | |
struct huge_argument local; | |
/* Read some stuff off the stack; | |
write some stuff on the stack. */ | |
memcpy (&local, &arg, sizeof (struct huge_argument)); | |
/* Kilobytes => /1024; | |
Stack may grow either way, depending on ABI. */ | |
if (base > (char *) &local) | |
stack_size = (base - (char *) &local) / 1024; | |
else | |
stack_size = ( (char *) &local - base) / 1024; | |
printf ("%u\n", stack_size); | |
push (local, base); | |
} | |
int | |
main (int argc, char ** argv) | |
{ | |
struct huge_argument arg; | |
/* Each call eats up a little more than a KB of stack. */ | |
push (arg, (char *) &arg); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment