Skip to content

Commit

Permalink
Tell Valgrind about our ULT stacks so it doesn't get confused
Browse files Browse the repository at this point in the history
This avoids reporting false-positive errors like the following:

==25331== Warning: client switching stacks?  SP change: 0xfff000508 --> 0x5a30a18
==25331==          to suppress, use: --max-stackframe=68608129776 or greater
==25331==
==25331== Invalid read of size 8
==25331==    at 0x569E4AC: swapcontext (swapcontext.S:93)
==25331==    by 0x56A07FF: ??? (in /lib/x86_64-linux-gnu/libc-2.19.so)
==25331==  Address 0x5a30bd0 is 256 bytes inside a block of size 1,064 alloc'd
==25331==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==25331==    by 0x5E80E4: CthCreateInner (libthreads-default.c:1714)
==25331==    by 0x5E828F: CthCreate (libthreads-default.c:1780)
==25331==    by 0x5E8E7C: ConverseInit (machine.c:331)
==25331==    by 0x51D9DD: main (main.C:18)

The Valgrind documentation explicitly recommends copying the header
included here into the client source tree, to avoid an external
dependency. The license is specifically geared to support this.

Change-Id: I26004af3edb7ac47931b80e78930c92857e31f67
  • Loading branch information
PhilMiller authored and stwhite91 committed Aug 29, 2017
1 parent 54b77a7 commit bdf92bc
Show file tree
Hide file tree
Showing 2 changed files with 7,134 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/conv-core/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@
#include "conv-trace.h"
#include <sys/types.h>

#include "valgrind.h"

#ifndef CMK_STACKSIZE_DEFAULT
#define CMK_STACKSIZE_DEFAULT 32768
#endif
Expand Down Expand Up @@ -167,6 +169,8 @@
int stacksize; /*Size of thread stack (bytes)*/
struct CthThreadListener *listener; /* pointer to the first of the listeners */

unsigned int valgrindStackID;

#if CMK_THREADS_BUILD_TLS
tlsseg_t tlsseg;
#endif
Expand Down Expand Up @@ -433,6 +437,9 @@ static void *CthAllocateStack(CthThreadBase *th,int *stackSize,int useMigratable
}
_MEMCHECK(ret);
th->stack=ret;

th->valgrindStackID = VALGRIND_STACK_REGISTER(ret, ret + *stackSize);

return ret;
}
static void CthThreadBaseFree(CthThreadBase *th)
Expand Down Expand Up @@ -468,6 +475,7 @@ static void CthThreadBaseFree(CthThreadBase *th)
else if (th->stack!=NULL) {
free(th->stack);
}
VALGRIND_STACK_DEREGISTER(th->valgrindStackID);
th->stack=NULL;
}

Expand Down

0 comments on commit bdf92bc

Please sign in to comment.