|
From: Nicholas N. <nj...@ca...> - 2004-05-04 09:07:45
|
On Mon, 3 May 2004, Henrik Nordstrom wrote: > > How Valgrind can be used to detect that a thread is > > accessing the stack of another thread? > > Not sure how practical this is, but it sounds like a good move provided it > is optional. Tere is however situations where two threads may want to > share local data on the stack so it can not be on by default. > > You should also be able to use a redzone on the stack of the crashing > thread and hopefully catch the corruption this way. Adding a redzone > should be as simple as declaring a local array and then tell valgrind that > this area is inaccessible (VALGRIND_MAKE_NOACCESS). But I am a little > uncertain on how valgrind manages thread stacks. I know there is some > magics for the normal stack, but not sure if this also applies to thread > stacks or if this magics have any implications on manual instrumentation. This is a difficult problem to detect, and Valgrind (Memcheck and/or Addrcheck) probably aren't going to be able to help you. They track each memory byte with a single bit that indicates the byte is "addressable" or "not addressable". There's no notion of ownership, or way of saying "this memory is addressable by thread A, but should be left alone by thread B". If thread A is writing into the middle of thread B's stack, that won't be detected, unfortunately. As for the redzone suggestion, I think Memcheck/Addrcheck already put redzones at the end of thread stacks, so any overruns of that sort should be caught... I could be wrong about that, though. N |