|
From: Avery P. <ape...@ni...> - 2003-11-02 20:20:41
|
On Sat, Nov 01, 2003 at 12:33:51PM +0000, Nicholas Nethercote wrote:
> Where did you insert the VALGRIND_MAKE_READABLE call? I'm pretty sure
> that macro will work on the stack. If I've understood your technique, I
> think you want to do this:
>
> remember esp
> alloc big new chunk on the stack
> restore esp
> call VALGRIND_MAKE_READABLE on the new chunk
>
> The critical thing being that you call the macro after you restore %esp.
Okay, so whatever I was doing before was definitely wrong, because I
followed this advice and stopped getting spurious valgrind errors. Yay!
Now, I think this disables a certain amount of valgrind checking. That is:
int x;
if (!setjmp)
longjmp(elsewhere)
// else someone longjmped back to me
VALGRIND_MAKE_READABLE(blah blah)
printf("x is now %d\n", x);
In this example, valgrind won't be able to discover that x was
uninitialized, since the memory was already marked readable to compensate
for it spuriously being marked *unreadable* earlier.
This actually doesn't bother me too much, because I expect to have rather
few errors with this problem: usually the function runs quite far before
doing the setjmp/longjmp, so 99% of the time it will have initialized the
variables by then anyway. Also, any functions I call from inside this one
will have valgrind do the right thing.
The inaccuracy, however, lies in throwing away data and then trying to
reconstruct it inaccurately.
Since I have total control over the setjmp/longjmp calls, would it be
possible to add a feature to valgrind like
if (!setjmp)
VALGRIND_STOP_INVALIDATING
longjmp(elsewhere)
// else someone longjmped back to me
VALGRIND_START_INVALIDATING
printf("x is now %d\n", x);
It would then need to be sure to invalidate only the areas between the old
and new stack pointer whenever %sp is changed (the normal way) rather than
blindly invalidating "everything under the current stack pointer."
This is pretty low priority, however. Thanks to your original message my
unit tests finally run under valgrind and I fixed two bugs last night thanks
to that.
Have fun,
Avery
P.S. Jeremy: I know the amount of stack usage by the kernel, signals, etc is
"undefined", but if you make the sub-stack big enough, all is mostly well.
sigaltstack() is probably a good idea though, you're right.
|