From e9343344d9bd268a05d1eae1ce80a3278ec19c89 Mon Sep 17 00:00:00 2001 From: Dave Allison Date: Thu, 10 Jul 2014 15:29:28 -0700 Subject: [PATCH] Fix mac build Fixes x86 fault handler, sigchain and quick_entrypoints for x86_64. Bug: 16215218 Change-Id: I5e58660ea815042968444e6352c57a5f53314cfd --- runtime/arch/x86/fault_handler_x86.cc | 40 +++++++++++++++----------- runtime/arch/x86_64/quick_entrypoints_x86_64.S | 4 +-- sigchainlib/Android.mk | 2 ++ sigchainlib/sigchain.cc | 4 +++ 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/runtime/arch/x86/fault_handler_x86.cc b/runtime/arch/x86/fault_handler_x86.cc index f62200aab..435f280a6 100644 --- a/runtime/arch/x86/fault_handler_x86.cc +++ b/runtime/arch/x86/fault_handler_x86.cc @@ -26,6 +26,16 @@ #include "thread.h" #include "thread-inl.h" +#if defined(__APPLE__) +#define ucontext __darwin_ucontext +#define CTX_ESP uc_mcontext->__ss.__esp +#define CTX_EIP uc_mcontext->__ss.__eip +#define CTX_EAX uc_mcontext->__ss.__eax +#else +#define CTX_ESP uc_mcontext.gregs[REG_ESP] +#define CTX_EIP uc_mcontext.gregs[REG_EIP] +#define CTX_EAX uc_mcontext.gregs[REG_EAX] +#endif // // X86 specific fault handler functions. @@ -163,7 +173,7 @@ void FaultManager::GetMethodAndReturnPCAndSP(siginfo_t* siginfo, void* context, mirror::ArtMethod** out_method, uintptr_t* out_return_pc, uintptr_t* out_sp) { struct ucontext* uc = reinterpret_cast(context); - *out_sp = static_cast(uc->uc_mcontext.gregs[REG_ESP]); + *out_sp = static_cast(uc->CTX_ESP); VLOG(signals) << "sp: " << std::hex << *out_sp; if (*out_sp == 0) { return; @@ -175,13 +185,13 @@ void FaultManager::GetMethodAndReturnPCAndSP(siginfo_t* siginfo, void* context, uintptr_t* overflow_addr = reinterpret_cast( reinterpret_cast(*out_sp) - GetStackOverflowReservedBytes(kX86)); if (overflow_addr == fault_addr) { - *out_method = reinterpret_cast(uc->uc_mcontext.gregs[REG_EAX]); + *out_method = reinterpret_cast(uc->CTX_EAX); } else { // The method is at the top of the stack. *out_method = reinterpret_cast(reinterpret_cast(*out_sp)[0]); } - uint8_t* pc = reinterpret_cast(uc->uc_mcontext.gregs[REG_EIP]); + uint8_t* pc = reinterpret_cast(uc->CTX_EIP); VLOG(signals) << HexDump(pc, 32, true, "PC "); uint32_t instr_size = GetInstructionSize(pc); @@ -190,8 +200,8 @@ void FaultManager::GetMethodAndReturnPCAndSP(siginfo_t* siginfo, void* context, bool NullPointerHandler::Action(int sig, siginfo_t* info, void* context) { struct ucontext *uc = reinterpret_cast(context); - uint8_t* pc = reinterpret_cast(uc->uc_mcontext.gregs[REG_EIP]); - uint8_t* sp = reinterpret_cast(uc->uc_mcontext.gregs[REG_ESP]); + uint8_t* pc = reinterpret_cast(uc->CTX_EIP); + uint8_t* sp = reinterpret_cast(uc->CTX_ESP); uint32_t instr_size = GetInstructionSize(pc); // We need to arrange for the signal handler to return to the null pointer @@ -203,10 +213,9 @@ bool NullPointerHandler::Action(int sig, siginfo_t* info, void* context) { uint32_t retaddr = reinterpret_cast(pc + instr_size); uint32_t* next_sp = reinterpret_cast(sp - 4); *next_sp = retaddr; - uc->uc_mcontext.gregs[REG_ESP] = reinterpret_cast(next_sp); + uc->CTX_ESP = reinterpret_cast(next_sp); - uc->uc_mcontext.gregs[REG_EIP] = - reinterpret_cast(art_quick_throw_null_pointer_exception); + uc->CTX_EIP = reinterpret_cast(art_quick_throw_null_pointer_exception); VLOG(signals) << "Generating null pointer exception"; return true; } @@ -230,8 +239,8 @@ bool SuspensionHandler::Action(int sig, siginfo_t* info, void* context) { uint8_t checkinst2[] = {0x85, 0x00}; struct ucontext *uc = reinterpret_cast(context); - uint8_t* pc = reinterpret_cast(uc->uc_mcontext.gregs[REG_EIP]); - uint8_t* sp = reinterpret_cast(uc->uc_mcontext.gregs[REG_ESP]); + uint8_t* pc = reinterpret_cast(uc->CTX_EIP); + uint8_t* sp = reinterpret_cast(uc->CTX_ESP); if (pc[0] != checkinst2[0] || pc[1] != checkinst2[1]) { // Second instruction is not correct (test eax,[eax]). @@ -264,9 +273,9 @@ bool SuspensionHandler::Action(int sig, siginfo_t* info, void* context) { uint32_t retaddr = reinterpret_cast(pc + 2); uint32_t* next_sp = reinterpret_cast(sp - 4); *next_sp = retaddr; - uc->uc_mcontext.gregs[REG_ESP] = reinterpret_cast(next_sp); + uc->CTX_ESP = reinterpret_cast(next_sp); - uc->uc_mcontext.gregs[REG_EIP] = reinterpret_cast(art_quick_test_suspend); + uc->CTX_EIP = reinterpret_cast(art_quick_test_suspend); // Now remove the suspend trigger that caused this fault. Thread::Current()->RemoveSuspendTrigger(); @@ -286,7 +295,7 @@ bool SuspensionHandler::Action(int sig, siginfo_t* info, void* context) { bool StackOverflowHandler::Action(int sig, siginfo_t* info, void* context) { struct ucontext *uc = reinterpret_cast(context); - uintptr_t sp = static_cast(uc->uc_mcontext.gregs[REG_ESP]); + uintptr_t sp = static_cast(uc->CTX_ESP); uintptr_t fault_addr = reinterpret_cast(info->si_addr); VLOG(signals) << "fault_addr: " << std::hex << fault_addr; @@ -315,11 +324,10 @@ bool StackOverflowHandler::Action(int sig, siginfo_t* info, void* context) { // the previous frame. // Tell the stack overflow code where the new stack pointer should be. - uc->uc_mcontext.gregs[REG_EAX] = pregion; + uc->CTX_EAX = pregion; // Now arrange for the signal handler to return to art_quick_throw_stack_overflow_from_signal. - uc->uc_mcontext.gregs[REG_EIP] = reinterpret_cast( - art_quick_throw_stack_overflow_from_signal); + uc->CTX_EIP = reinterpret_cast(art_quick_throw_stack_overflow_from_signal); return true; } diff --git a/runtime/arch/x86_64/quick_entrypoints_x86_64.S b/runtime/arch/x86_64/quick_entrypoints_x86_64.S index 7f7226c0a..885fbfde5 100644 --- a/runtime/arch/x86_64/quick_entrypoints_x86_64.S +++ b/runtime/arch/x86_64/quick_entrypoints_x86_64.S @@ -18,7 +18,7 @@ MACRO0(SETUP_FP_CALLEE_SAVE_FRAME) // Create space for ART FP callee-saved registers - subq LITERAL(4 * 8), %rsp + subq MACRO_LITERAL(4 * 8), %rsp CFI_ADJUST_CFA_OFFSET(4 * 8) movq %xmm12, 0(%rsp) movq %xmm13, 8(%rsp) @@ -32,7 +32,7 @@ MACRO0(RESTORE_FP_CALLEE_SAVE_FRAME) movq 8(%rsp), %xmm13 movq 16(%rsp), %xmm14 movq 24(%rsp), %xmm15 - addq LITERAL(4 * 8), %rsp + addq MACRO_LITERAL(4 * 8), %rsp CFI_ADJUST_CFA_OFFSET(- 4 * 8) END_MACRO diff --git a/sigchainlib/Android.mk b/sigchainlib/Android.mk index 20c8cacf3..d86735d12 100644 --- a/sigchainlib/Android.mk +++ b/sigchainlib/Android.mk @@ -23,6 +23,7 @@ LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION) LOCAL_MODULE_TAGS := optional LOCAL_CFLAGS += $(ART_TARGET_CFLAGS) LOCAL_SRC_FILES := sigchain.cc +LOCAL_CLANG = $(ART_TARGET_CLANG) LOCAL_MODULE:= libsigchain LOCAL_SHARED_LIBRARIES := liblog libdl LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk @@ -35,6 +36,7 @@ LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION) LOCAL_MODULE_TAGS := optional LOCAL_IS_HOST_MODULE := true LOCAL_CFLAGS += $(ART_HOST_CFLAGS) +LOCAL_CLANG = $(ART_HOST_CLANG) LOCAL_SRC_FILES := sigchain.cc LOCAL_MODULE:= libsigchain LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk diff --git a/sigchainlib/sigchain.cc b/sigchainlib/sigchain.cc index 458ad6958..6f9308383 100644 --- a/sigchainlib/sigchain.cc +++ b/sigchainlib/sigchain.cc @@ -26,6 +26,10 @@ #include #include +#if defined(__APPLE__) +#define _NSIG NSIG +#endif + namespace art { class SignalAction { -- 2.11.0