X-Git-Url: https://git.saurik.com/apple/libpthread.git/blobdiff_plain/235d2f0e8fa84839307390481219c77389440e1b..c6e5f90c4dd303939f631da331df7b356da942e6:/tests/helpers/stackoverflow_crash.c?ds=inline diff --git a/tests/helpers/stackoverflow_crash.c b/tests/helpers/stackoverflow_crash.c new file mode 100644 index 0000000..2858033 --- /dev/null +++ b/tests/helpers/stackoverflow_crash.c @@ -0,0 +1,56 @@ +#include +#include + +static volatile int * array1_ref = NULL; +static long last_stack_addr = 0; + +static void +recursive_fn(void) +{ + volatile int array1[1024]; /* leave this as it is */ + int addr; + last_stack_addr = (long)&addr; + array1_ref = array1; /* make sure compiler cannot discard storage */ + array1[0] = 0; + if (array1_ref == 0) { + /* fool clang -Winfinite-recursion */ + return; + } + recursive_fn(); + return; +} + +int +main(__unused int argc, __unused const char *argv[]) +{ + struct rlimit save; + + if (getrlimit(RLIMIT_STACK, &save) == -1) { + printf("child: ERROR - getrlimit"); + return 2; + } + printf("child: LOG - current stack limits cur=0x%llx, max=0x%llx, inf=0x%llx\n", save.rlim_cur, save.rlim_max, RLIM_INFINITY); + + if(save.rlim_cur >= save.rlim_max) { + printf("child: ERROR - invalid limits"); + return 2; + } + + if(save.rlim_max == RLIM_INFINITY) { + printf("child: ERROR - rlim_max = RLIM_INFINITY"); + return 2; + } + + save.rlim_cur += 4; + + printf("child: LOG - Raising setrlimit rlim_cur=0x%llx, rlim_max=0x%llx\n", save.rlim_cur, save.rlim_max); + + if (setrlimit(RLIMIT_STACK, &save) == -1) { + printf("child: ERROR - Raising the limits failed."); + return 2; + } + + printf("child: LOG - Make the stack grow such that a SIGSEGV is generated.\n"); + recursive_fn(); + return 0; +}