From e7a48c0fa2832b1f45933a140742e9b0c282ec9b Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 2 Sep 2010 17:28:20 -0600 Subject: [PATCH] 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. --- src/powerpc.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/powerpc.cpp b/src/powerpc.cpp index fbbfb64e38..eb1d5ef33b 100644 --- a/src/powerpc.cpp +++ b/src/powerpc.cpp @@ -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);