On Thu, 2017-10-19 at 12:06 -0400, Zack Weinberg wrote:
> I can work around this by forcibly adjusting valgrind's state for the
> "data" object (compile with -DDO_MAKE_MEM_WRITABLE to see) but I
> would
> like to understand *why* this memory has become unwritable, why the
> STACK_REGISTER/DEREGISTER was insufficient, and whether there's a
> more
> appropriate work-around.

STACK_REGISTER (STACK_DEREGISTER) is just marking a piece
of memory as being a stack (not being a stack anymore).
This is a.o. used to help unwind logic, provide better description
of an address in error messages, etc ...

These do not change the Addressable or Validity-bits of the
 piece of memory.
So, after a piece of memory has been used as a stack,
depending on how much of this stack was used, the 'normal'
valgrind memcheck code has marked some memory unaccessible
Typically, when a function returns, the space that was used
by the frame of the returning function is marked as unaccessible.

When you deregister the stack, these V-bits/A-bits are not 
changed, and so part of this memory is now marked as not addressable.

IMO, before switching to a new stack, it would be better to
mark the stack as not addressable (maybe a small part of the
stack must be kept addressable, to just allow switching to this
stack).
Marking the stack as unaddressable would help memcheck to detect e.g.
a dereference to a 'not valid' part of the stack.

And when a stack is not used anymore, it might be needed
(like in your case) to mark the memory as addressable again.

So, I think that what you see is all normal :
STACK_REGISTER (STACK_DEREGISTER) are low level features,
they do not do the whole valgrind magic that might be needed
e.g. for your memset after usage.
And I think that your usage of VALGRIND_MAKE_MEM_UNDEFINED
is the correct thing to do.

Philippe



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to