aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWaluigiWare64 <68647953+WaluigiWare64@users.noreply.github.com>2021-02-25 21:17:11 +0000
committerGitHub <noreply@github.com>2021-02-25 21:17:11 +0000
commit89051f63d4c6c62ca18110037534a9fc575574f2 (patch)
treed1d011734cff8d36f18596230635f9b4eb1e534b /src
parent81980d28364ee83634e7c3101b2e290fff254c8f (diff)
Define CONTEXT_PC and use instead for much cleaner code (#1017)
* Define CONTEXT_PC and use instead for much cleaner code Also include ways to get the Program Counter on ARM64 FreeBSD and NetBSD
Diffstat (limited to 'src')
-rw-r--r--src/ARMJIT_Memory.cpp71
1 files changed, 32 insertions, 39 deletions
diff --git a/src/ARMJIT_Memory.cpp b/src/ARMJIT_Memory.cpp
index 063437e..77caced 100644
--- a/src/ARMJIT_Memory.cpp
+++ b/src/ARMJIT_Memory.cpp
@@ -63,6 +63,33 @@ struct FaultDescription
bool FaultHandler(FaultDescription& faultDesc);
}
+// Yes I know this looks messy, but better here than somewhere else in the code
+#if defined(_WIN32)
+ #define CONTEXT_PC Rip
+#else
+ #if defined(__x86_64__)
+ #if defined(__linux__)
+ #define CONTEXT_PC uc_mcontext.gregs[REG_RIP]
+ #elif defined(__APPLE__)
+ #define CONTEXT_PC uc_mcontext->__ss.__rip
+ #elif defined(__FreeBSD__)
+ #define CONTEXT_PC uc_mcontext.mc_rip
+ #elif defined(__NetBSD__)
+ #define CONTEXT_PC uc_mcontext.__gregs[_REG_RIP]
+ #endif
+ #elif defined(__aarch64__)
+ #if defined(__linux__)
+ #define CONTEXT_PC uc_mcontext.pc
+ #elif defined(__APPLE__)
+ #define CONTEXT_PC uc_mcontext->__ss.__pc
+ #elif defined(__FreeBSD__)
+ #define CONTEXT_PC uc_mcontext.mc_gpregs.gp_elr
+ #elif defined(__NetBSD__)
+ #define CONTEXT_PC uc_mcontext.__gregs[_REG_PC]
+ #endif
+ #endif
+#endif
+
#if defined(__ANDROID__)
#define ASHMEM_DEVICE "/dev/ashmem"
#endif
@@ -120,11 +147,11 @@ static LONG ExceptionHandler(EXCEPTION_POINTERS* exceptionInfo)
ARMJIT_Memory::FaultDescription desc;
u8* curArea = (u8*)(NDS::CurCPU == 0 ? ARMJIT_Memory::FastMem9Start : ARMJIT_Memory::FastMem7Start);
desc.EmulatedFaultAddr = (u8*)exceptionInfo->ExceptionRecord->ExceptionInformation[1] - curArea;
- desc.FaultPC = (u8*)exceptionInfo->ContextRecord->Rip;
+ desc.FaultPC = (u8*)exceptionInfo->ContextRecord->CONTEXT_PC;
if (ARMJIT_Memory::FaultHandler(desc))
{
- exceptionInfo->ContextRecord->Rip = (u64)desc.FaultPC;
+ exceptionInfo->ContextRecord->CONTEXT_PC = (u64)desc.FaultPC;
return EXCEPTION_CONTINUE_EXECUTION;
}
@@ -153,47 +180,13 @@ static void SigsegvHandler(int sig, siginfo_t* info, void* rawContext)
ARMJIT_Memory::FaultDescription desc;
u8* curArea = (u8*)(NDS::CurCPU == 0 ? ARMJIT_Memory::FastMem9Start : ARMJIT_Memory::FastMem7Start);
-#ifdef __x86_64__
+
desc.EmulatedFaultAddr = (u8*)info->si_addr - curArea;
- #if defined(__APPLE__)
- desc.FaultPC = (u8*)context->uc_mcontext->__ss.__rip;
- #elif defined(__FreeBSD__)
- desc.FaultPC = (u8*)context->uc_mcontext.mc_rip;
- #elif defined(__NetBSD__)
- desc.FaultPC = (u8*)context->uc_mcontext.__gregs[_REG_RIP];
- #else
- desc.FaultPC = (u8*)context->uc_mcontext.gregs[REG_RIP];
- #endif
-
-#else
- #ifdef __APPLE__
- desc.EmulatedFaultAddr = (u8*)context->uc_mcontext->__es.__far - curArea;
- desc.FaultPC = (u8*)context->uc_mcontext->__ss.__pc;
- #else
- desc.EmulatedFaultAddr = (u8*)context->uc_mcontext.fault_address - curArea;
- desc.FaultPC = (u8*)context->uc_mcontext.pc;
- #endif
-#endif
+ desc.FaultPC = (u8*)context->CONTEXT_PC;
if (ARMJIT_Memory::FaultHandler(desc))
{
-#ifdef __x86_64__
- #if defined(__APPLE__)
- context->uc_mcontext->__ss.__rip = (u64)desc.FaultPC;
- #elif defined(__FreeBSD__)
- context->uc_mcontext.mc_rip = (u64)desc.FaultPC;
- #elif defined(__NetBSD__)
- context->uc_mcontext.__gregs[_REG_RIP] = (u64)desc.FaultPC;
- #else
- context->uc_mcontext.gregs[REG_RIP] = (u64)desc.FaultPC;
- #endif
-#else
- #ifdef __APPLE__
- context->uc_mcontext->__ss.__pc = (u64)desc.FaultPC;
- #else
- context->uc_mcontext.pc = (u64)desc.FaultPC;
- #endif
-#endif
+ context->CONTEXT_PC = (u64)desc.FaultPC;
return;
}