|
From: Julian S. <js...@ac...> - 2006-01-21 02:47:18
|
On Wednesday 18 January 2006 15:19, Josef Weidendorfer wrote:
> On Wednesday 18 January 2006 06:24, Julian Seward wrote:
> > to the post-actions since both are in the same function. Recursion and
> > I think longjmping still work (perhaps not on ppc64).
>
> Longjumping will skip the frame of the wrapper function, too.
> So post-actions are not called.
>
> I am not sure this is a problem in practice.
For x86/amd64/ppc32, function wrapping is simple, conceptually:
when a wrapped/redirected function is called, V runs instead the
replacement function, and at that instant also it writes into a
pseudo-register (guest_NRADDR) the address of the un-redirected
function ("NRADDR" == Non-Redirected Address). The wrapper
function can get hold of this address and call it to get to the
original.
So function wrapping only requires magic at entry to the wrapper,
not at exit. This means longjumping and recursion work right.
On ppc64-linux it is not so simple. For each function, %r2 must
point to a constant pool ("table of contents") which is specific to
that function, or at least to that shared object.
Therefore, when diverting to the wrapper, valgrind must reload
r2 with a new value which is correct for the wrapper*. When the
wrapper returns it must restore r2 to what it was before. This
means that V has to keep a shadow stack of (pc,r2) pairs, one
for each nested wrapper which is active, and carefully save and
restore r2 values. This means if there is a longjmp in a wrapper
it will go wrong, because this stack will be out of sync.
J
* even the problem of figuring out the correct r2 for a given
function is not simple, requires some rather fragile extensions
to the symbol table reader
|