Bug 921330: Fix sync unwind on Mac OS X. r=BenWa

This commit is contained in:
Aaron Klotz 2013-10-15 12:58:52 -06:00
parent f16d40ff3b
commit b776cfe9c9

View File

@ -412,32 +412,36 @@ void Sampler::UnregisterCurrentThread()
}
}
__attribute__((noinline)) static Address GetPC()
{
return reinterpret_cast<Address>(__builtin_return_address(0));
}
void TickSample::PopulateContext(void* aContext)
{
// Note that this asm changes if PopulateContext's parameter list is altered
#if defined(SPS_PLAT_amd64_darwin)
asm (
"movq %%rsp, %0\n\t"
"movq %%rbp, %1\n\t"
// Compute caller's %rsp by adding to %rbp:
// 8 bytes for previous %rbp, 8 bytes for return address
"leaq 0x10(%%rbp), %0\n\t"
// Dereference %rbp to get previous %rbp
"movq (%%rbp), %1\n\t"
:
"=g"(sp),
"=g"(fp)
"=r"(sp),
"=r"(fp)
);
#elif defined(SPS_PLAT_x86_darwin)
asm (
"movl %%esp, %0\n\t"
"movl %%ebp, %1\n\t"
// Compute caller's %esp by adding to %ebp:
// 4 bytes for aContext + 4 bytes for return address +
// 4 bytes for previous %ebp
"leal 0xc(%%ebp), %0\n\t"
// Dereference %ebp to get previous %ebp
"movl (%%ebp), %1\n\t"
:
"=g"(sp),
"=g"(fp)
"=r"(sp),
"=r"(fp)
);
#else
# error "Unsupported architecture"
#endif
pc = GetPC();
pc = reinterpret_cast<Address>(__builtin_extract_return_addr(
__builtin_return_address(0)));
}