add STACK_TRAP to track stack use on client, will seqfault if exceed limit to see where use is too high, doesn't work with pthread_create()

This commit is contained in:
toddouska 2013-06-03 14:56:37 -07:00
parent baa012b1d9
commit ae84982777
3 changed files with 46 additions and 1 deletions

View File

@ -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 <time.h> facility */

View File

@ -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 */

View File

@ -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"))