From 8a4d7eb6c238cab63e1587ca37f9ed70fdc09863 Mon Sep 17 00:00:00 2001 From: Android Tools Maintainers Date: Thu, 13 Dec 2018 09:11:09 +0000 Subject: [PATCH] Use `ucontext_t` instead of `ucontext` Both Bionic and glibc define a struct called `ucontext_t` but only Bionic defines an alias `ucontext_t`. Let's use the more standardized one. Gbp-Pq: Name ucontext.patch --- runtime/arch/arm/fault_handler_arm.cc | 8 ++++---- runtime/arch/arm/instruction_set_features_arm.cc | 5 +++-- runtime/arch/arm64/fault_handler_arm64.cc | 8 ++++---- runtime/arch/mips/fault_handler_mips.cc | 6 +++--- runtime/arch/mips64/fault_handler_mips64.cc | 6 +++--- runtime/arch/x86/fault_handler_x86.cc | 8 ++++---- runtime/native_stack_dump.cc | 3 ++- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/runtime/arch/arm/fault_handler_arm.cc b/runtime/arch/arm/fault_handler_arm.cc index b4bca01..9901679 100644 --- a/runtime/arch/arm/fault_handler_arm.cc +++ b/runtime/arch/arm/fault_handler_arm.cc @@ -48,7 +48,7 @@ static uint32_t GetInstructionSize(uint8_t* pc) { void FaultManager::GetMethodAndReturnPcAndSp(siginfo_t* siginfo ATTRIBUTE_UNUSED, void* context, ArtMethod** out_method, uintptr_t* out_return_pc, uintptr_t* out_sp) { - struct ucontext* uc = reinterpret_cast(context); + struct ucontext_t* uc = reinterpret_cast(context); struct sigcontext *sc = reinterpret_cast(&uc->uc_mcontext); *out_sp = static_cast(sc->arm_sp); VLOG(signals) << "sp: " << std::hex << *out_sp; @@ -99,7 +99,7 @@ bool NullPointerHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info, void* // register in order to find the mapping. // Need to work out the size of the instruction that caused the exception. - struct ucontext *uc = reinterpret_cast(context); + struct ucontext_t *uc = reinterpret_cast(context); struct sigcontext *sc = reinterpret_cast(&uc->uc_mcontext); uint8_t* ptr = reinterpret_cast(sc->arm_pc); uint32_t instr_size = GetInstructionSize(ptr); @@ -132,7 +132,7 @@ bool SuspensionHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info ATTRIBU + Thread::ThreadSuspendTriggerOffset().Int32Value(); uint16_t checkinst2 = 0x6800; - struct ucontext* uc = reinterpret_cast(context); + struct ucontext_t* uc = reinterpret_cast(context); struct sigcontext *sc = reinterpret_cast(&uc->uc_mcontext); uint8_t* ptr2 = reinterpret_cast(sc->arm_pc); uint8_t* ptr1 = ptr2 - 4; @@ -197,7 +197,7 @@ bool SuspensionHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info ATTRIBU bool StackOverflowHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info ATTRIBUTE_UNUSED, void* context) { - struct ucontext* uc = reinterpret_cast(context); + struct ucontext_t* uc = reinterpret_cast(context); struct sigcontext *sc = reinterpret_cast(&uc->uc_mcontext); VLOG(signals) << "stack overflow handler with sp at " << std::hex << &uc; VLOG(signals) << "sigcontext: " << std::hex << sc; diff --git a/runtime/arch/arm/instruction_set_features_arm.cc b/runtime/arch/arm/instruction_set_features_arm.cc index 8384460..9b6213c 100644 --- a/runtime/arch/arm/instruction_set_features_arm.cc +++ b/runtime/arch/arm/instruction_set_features_arm.cc @@ -220,8 +220,9 @@ static void bad_instr_handle(int signo ATTRIBUTE_UNUSED, siginfo_t* si ATTRIBUTE_UNUSED, void* data) { #if defined(__arm__) - struct ucontext *uc = (struct ucontext *)data; - struct sigcontext *sc = &uc->uc_mcontext; + struct ucontext_t *uc = (struct ucontext_t *)data; + // See the starting chunk of `FaultManager::GetMethodAndReturnPcAndSp()` in `fault_handler_arm.cc` + struct sigcontext *sc = reinterpret_cast(&uc->uc_mcontext); sc->arm_r0 = 0; // Set R0 to #0 to signal error. sc->arm_pc += 4; // Skip offending instruction. #else diff --git a/runtime/arch/arm64/fault_handler_arm64.cc b/runtime/arch/arm64/fault_handler_arm64.cc index 0ead732..a810cf2 100644 --- a/runtime/arch/arm64/fault_handler_arm64.cc +++ b/runtime/arch/arm64/fault_handler_arm64.cc @@ -41,7 +41,7 @@ namespace art { void FaultManager::GetMethodAndReturnPcAndSp(siginfo_t* siginfo ATTRIBUTE_UNUSED, void* context, ArtMethod** out_method, uintptr_t* out_return_pc, uintptr_t* out_sp) { - struct ucontext *uc = reinterpret_cast(context); + struct ucontext_t *uc = reinterpret_cast(context); struct sigcontext *sc = reinterpret_cast(&uc->uc_mcontext); *out_sp = static_cast(sc->sp); VLOG(signals) << "sp: " << *out_sp; @@ -77,7 +77,7 @@ bool NullPointerHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info, void* // PC at the point of call. For Null checks we insert a GC map that is immediately after // the load/store instruction that might cause the fault. - struct ucontext *uc = reinterpret_cast(context); + struct ucontext_t *uc = reinterpret_cast(context); struct sigcontext *sc = reinterpret_cast(&uc->uc_mcontext); // Push the gc map location to the stack and pass the fault address in LR. @@ -106,7 +106,7 @@ bool SuspensionHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info ATTRIBU (Thread::ThreadSuspendTriggerOffset().Int32Value() << 7); uint32_t checkinst2 = 0xf9400000; - struct ucontext *uc = reinterpret_cast(context); + struct ucontext_t *uc = reinterpret_cast(context); struct sigcontext *sc = reinterpret_cast(&uc->uc_mcontext); uint8_t* ptr2 = reinterpret_cast(sc->pc); uint8_t* ptr1 = ptr2 - 4; @@ -152,7 +152,7 @@ bool SuspensionHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info ATTRIBU bool StackOverflowHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info ATTRIBUTE_UNUSED, void* context) { - struct ucontext *uc = reinterpret_cast(context); + struct ucontext_t *uc = reinterpret_cast(context); struct sigcontext *sc = reinterpret_cast(&uc->uc_mcontext); VLOG(signals) << "stack overflow handler with sp at " << std::hex << &uc; VLOG(signals) << "sigcontext: " << std::hex << sc; diff --git a/runtime/arch/mips/fault_handler_mips.cc b/runtime/arch/mips/fault_handler_mips.cc index 52a3df5..84c1f87 100644 --- a/runtime/arch/mips/fault_handler_mips.cc +++ b/runtime/arch/mips/fault_handler_mips.cc @@ -39,7 +39,7 @@ namespace art { void FaultManager::GetMethodAndReturnPcAndSp(siginfo_t* siginfo, void* context, ArtMethod** out_method, uintptr_t* out_return_pc, uintptr_t* out_sp) { - struct ucontext* uc = reinterpret_cast(context); + struct ucontext_t* uc = reinterpret_cast(context); struct sigcontext *sc = reinterpret_cast(&uc->uc_mcontext); *out_sp = static_cast(sc->sc_regs[mips::SP]); VLOG(signals) << "sp: " << *out_sp; @@ -76,7 +76,7 @@ bool NullPointerHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info, void* // PC at the point of call. For Null checks we insert a GC map that is immediately after // the load/store instruction that might cause the fault. - struct ucontext *uc = reinterpret_cast(context); + struct ucontext_t *uc = reinterpret_cast(context); struct sigcontext *sc = reinterpret_cast(&uc->uc_mcontext); // Decrement $sp by the frame size of the kSaveEverything method and store @@ -111,7 +111,7 @@ bool SuspensionHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info ATTRIBU // to the overflow region below the protected region. bool StackOverflowHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info, void* context) { - struct ucontext* uc = reinterpret_cast(context); + struct ucontext_t* uc = reinterpret_cast(context); struct sigcontext *sc = reinterpret_cast(&uc->uc_mcontext); VLOG(signals) << "stack overflow handler with sp at " << std::hex << &uc; VLOG(signals) << "sigcontext: " << std::hex << sc; diff --git a/runtime/arch/mips64/fault_handler_mips64.cc b/runtime/arch/mips64/fault_handler_mips64.cc index 9d77ebc..a6085f4 100644 --- a/runtime/arch/mips64/fault_handler_mips64.cc +++ b/runtime/arch/mips64/fault_handler_mips64.cc @@ -40,7 +40,7 @@ namespace art { void FaultManager::GetMethodAndReturnPcAndSp(siginfo_t* siginfo, void* context, ArtMethod** out_method, uintptr_t* out_return_pc, uintptr_t* out_sp) { - struct ucontext* uc = reinterpret_cast(context); + struct ucontext_t* uc = reinterpret_cast(context); struct sigcontext *sc = reinterpret_cast(&uc->uc_mcontext); *out_sp = static_cast(sc->sc_regs[mips64::SP]); VLOG(signals) << "sp: " << *out_sp; @@ -78,7 +78,7 @@ bool NullPointerHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info, void* // PC at the point of call. For Null checks we insert a GC map that is immediately after // the load/store instruction that might cause the fault. - struct ucontext *uc = reinterpret_cast(context); + struct ucontext_t *uc = reinterpret_cast(context); struct sigcontext *sc = reinterpret_cast(&uc->uc_mcontext); // Decrement $sp by the frame size of the kSaveEverything method and store @@ -113,7 +113,7 @@ bool SuspensionHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info ATTRIBU // to the overflow region below the protected region. bool StackOverflowHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info, void* context) { - struct ucontext* uc = reinterpret_cast(context); + struct ucontext_t* uc = reinterpret_cast(context); struct sigcontext *sc = reinterpret_cast(&uc->uc_mcontext); VLOG(signals) << "stack overflow handler with sp at " << std::hex << &uc; VLOG(signals) << "sigcontext: " << std::hex << sc; diff --git a/runtime/arch/x86/fault_handler_x86.cc b/runtime/arch/x86/fault_handler_x86.cc index 798c500..44a90dc 100644 --- a/runtime/arch/x86/fault_handler_x86.cc +++ b/runtime/arch/x86/fault_handler_x86.cc @@ -280,7 +280,7 @@ static uint32_t GetInstructionSize(const uint8_t* pc) { void FaultManager::GetMethodAndReturnPcAndSp(siginfo_t* siginfo, void* context, ArtMethod** out_method, uintptr_t* out_return_pc, uintptr_t* out_sp) { - struct ucontext* uc = reinterpret_cast(context); + struct ucontext_t* uc = reinterpret_cast(context); *out_sp = static_cast(uc->CTX_ESP); VLOG(signals) << "sp: " << std::hex << *out_sp; if (*out_sp == 0) { @@ -325,7 +325,7 @@ bool NullPointerHandler::Action(int, siginfo_t* sig, void* context) { if (!IsValidImplicitCheck(sig)) { return false; } - struct ucontext *uc = reinterpret_cast(context); + struct ucontext_t *uc = reinterpret_cast(context); uint8_t* pc = reinterpret_cast(uc->CTX_EIP); uint8_t* sp = reinterpret_cast(uc->CTX_ESP); @@ -381,7 +381,7 @@ bool SuspensionHandler::Action(int, siginfo_t*, void* context) { #endif uint8_t checkinst2[] = {0x85, 0x00}; - struct ucontext *uc = reinterpret_cast(context); + struct ucontext_t *uc = reinterpret_cast(context); uint8_t* pc = reinterpret_cast(uc->CTX_EIP); uint8_t* sp = reinterpret_cast(uc->CTX_ESP); @@ -437,7 +437,7 @@ bool SuspensionHandler::Action(int, siginfo_t*, void* context) { // address for the previous method is on the stack at ESP. bool StackOverflowHandler::Action(int, siginfo_t* info, void* context) { - struct ucontext *uc = reinterpret_cast(context); + struct ucontext_t *uc = reinterpret_cast(context); uintptr_t sp = static_cast(uc->CTX_ESP); uintptr_t fault_addr = reinterpret_cast(info->si_addr); diff --git a/runtime/native_stack_dump.cc b/runtime/native_stack_dump.cc index 7e16357..06b04dc 100644 --- a/runtime/native_stack_dump.cc +++ b/runtime/native_stack_dump.cc @@ -36,6 +36,7 @@ #include #include #include +#include #include "android-base/stringprintf.h" @@ -297,7 +298,7 @@ void DumpNativeStack(std::ostream& os, map = tmp_map.get(); } std::unique_ptr backtrace(Backtrace::Create(BACKTRACE_CURRENT_PROCESS, tid, map)); - if (!backtrace->Unwind(0, reinterpret_cast(ucontext_ptr))) { + if (!backtrace->Unwind(0, reinterpret_cast(ucontext_ptr))) { os << prefix << "(backtrace::Unwind failed for thread " << tid << ": " << backtrace->GetErrorString(backtrace->GetError()) << ")" << std::endl; return; -- 2.30.2