From eea609c55e2dd6e22a82f79638a43a60d0c5627d Mon Sep 17 00:00:00 2001 From: "Anthony J. Bentley" Date: Sun, 17 Jul 2016 18:59:26 -0600 Subject: [PATCH 1/3] Explicitly error out when no context definition is provided. If there is no context definition in a non-generic build, compilation will error out anyway, but in a less obvious place. --- Source/Core/Core/MachineContext.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/MachineContext.h b/Source/Core/Core/MachineContext.h index 8c683121d1..81012b6b83 100644 --- a/Source/Core/Core/MachineContext.h +++ b/Source/Core/Core/MachineContext.h @@ -114,7 +114,7 @@ typedef mcontext_t SContext; #define CTX_SP sp #define CTX_PC pc #else -#warning No context definition for OS +#error No context definition for OS #endif #elif defined(__NetBSD__) #include @@ -164,6 +164,8 @@ typedef mcontext_t SContext; #else #error No context definition for OS #endif +#else +#error No context definition for OS #endif #if _M_X86_64 From 6e6b113a7edb3f09a76833abaf22d409fe46ffb9 Mon Sep 17 00:00:00 2001 From: "Anthony J. Bentley" Date: Sun, 17 Jul 2016 19:02:59 -0600 Subject: [PATCH 2/3] Clarify error message. If the #error hits, the operating system may be fine but the architecture won't be. --- Source/Core/Core/MachineContext.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/MachineContext.h b/Source/Core/Core/MachineContext.h index 81012b6b83..ac757f23f0 100644 --- a/Source/Core/Core/MachineContext.h +++ b/Source/Core/Core/MachineContext.h @@ -34,7 +34,7 @@ typedef CONTEXT SContext; #define CTX_R15 R15 #define CTX_RIP Rip #else -#error No context definition for OS +#error No context definition for architecture #endif #elif defined(__APPLE__) && !defined(USE_SIGACTION_ON_APPLE) // for modules: @@ -63,7 +63,7 @@ typedef x86_thread_state64_t SContext; #define CTX_R15 __r15 #define CTX_RIP __rip #else -#error No context definition for OS +#error No context definition for architecture #endif #elif defined(__APPLE__) #include @@ -114,7 +114,7 @@ typedef mcontext_t SContext; #define CTX_SP sp #define CTX_PC pc #else -#error No context definition for OS +#error No context definition for architecture #endif #elif defined(__NetBSD__) #include @@ -138,7 +138,7 @@ typedef mcontext_t SContext; #define CTX_R15 __gregs[_REG_R15] #define CTX_RIP __gregs[_REG_RIP] #else -#error No context definition for OS +#error No context definition for architecture #endif #elif defined(__FreeBSD__) #include @@ -162,7 +162,7 @@ typedef mcontext_t SContext; #define CTX_R15 mc_r15 #define CTX_RIP mc_rip #else -#error No context definition for OS +#error No context definition for architecture #endif #else #error No context definition for OS From b0f4a2b959795a569d099c955b5a266273c7ca3e Mon Sep 17 00:00:00 2001 From: "Anthony J. Bentley" Date: Sun, 17 Jul 2016 19:03:47 -0600 Subject: [PATCH 3/3] Add a context definition for OpenBSD amd64. --- Source/Core/Core/MachineContext.h | 24 ++++++++++++++++++++++++ Source/Core/Core/MemTools.cpp | 6 +++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/MachineContext.h b/Source/Core/Core/MachineContext.h index ac757f23f0..891f5c2e15 100644 --- a/Source/Core/Core/MachineContext.h +++ b/Source/Core/Core/MachineContext.h @@ -116,6 +116,30 @@ typedef mcontext_t SContext; #else #error No context definition for architecture #endif +#elif defined(__OpenBSD__) +#include +typedef ucontext_t SContext; +#if _M_X86_64 +#define CTX_RAX sc_rax +#define CTX_RBX sc_rbx +#define CTX_RCX sc_rcx +#define CTX_RDX sc_rdx +#define CTX_RDI sc_rdi +#define CTX_RSI sc_rsi +#define CTX_RBP sc_rbp +#define CTX_RSP sc_rsp +#define CTX_R8 sc_r8 +#define CTX_R9 sc_r9 +#define CTX_R10 sc_r10 +#define CTX_R11 sc_r11 +#define CTX_R12 sc_r12 +#define CTX_R13 sc_r13 +#define CTX_R14 sc_r14 +#define CTX_R15 sc_r15 +#define CTX_RIP sc_rip +#else +#error No context definition for architecture +#endif #elif defined(__NetBSD__) #include typedef mcontext_t SContext; diff --git a/Source/Core/Core/MemTools.cpp b/Source/Core/Core/MemTools.cpp index a54cd0cfab..e9392dcd23 100644 --- a/Source/Core/Core/MemTools.cpp +++ b/Source/Core/Core/MemTools.cpp @@ -248,8 +248,12 @@ static void sigsegv_handler(int sig, siginfo_t* info, void* raw_context) } uintptr_t bad_address = (uintptr_t)info->si_addr; - // Get all the information we can out of the context. +// Get all the information we can out of the context. +#ifdef __OpenBSD__ + ucontext_t* ctx = context; +#else mcontext_t* ctx = &context->uc_mcontext; +#endif // assume it's not a write if (!JitInterface::HandleFault(bad_address, #ifdef __APPLE__