diff --git a/ctaocrypt/src/asn.c b/ctaocrypt/src/asn.c index 99e28e539..3c348de7c 100644 --- a/ctaocrypt/src/asn.c +++ b/ctaocrypt/src/asn.c @@ -137,6 +137,13 @@ #define XGMTIME(c) gmtime((c)) #define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t)) + #ifdef STACK_TRAP + /* for stack trap tracking, don't call os gmtime on OS X/linux, + uses a lot of stack spce */ + extern time_t time(time_t * timer); + #define XTIME(tl) time((tl)) + #endif /* STACK_TRAP */ + #else /* default */ /* uses complete facility */ diff --git a/cyassl/test.h b/cyassl/test.h index 641826a0e..f7259d092 100644 --- a/cyassl/test.h +++ b/cyassl/test.h @@ -1239,6 +1239,42 @@ static INLINE void StackSizeCheck(func_args* args, thread_func tf) #endif /* HAVE_STACK_SIZE */ + +#ifdef STACK_TRAP + +/* good settings + --enable-debug --disable-shared C_EXTRA_FLAGS="-DUSER_TIME -DTFM_TIMING_RESISTANT -DPOSITIVE_EXP_ONLY -DSTACK_TRAP" + +*/ + +#ifdef HAVE_STACK_SIZE + /* client only for now, setrlimit will fail if pthread_create() called */ + /* STACK_SIZE does pthread_create() on client */ + #error "can't use STACK_TRAP with STACK_SIZE, setrlimit will fail" +#endif /* HAVE_STACK_SIZE */ + +static INLINE void StackTrap(void) +{ + struct rlimit rl; + if (getrlimit(RLIMIT_STACK, &rl) != 0) + err_sys("getrlimit failed"); + printf("rlim_cur = %llu\n", rl.rlim_cur); + rl.rlim_cur = 1024*21; /* adjust trap size here */ + if (setrlimit(RLIMIT_STACK, &rl) != 0) { + perror("setrlimit"); + err_sys("setrlimit failed"); + } +} + +#else /* STACK_TRAP */ + +static INLINE void StackTrap(void) +{ +} + +#endif /* STACK_TRAP */ + + #if defined(__hpux__) || defined(__MINGW32__) /* HP/UX doesn't have strsep, needed by test/suites.c */ diff --git a/examples/client/client.c b/examples/client/client.c index 78c63ba1c..200d05f74 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -201,6 +201,8 @@ THREAD_RETURN CYASSL_THREAD client_test(void* args) (void)sslResume; (void)trackMemory; + StackTrap(); + while ((ch = mygetopt(argc, argv, "?gdusmNrtfxh:p:v:l:A:c:k:b:zS:")) != -1){ switch (ch) { case '?' : @@ -693,7 +695,7 @@ THREAD_RETURN CYASSL_THREAD client_test(void* args) args.argv = argv; CyaSSL_Init(); -#if defined(DEBUG_CYASSL) && !defined(CYASSL_MDK_SHELL) +#if defined(DEBUG_CYASSL) && !defined(CYASSL_MDK_SHELL) && !defined(STACK_TRAP) CyaSSL_Debugging_ON(); #endif if (CurrentDir("client") || CurrentDir("build"))