From: Android Tools Maintainers Date: Thu, 28 Jul 2022 16:01:55 +0000 (+0100) Subject: Use `ucontext_t` instead of `ucontext` X-Git-Tag: archive/raspbian/29.0.6-20+rpi1^2~12 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c1e5e2d480db4bfebee2fc4ebdfc9638b3eefa97;p=android-platform-tools.git Use `ucontext_t` instead of `ucontext` Forwarded: not-needed 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: Topic art Gbp-Pq: Name ucontext.patch --- diff --git a/art/runtime/arch/arm/fault_handler_arm.cc b/art/runtime/arch/arm/fault_handler_arm.cc index 4e7d64cc..7a11c642 100644 --- a/art/runtime/arch/arm/fault_handler_arm.cc +++ b/art/runtime/arch/arm/fault_handler_arm.cc @@ -51,7 +51,7 @@ void FaultManager::GetMethodAndReturnPcAndSp(siginfo_t* siginfo ATTRIBUTE_UNUSED uintptr_t* out_return_pc, uintptr_t* out_sp, bool* out_is_stack_overflow) { - 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; @@ -104,7 +104,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); @@ -137,7 +137,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; @@ -202,7 +202,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/art/runtime/arch/arm/instruction_set_features_arm.cc b/art/runtime/arch/arm/instruction_set_features_arm.cc index fdf4dbd7..4df8f26b 100644 --- a/art/runtime/arch/arm/instruction_set_features_arm.cc +++ b/art/runtime/arch/arm/instruction_set_features_arm.cc @@ -223,8 +223,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/art/runtime/arch/arm64/fault_handler_arm64.cc b/art/runtime/arch/arm64/fault_handler_arm64.cc index c139e21d..9447fb14 100644 --- a/art/runtime/arch/arm64/fault_handler_arm64.cc +++ b/art/runtime/arch/arm64/fault_handler_arm64.cc @@ -44,7 +44,7 @@ void FaultManager::GetMethodAndReturnPcAndSp(siginfo_t* siginfo ATTRIBUTE_UNUSED uintptr_t* out_return_pc, uintptr_t* out_sp, bool* out_is_stack_overflow) { - 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; @@ -82,7 +82,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. @@ -111,7 +111,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; @@ -157,7 +157,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/art/runtime/arch/mips/fault_handler_mips.cc b/art/runtime/arch/mips/fault_handler_mips.cc index f55df925..1663ca34 100644 --- a/art/runtime/arch/mips/fault_handler_mips.cc +++ b/art/runtime/arch/mips/fault_handler_mips.cc @@ -43,7 +43,7 @@ void FaultManager::GetMethodAndReturnPcAndSp(siginfo_t* siginfo, uintptr_t* out_return_pc, uintptr_t* out_sp, bool* out_is_stack_overflow) { - 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; @@ -82,7 +82,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 @@ -117,7 +117,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/art/runtime/arch/mips64/fault_handler_mips64.cc b/art/runtime/arch/mips64/fault_handler_mips64.cc index ff53fa69..dfc42b1a 100644 --- a/art/runtime/arch/mips64/fault_handler_mips64.cc +++ b/art/runtime/arch/mips64/fault_handler_mips64.cc @@ -44,7 +44,7 @@ void FaultManager::GetMethodAndReturnPcAndSp(siginfo_t* siginfo, uintptr_t* out_return_pc, uintptr_t* out_sp, bool* out_is_stack_overflow) { - 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; @@ -84,7 +84,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 @@ -119,7 +119,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/art/runtime/arch/x86/fault_handler_x86.cc b/art/runtime/arch/x86/fault_handler_x86.cc index 3a08ec5c..9e0ede7f 100644 --- a/art/runtime/arch/x86/fault_handler_x86.cc +++ b/art/runtime/arch/x86/fault_handler_x86.cc @@ -282,7 +282,7 @@ void FaultManager::GetMethodAndReturnPcAndSp(siginfo_t* siginfo, void* context, uintptr_t* out_return_pc, uintptr_t* out_sp, bool* out_is_stack_overflow) { - 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) { @@ -329,7 +329,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); @@ -385,7 +385,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); @@ -441,7 +441,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/art/runtime/native_stack_dump.cc b/art/runtime/native_stack_dump.cc index 74d9033b..08d6a2fb 100644 --- a/art/runtime/native_stack_dump.cc +++ b/art/runtime/native_stack_dump.cc @@ -38,6 +38,7 @@ #include #include #include +#include #include "android-base/file.h" #include "android-base/stringprintf.h" @@ -334,7 +335,7 @@ void DumpNativeStack(std::ostream& os, } std::unique_ptr backtrace(Backtrace::Create(BACKTRACE_CURRENT_PROCESS, tid, map)); backtrace->SetSkipFrames(skip_frames); - 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;