Added register struct defs for non-linux

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1559 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
bushing 2008-12-17 02:08:11 +00:00
parent af501556b3
commit 1e774a5db2
1 changed files with 22 additions and 10 deletions

View File

@ -26,6 +26,17 @@
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
#include <sys/ucontext.h> // Look in here for the context definition. #include <sys/ucontext.h> // Look in here for the context definition.
#ifdef __LINUX__
#define CREG_RAX(ctx) (ctx)->gregs[REG_RAX]
#define CREG_RIP(ctx) (ctx)->gregs[REG_RIP]
#define CREG_EAX(ctx) (ctx)->gregs[REG_EAX]
#define CREG_EIP(ctx) (ctx)->gregs[REG_EIP]
#else
#define CREG_RAX(ctx) (*(ctx))->__ss.__rax
#define CREG_RIP(ctx) (*(ctx))->__ss.__rip
#define CREG_EAX(ctx) (*(ctx))->__ss.__eax
#define CREG_EIP(ctx) (*(ctx))->__ss.__eip
#endif
#endif #endif
@ -185,9 +196,9 @@ void sigsegv_handler(int signal, siginfo_t *info, void *raw_context)
// Get all the information we can out of the context. // Get all the information we can out of the context.
mcontext_t *ctx = &context->uc_mcontext; mcontext_t *ctx = &context->uc_mcontext;
#ifdef _M_X64 #ifdef _M_X64
u8 *fault_instruction_ptr = (u8 *)ctx->gregs[REG_RIP]; u8 *fault_instruction_ptr = (u8 *)CREG_RIP(ctx);
#else #else
u8 *fault_instruction_ptr = (u8 *)ctx->gregs[REG_EIP]; u8 *fault_instruction_ptr = (u8 *)CREG_EIP(ctx);
#endif #endif
if (!Jit64::IsInJitCode((const u8 *)fault_instruction_ptr)) { if (!Jit64::IsInJitCode((const u8 *)fault_instruction_ptr)) {
// Let's not prevent debugging. // Let's not prevent debugging.
@ -208,21 +219,22 @@ void sigsegv_handler(int signal, siginfo_t *info, void *raw_context)
int access_type = 0; int access_type = 0;
CONTEXT fake_ctx; CONTEXT fake_ctx;
#ifdef _M_X64 #ifdef _M_X64
fake_ctx.Rax = ctx->gregs[REG_RAX]; fake_ctx.Rax = CREG_RAX(ctx);
fake_ctx.Rip = ctx->gregs[REG_RIP]; fake_ctx.Rip = CREG_RIP(ctx);
#else #else
fake_ctx.Eax = ctx->gregs[REG_EAX]; fake_ctx.Eax = CREG_EAX(ctx);
fake_ctx.Eip = ctx->gregs[REG_EIP]; fake_ctx.Eip = CREG_EIP(ctx);
#endif #endif
u8 *new_rip = Jit64::BackPatch(fault_instruction_ptr, access_type, em_address, &fake_ctx); u8 *new_rip = Jit64::BackPatch(fault_instruction_ptr, access_type, em_address, &fake_ctx);
if (new_rip) { if (new_rip) {
#ifdef _M_X64 #ifdef _M_X64
ctx->gregs[REG_RAX] = fake_ctx.Rax; CREG_RAX(ctx) = fake_ctx.Rax;
ctx->gregs[REG_RIP] = (u64)new_rip; CREG_RIP(ctx) = fake_ctx.Rip;
#else #else
ctx->gregs[REG_EAX] = fake_ctx.Eax; CREG_EAX(ctx) = fake_ctx.Eax;
ctx->gregs[REG_EIP] = (u32)new_rip; CREG_EIP(ctx) = fake_ctx.Eip;
#endif #endif
} }
} }