Use the POSIX types for ucontext_t/mcontext_t.
Noticed while trying to copy & paste arm64 code for riscv64 (which had
a different name for the implementation-detail `struct`, but the POSIX
`typedef` would have worked fine).
Test: treehugger
Change-Id: I4880fdc821e564aafecf19f880b6c3ba4c13b072
diff --git a/runtime/arch/arm/fault_handler_arm.cc b/runtime/arch/arm/fault_handler_arm.cc
index 974e056..f02ec65 100644
--- a/runtime/arch/arm/fault_handler_arm.cc
+++ b/runtime/arch/arm/fault_handler_arm.cc
@@ -46,19 +46,19 @@
}
uintptr_t FaultManager::GetFaultPc(siginfo_t* siginfo ATTRIBUTE_UNUSED, void* context) {
- struct ucontext* uc = reinterpret_cast<struct ucontext*>(context);
- struct sigcontext* sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
- if (sc->arm_sp == 0) {
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
+ mcontext_t* mc = reinterpret_cast<mcontext_t*>(&uc->uc_mcontext);
+ if (mc->arm_sp == 0) {
VLOG(signals) << "Missing SP";
return 0u;
}
- return sc->arm_pc;
+ return mc->arm_pc;
}
uintptr_t FaultManager::GetFaultSp(void* context) {
- struct ucontext* uc = reinterpret_cast<struct ucontext*>(context);
- struct sigcontext* sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
- return sc->arm_sp;
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
+ mcontext_t* mc = reinterpret_cast<mcontext_t*>(&uc->uc_mcontext);
+ return mc->arm_sp;
}
bool NullPointerHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info, void* context) {
@@ -67,9 +67,9 @@
return false;
}
- struct ucontext* uc = reinterpret_cast<struct ucontext*>(context);
- struct sigcontext* sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
- ArtMethod** sp = reinterpret_cast<ArtMethod**>(sc->arm_sp);
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
+ mcontext_t* mc = reinterpret_cast<mcontext_t*>(&uc->uc_mcontext);
+ ArtMethod** sp = reinterpret_cast<ArtMethod**>(mc->arm_sp);
if (!IsValidMethod(*sp)) {
return false;
}
@@ -87,20 +87,20 @@
// to that PC (though we're going to jump to the exception handler instead).
// Need to work out the size of the instruction that caused the exception.
- uint8_t* ptr = reinterpret_cast<uint8_t*>(sc->arm_pc);
- bool in_thumb_mode = sc->arm_cpsr & (1 << 5);
+ uint8_t* ptr = reinterpret_cast<uint8_t*>(mc->arm_pc);
+ bool in_thumb_mode = mc->arm_cpsr & (1 << 5);
uint32_t instr_size = in_thumb_mode ? GetInstructionSize(ptr) : 4;
- uintptr_t return_pc = (sc->arm_pc + instr_size) | (in_thumb_mode ? 1 : 0);
+ uintptr_t return_pc = (mc->arm_pc + instr_size) | (in_thumb_mode ? 1 : 0);
// Push the return PC to the stack and pass the fault address in LR.
- sc->arm_sp -= sizeof(uintptr_t);
- *reinterpret_cast<uintptr_t*>(sc->arm_sp) = return_pc;
- sc->arm_lr = fault_address;
+ mc->arm_sp -= sizeof(uintptr_t);
+ *reinterpret_cast<uintptr_t*>(mc->arm_sp) = return_pc;
+ mc->arm_lr = fault_address;
// Arrange for the signal handler to return to the NPE entrypoint.
- sc->arm_pc = reinterpret_cast<uintptr_t>(art_quick_throw_null_pointer_exception_from_signal);
+ mc->arm_pc = reinterpret_cast<uintptr_t>(art_quick_throw_null_pointer_exception_from_signal);
// Make sure the thumb bit is set as the handler is in thumb mode.
- sc->arm_cpsr = sc->arm_cpsr | (1 << 5);
+ mc->arm_cpsr = mc->arm_cpsr | (1 << 5);
// Pass the faulting address as the first argument of
// art_quick_throw_null_pointer_exception_from_signal.
VLOG(signals) << "Generating null pointer exception";
@@ -123,9 +123,9 @@
+ Thread::ThreadSuspendTriggerOffset<PointerSize::k32>().Int32Value();
uint16_t checkinst2 = 0x6800;
- struct ucontext* uc = reinterpret_cast<struct ucontext*>(context);
- struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
- uint8_t* ptr2 = reinterpret_cast<uint8_t*>(sc->arm_pc);
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
+ mcontext_t* mc = reinterpret_cast<mcontext_t*>(&uc->uc_mcontext);
+ uint8_t* ptr2 = reinterpret_cast<uint8_t*>(mc->arm_pc);
uint8_t* ptr1 = ptr2 - 4;
VLOG(signals) << "checking suspend";
@@ -158,10 +158,10 @@
// NB: remember that we need to set the bottom bit of the LR register
// to switch to thumb mode.
- VLOG(signals) << "arm lr: " << std::hex << sc->arm_lr;
- VLOG(signals) << "arm pc: " << std::hex << sc->arm_pc;
- sc->arm_lr = sc->arm_pc + 3; // +2 + 1 (for thumb)
- sc->arm_pc = reinterpret_cast<uintptr_t>(art_quick_implicit_suspend);
+ VLOG(signals) << "arm lr: " << std::hex << mc->arm_lr;
+ VLOG(signals) << "arm pc: " << std::hex << mc->arm_pc;
+ mc->arm_lr = mc->arm_pc + 3; // +2 + 1 (for thumb)
+ mc->arm_pc = reinterpret_cast<uintptr_t>(art_quick_implicit_suspend);
// Now remove the suspend trigger that caused this fault.
Thread::Current()->RemoveSuspendTrigger();
@@ -188,15 +188,15 @@
bool StackOverflowHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info ATTRIBUTE_UNUSED,
void* context) {
- struct ucontext* uc = reinterpret_cast<struct ucontext*>(context);
- struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
+ mcontext_t* mc = reinterpret_cast<mcontext_t*>(&uc->uc_mcontext);
VLOG(signals) << "stack overflow handler with sp at " << std::hex << &uc;
- VLOG(signals) << "sigcontext: " << std::hex << sc;
+ VLOG(signals) << "sigcontext: " << std::hex << mc;
- uintptr_t sp = sc->arm_sp;
+ uintptr_t sp = mc->arm_sp;
VLOG(signals) << "sp: " << std::hex << sp;
- uintptr_t fault_addr = sc->fault_address;
+ uintptr_t fault_addr = mc->fault_address;
VLOG(signals) << "fault_addr: " << std::hex << fault_addr;
VLOG(signals) << "checking for stack overflow, sp: " << std::hex << sp <<
", fault_addr: " << fault_addr;
@@ -215,10 +215,10 @@
// The value of LR must be the same as it was when we entered the code that
// caused this fault. This will be inserted into a callee save frame by
// the function to which this handler returns (art_quick_throw_stack_overflow).
- sc->arm_pc = reinterpret_cast<uintptr_t>(art_quick_throw_stack_overflow);
+ mc->arm_pc = reinterpret_cast<uintptr_t>(art_quick_throw_stack_overflow);
// Make sure the thumb bit is set as the handler is in thumb mode.
- sc->arm_cpsr = sc->arm_cpsr | (1 << 5);
+ mc->arm_cpsr = mc->arm_cpsr | (1 << 5);
// The kernel will now return to the address in sc->arm_pc.
return true;
diff --git a/runtime/arch/arm/instruction_set_features_arm.cc b/runtime/arch/arm/instruction_set_features_arm.cc
index 64ed2a7..749476b 100644
--- a/runtime/arch/arm/instruction_set_features_arm.cc
+++ b/runtime/arch/arm/instruction_set_features_arm.cc
@@ -247,10 +247,10 @@
siginfo_t* si ATTRIBUTE_UNUSED,
void* data) {
#if defined(__arm__)
- struct ucontext *uc = (struct ucontext *)data;
- struct sigcontext *sc = &uc->uc_mcontext;
- sc->arm_r0 = 0; // Set R0 to #0 to signal error.
- sc->arm_pc += 4; // Skip offending instruction.
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(data);
+ mcontext_t* mc = &uc->uc_mcontext;
+ mc->arm_r0 = 0; // Set R0 to #0 to signal error.
+ mc->arm_pc += 4; // Skip offending instruction.
#else
UNUSED(data);
#endif
diff --git a/runtime/arch/arm64/fault_handler_arm64.cc b/runtime/arch/arm64/fault_handler_arm64.cc
index 9634492..3878b57 100644
--- a/runtime/arch/arm64/fault_handler_arm64.cc
+++ b/runtime/arch/arm64/fault_handler_arm64.cc
@@ -47,19 +47,19 @@
return 0u;
}
- struct ucontext* uc = reinterpret_cast<struct ucontext*>(context);
- struct sigcontext* sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
- if (sc->sp == 0) {
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
+ mcontext_t* mc = reinterpret_cast<mcontext_t*>(&uc->uc_mcontext);
+ if (mc->sp == 0) {
VLOG(signals) << "Missing SP";
return 0u;
}
- return sc->pc;
+ return mc->pc;
}
uintptr_t FaultManager::GetFaultSp(void* context) {
- struct ucontext* uc = reinterpret_cast<struct ucontext*>(context);
- struct sigcontext* sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
- return sc->sp;
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
+ mcontext_t* mc = reinterpret_cast<mcontext_t*>(&uc->uc_mcontext);
+ return mc->sp;
}
bool NullPointerHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info, void* context) {
@@ -74,21 +74,21 @@
// need the return PC to recognize that this was a null check in Nterp, so
// that the handler can get the needed data from the Nterp frame.
- struct ucontext* uc = reinterpret_cast<struct ucontext*>(context);
- struct sigcontext* sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
- ArtMethod** sp = reinterpret_cast<ArtMethod**>(sc->sp);
- uintptr_t return_pc = sc->pc + 4u;
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
+ mcontext_t* mc = reinterpret_cast<mcontext_t*>(&uc->uc_mcontext);
+ ArtMethod** sp = reinterpret_cast<ArtMethod**>(mc->sp);
+ uintptr_t return_pc = mc->pc + 4u;
if (!IsValidMethod(*sp) || !IsValidReturnPc(sp, return_pc)) {
return false;
}
// Push the return PC to the stack and pass the fault address in LR.
- sc->sp -= sizeof(uintptr_t);
- *reinterpret_cast<uintptr_t*>(sc->sp) = return_pc;
- sc->regs[30] = fault_address;
+ mc->sp -= sizeof(uintptr_t);
+ *reinterpret_cast<uintptr_t*>(mc->sp) = return_pc;
+ mc->regs[30] = fault_address;
// Arrange for the signal handler to return to the NPE entrypoint.
- sc->pc = reinterpret_cast<uintptr_t>(art_quick_throw_null_pointer_exception_from_signal);
+ mc->pc = reinterpret_cast<uintptr_t>(art_quick_throw_null_pointer_exception_from_signal);
VLOG(signals) << "Generating null pointer exception";
return true;
}
@@ -102,10 +102,10 @@
constexpr uint32_t checkinst =
0xf9400000 | (kSuspendCheckRegister << 5) | (kSuspendCheckRegister << 0);
- struct ucontext* uc = reinterpret_cast<struct ucontext*>(context);
- struct sigcontext* sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
+ mcontext_t* mc = reinterpret_cast<mcontext_t*>(&uc->uc_mcontext);
- uint32_t inst = *reinterpret_cast<uint32_t*>(sc->pc);
+ uint32_t inst = *reinterpret_cast<uint32_t*>(mc->pc);
VLOG(signals) << "checking suspend; inst: " << std::hex << inst << " checkinst: " << checkinst;
if (inst != checkinst) {
// The instruction is not good, not ours.
@@ -117,9 +117,9 @@
// Set LR so that after the suspend check it will resume after the
// `ldr x21, [x21,#0]` instruction that triggered the suspend check.
- sc->regs[30] = sc->pc + 4;
+ mc->regs[30] = mc->pc + 4;
// Arrange for the signal handler to return to `art_quick_implicit_suspend()`.
- sc->pc = reinterpret_cast<uintptr_t>(art_quick_implicit_suspend);
+ mc->pc = reinterpret_cast<uintptr_t>(art_quick_implicit_suspend);
// Now remove the suspend trigger that caused this fault.
Thread::Current()->RemoveSuspendTrigger();
@@ -130,15 +130,15 @@
bool StackOverflowHandler::Action(int sig ATTRIBUTE_UNUSED, siginfo_t* info ATTRIBUTE_UNUSED,
void* context) {
- struct ucontext* uc = reinterpret_cast<struct ucontext*>(context);
- struct sigcontext* sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
+ mcontext_t* mc = reinterpret_cast<mcontext_t*>(&uc->uc_mcontext);
VLOG(signals) << "stack overflow handler with sp at " << std::hex << &uc;
- VLOG(signals) << "sigcontext: " << std::hex << sc;
+ VLOG(signals) << "sigcontext: " << std::hex << mc;
- uintptr_t sp = sc->sp;
+ uintptr_t sp = mc->sp;
VLOG(signals) << "sp: " << std::hex << sp;
- uintptr_t fault_addr = sc->fault_address;
+ uintptr_t fault_addr = mc->fault_address;
VLOG(signals) << "fault_addr: " << std::hex << fault_addr;
VLOG(signals) << "checking for stack overflow, sp: " << std::hex << sp <<
", fault_addr: " << fault_addr;
@@ -157,7 +157,7 @@
// The value of LR must be the same as it was when we entered the code that
// caused this fault. This will be inserted into a callee save frame by
// the function to which this handler returns (art_quick_throw_stack_overflow).
- sc->pc = reinterpret_cast<uintptr_t>(art_quick_throw_stack_overflow);
+ mc->pc = reinterpret_cast<uintptr_t>(art_quick_throw_stack_overflow);
// The kernel will now return to the address in sc->pc.
return true;
diff --git a/runtime/arch/x86/fault_handler_x86.cc b/runtime/arch/x86/fault_handler_x86.cc
index c485f0d..cd2d38f 100644
--- a/runtime/arch/x86/fault_handler_x86.cc
+++ b/runtime/arch/x86/fault_handler_x86.cc
@@ -260,7 +260,7 @@
}
uintptr_t FaultManager::GetFaultPc(siginfo_t* siginfo ATTRIBUTE_UNUSED, void* context) {
- struct ucontext* uc = reinterpret_cast<struct ucontext*>(context);
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
if (uc->CTX_ESP == 0) {
VLOG(signals) << "Missing SP";
return 0u;
@@ -269,7 +269,7 @@
}
uintptr_t FaultManager::GetFaultSp(void* context) {
- struct ucontext* uc = reinterpret_cast<struct ucontext*>(context);
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
return uc->CTX_ESP;
}
@@ -279,7 +279,7 @@
return false;
}
- struct ucontext* uc = reinterpret_cast<struct ucontext*>(context);
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
ArtMethod** sp = reinterpret_cast<ArtMethod**>(uc->CTX_ESP);
ArtMethod* method = *sp;
if (!IsValidMethod(method)) {
@@ -359,7 +359,7 @@
#endif
uint8_t checkinst2[] = {0x85, 0x00};
- struct ucontext* uc = reinterpret_cast<struct ucontext*>(context);
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
uint8_t* pc = reinterpret_cast<uint8_t*>(uc->CTX_EIP);
uint8_t* sp = reinterpret_cast<uint8_t*>(uc->CTX_ESP);
@@ -415,7 +415,7 @@
// 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);
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
uintptr_t sp = static_cast<uintptr_t>(uc->CTX_ESP);
uintptr_t fault_addr = reinterpret_cast<uintptr_t>(info->si_addr);
diff --git a/test/004-SignalTest/signaltest.cc b/test/004-SignalTest/signaltest.cc
index 6f97b2a..daa31d3 100644
--- a/test/004-SignalTest/signaltest.cc
+++ b/test/004-SignalTest/signaltest.cc
@@ -77,18 +77,18 @@
sigprocmask(SIG_UNBLOCK, &mask, nullptr);
#if defined(__arm__)
- struct ucontext *uc = reinterpret_cast<struct ucontext*>(context);
- struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
- sc->arm_pc += 2; // Skip instruction causing segv.
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
+ mcontext_t* mc = reinterpret_cast<mcontext_t*>(&uc->uc_mcontext);
+ mc->arm_pc += 2; // Skip instruction causing segv.
#elif defined(__aarch64__)
- struct ucontext *uc = reinterpret_cast<struct ucontext*>(context);
- struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
- sc->pc += 4; // Skip instruction causing segv.
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
+ mcontext_t* mc = reinterpret_cast<mcontext_t*>(&uc->uc_mcontext);
+ mc->pc += 4; // Skip instruction causing segv.
#elif defined(__i386__)
- struct ucontext *uc = reinterpret_cast<struct ucontext*>(context);
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
uc->CTX_EIP += 3;
#elif defined(__x86_64__)
- struct ucontext *uc = reinterpret_cast<struct ucontext*>(context);
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
uc->CTX_EIP += 2;
#else
UNUSED(context);
diff --git a/test/115-native-bridge/nativebridge.cc b/test/115-native-bridge/nativebridge.cc
index 3209449..a5541ce 100644
--- a/test/115-native-bridge/nativebridge.cc
+++ b/test/115-native-bridge/nativebridge.cc
@@ -557,18 +557,18 @@
void* context) {
if (sig == SIGSEGV) {
#if defined(__arm__)
- struct ucontext *uc = reinterpret_cast<struct ucontext*>(context);
- struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
- sc->arm_pc += 2; // Skip instruction causing segv & sigill.
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
+ mcontext_t* mc = reinterpret_cast<mcontext_t*>(&uc->uc_mcontext);
+ mc->arm_pc += 2; // Skip instruction causing segv & sigill.
#elif defined(__aarch64__)
- struct ucontext *uc = reinterpret_cast<struct ucontext*>(context);
- struct sigcontext *sc = reinterpret_cast<struct sigcontext*>(&uc->uc_mcontext);
- sc->pc += 4; // Skip instruction causing segv & sigill.
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
+ mcontext_t* mc = reinterpret_cast<mcontext_t*>(&uc->uc_mcontext);
+ mc->pc += 4; // Skip instruction causing segv & sigill.
#elif defined(__i386__)
- struct ucontext *uc = reinterpret_cast<struct ucontext*>(context);
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
uc->CTX_EIP += 3;
#elif defined(__x86_64__)
- struct ucontext *uc = reinterpret_cast<struct ucontext*>(context);
+ ucontext_t* uc = reinterpret_cast<ucontext_t*>(context);
uc->CTX_EIP += 2;
#else
UNUSED(context);