Skip to content

Instantly share code, notes, and snippets.

@submachine
Last active December 23, 2015 17:59
Show Gist options
  • Save submachine/6673118 to your computer and use it in GitHub Desktop.
Save submachine/6673118 to your computer and use it in GitHub Desktop.
Keep pushing till we run out of stack area.
#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