Use `ucontext_t` instead of `ucontext`
authorAndroid Tools Maintainers <android-tools-devel@lists.alioth.debian.org>
Tue, 19 Mar 2019 01:46:21 +0000 (01:46 +0000)
committerPeter Michael Green <plugwash@raspbian.org>
Tue, 19 Mar 2019 01:46:21 +0000 (01:46 +0000)
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
runtime/arch/arm/instruction_set_features_arm.cc
runtime/arch/arm64/fault_handler_arm64.cc
runtime/arch/mips/fault_handler_mips.cc
runtime/arch/mips64/fault_handler_mips64.cc
runtime/arch/x86/fault_handler_x86.cc
runtime/native_stack_dump.cc

index b4bca014f4f61f28bbee718b7820e2403ff98975..9901679e581d2cd0a1f30a51b99ea7500ecd30fa 100644 (file)
@@ -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<struct ucontext*>(context);
+  struct ucontext_t* uc = reinterpret_cast<struct ucontext_t*>(context);
   struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
   *out_sp = static_cast<uintptr_t>(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<struct ucontext*>(context);
+  struct ucontext_t *uc = reinterpret_cast<struct ucontext_t*>(context);
   struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
   uint8_t* ptr = reinterpret_cast<uint8_t*>(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<PointerSize::k32>().Int32Value();
   uint16_t checkinst2 = 0x6800;
 
-  struct ucontext* uc = reinterpret_cast<struct ucontext*>(context);
+  struct ucontext_t* uc = reinterpret_cast<struct ucontext_t*>(context);
   struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
   uint8_t* ptr2 = reinterpret_cast<uint8_t*>(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<struct ucontext*>(context);
+  struct ucontext_t* uc = reinterpret_cast<struct ucontext_t*>(context);
   struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
   VLOG(signals) << "stack overflow handler with sp at " << std::hex << &uc;
   VLOG(signals) << "sigcontext: " << std::hex << sc;
index 838446017169656034dae46ffb9ecbb0b0c10d60..9b6213c9a5e64804473a6ec1a4ee5f7b8ad73555 100644 (file)
@@ -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<struct sigcontext*>(&uc->uc_mcontext);
   sc->arm_r0 = 0;     // Set R0 to #0 to signal error.
   sc->arm_pc += 4;    // Skip offending instruction.
 #else
index 0ead732cdda56cf79251159c2c6514428cd5e2c7..a810cf2d56b51081f06c291547ccf700add62ed4 100644 (file)
@@ -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<struct ucontext *>(context);
+  struct ucontext_t *uc = reinterpret_cast<struct ucontext_t *>(context);
   struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
   *out_sp = static_cast<uintptr_t>(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<struct ucontext*>(context);
+  struct ucontext_t *uc = reinterpret_cast<struct ucontext_t*>(context);
   struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&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<PointerSize::k64>().Int32Value() << 7);
   uint32_t checkinst2 = 0xf9400000;
 
-  struct ucontext *uc = reinterpret_cast<struct ucontext *>(context);
+  struct ucontext_t *uc = reinterpret_cast<struct ucontext_t *>(context);
   struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
   uint8_t* ptr2 = reinterpret_cast<uint8_t*>(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<struct ucontext *>(context);
+  struct ucontext_t *uc = reinterpret_cast<struct ucontext_t *>(context);
   struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
   VLOG(signals) << "stack overflow handler with sp at " << std::hex << &uc;
   VLOG(signals) << "sigcontext: " << std::hex << sc;
index 52a3df55d61de7b506546936bdab0bef5ac5e515..84c1f8741ceb7e63d5d780b75373b3c53834dbf1 100644 (file)
@@ -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<struct ucontext*>(context);
+  struct ucontext_t* uc = reinterpret_cast<struct ucontext_t*>(context);
   struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
   *out_sp = static_cast<uintptr_t>(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<struct ucontext*>(context);
+  struct ucontext_t *uc = reinterpret_cast<struct ucontext_t*>(context);
   struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&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<struct ucontext*>(context);
+  struct ucontext_t* uc = reinterpret_cast<struct ucontext_t*>(context);
   struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
   VLOG(signals) << "stack overflow handler with sp at " << std::hex << &uc;
   VLOG(signals) << "sigcontext: " << std::hex << sc;
index 9d77ebcd22f0068fe37d6279e41bc25d8adffae5..a6085f4f198e583942f1333252640b5af6689cd0 100644 (file)
@@ -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<struct ucontext*>(context);
+  struct ucontext_t* uc = reinterpret_cast<struct ucontext_t*>(context);
   struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
   *out_sp = static_cast<uintptr_t>(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<struct ucontext*>(context);
+  struct ucontext_t *uc = reinterpret_cast<struct ucontext_t*>(context);
   struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&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<struct ucontext*>(context);
+  struct ucontext_t* uc = reinterpret_cast<struct ucontext_t*>(context);
   struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
   VLOG(signals) << "stack overflow handler with sp at " << std::hex << &uc;
   VLOG(signals) << "sigcontext: " << std::hex << sc;
index 798c500f181d5c097cae7a8d58ec46c310389f23..44a90dcf2e61a466483215428b2821aa5efbf43c 100644 (file)
@@ -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<struct ucontext*>(context);
+  struct ucontext_t* uc = reinterpret_cast<struct ucontext_t*>(context);
   *out_sp = static_cast<uintptr_t>(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<struct ucontext*>(context);
+  struct ucontext_t *uc = reinterpret_cast<struct ucontext_t*>(context);
   uint8_t* pc = reinterpret_cast<uint8_t*>(uc->CTX_EIP);
   uint8_t* sp = reinterpret_cast<uint8_t*>(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<struct ucontext*>(context);
+  struct ucontext_t *uc = reinterpret_cast<struct ucontext_t*>(context);
   uint8_t* pc = reinterpret_cast<uint8_t*>(uc->CTX_EIP);
   uint8_t* sp = reinterpret_cast<uint8_t*>(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<struct ucontext*>(context);
+  struct ucontext_t *uc = reinterpret_cast<struct ucontext_t*>(context);
   uintptr_t sp = static_cast<uintptr_t>(uc->CTX_ESP);
 
   uintptr_t fault_addr = reinterpret_cast<uintptr_t>(info->si_addr);
index 7e16357376bd9227faa46a448cb2b876e5459e31..06b04dc3b2ae970bc6acc67792682046a41a1207 100644 (file)
@@ -36,6 +36,7 @@
 #include <stdlib.h>
 #include <sys/time.h>
 #include <sys/types.h>
+#include <sys/ucontext.h>
 
 #include "android-base/stringprintf.h"
 
@@ -297,7 +298,7 @@ void DumpNativeStack(std::ostream& os,
     map = tmp_map.get();
   }
   std::unique_ptr<Backtrace> backtrace(Backtrace::Create(BACKTRACE_CURRENT_PROCESS, tid, map));
-  if (!backtrace->Unwind(0, reinterpret_cast<ucontext*>(ucontext_ptr))) {
+  if (!backtrace->Unwind(0, reinterpret_cast<ucontext_t*>(ucontext_ptr))) {
     os << prefix << "(backtrace::Unwind failed for thread " << tid
        << ": " <<  backtrace->GetErrorString(backtrace->GetError()) << ")" << std::endl;
     return;