Last active
September 10, 2024 12:44
-
-
Save msg555/5418199 to your computer and use it in GitHub Desktop.
Revisions
-
msg555 revised this gist
Apr 19, 2013 . 1 changed file with 14 additions and 11 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,20 +5,23 @@ #define STACK_PAD 128 int rec(int n) { return n == 0 ? 0 : rec(n - 1) + 1; } int main() { /* Allocate a new stack to use first. Because stacks grow to lower addresses * we want to use just a little before the end of the allocation. */ char* nstack = (char*)malloc(STACK_SIZE) + STACK_SIZE - STACK_PAD; /* Adjust the stack pointer to fall right in our newly allocated stack. * "char stack_hack[sz];" has the effect of subtracting sz from the stack * pointer. */ char stack_hack[(char*)&nstack - nstack]; /* Now we can recurse deeply. If you comment out the definition of stack_hack * then (on my system's limits, anyway) the second one will segfault. */ printf("%d\n", rec(100000)); printf("%d\n", rec(1000000)); return 1; } -
msg555 revised this gist
Apr 19, 2013 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,5 @@ #include <stdio.h> #include <stdlib.h> #define STACK_SIZE (1 << 26) #define STACK_PAD 128 @@ -19,7 +18,7 @@ void nmain() { int main() { char* nstack = (char*)malloc(STACK_SIZE) + STACK_SIZE - STACK_PAD; char lols[(char*)&nstack - nstack]; nmain(); return 1; } -
msg555 created this gist
Apr 19, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ #include <stdio.h> #include <stdlib.h> #include <alloca.h> #define STACK_SIZE (1 << 26) #define STACK_PAD 128 int rec(int n) { if(n == 0) return 0; int r = rec(n - 1); ++r; return r; } void nmain() { printf("%d\n", rec(1000000)); exit(0); } int main() { char* nstack = (char*)malloc(STACK_SIZE) + STACK_SIZE - STACK_PAD; alloca((char*)&nstack - nstack); nmain(); return 1; }