save return address in powerpc.cpp's MyAssembler::saveFrame

We've been getting away with not doing this so far since our Java
calling convention matches the native calling convention concerning
where the return address is saved, so when our thunk calls native code
it gets saved for us automatically.  However, there was still the
danger that a thread would interrupt another thread after the stack
pointer was saved to the thread field but before the native code was
called and try to get a stack trace, at which point it would try to
find the return address relative to that stack pointer and find
garbage instead.  This commit ensures that we save the return address
before saving the stack pointer to avoid such a situation.
This commit is contained in:
Joel Dice 2010-09-02 17:28:20 -06:00
parent a4914daae4
commit e7a48c0fa2

View File

@ -2142,6 +2142,12 @@ class MyAssembler: public Assembler {
}
virtual void saveFrame(unsigned stackOffset, unsigned) {
Register returnAddress(0);
emit(&c, mflr(returnAddress.low));
Memory returnAddressDst(StackRegister, 8);
moveRM(&c, BytesPerWord, &returnAddress, BytesPerWord, &returnAddressDst);
Register stack(StackRegister);
Memory stackDst(ThreadRegister, stackOffset);
moveRM(&c, BytesPerWord, &stack, BytesPerWord, &stackDst);