Merge pull request #1449 from comex/memtools-merge

Reorganize faulting stuff.  Differentiate between arch- and OS-specific defines.
This commit is contained in:
comex 2014-11-16 13:46:33 -05:00
commit aa2fc1f66b
14 changed files with 37 additions and 108 deletions

View File

@ -1,78 +0,0 @@
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#include <cstdio>
#include <signal.h>
#ifdef ANDROID
#include <asm/sigcontext.h>
#else
#include <execinfo.h>
#include <sys/ucontext.h> // Look in here for the context definition.
#endif
#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
#include "Core/MemTools.h"
#include "Core/HW/Memmap.h"
#include "Core/PowerPC/JitInterface.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/PowerPC/JitCommon/JitBase.h"
namespace EMM
{
#ifdef ANDROID
typedef struct sigcontext mcontext_t;
typedef struct ucontext {
uint32_t uc_flags;
struct ucontext* uc_link;
stack_t uc_stack;
mcontext_t uc_mcontext;
// Other fields are not used by Google Breakpad. Don't define them.
} ucontext_t;
#endif
static void sigsegv_handler(int sig, siginfo_t *info, void *raw_context)
{
if (sig != SIGSEGV)
{
// We are not interested in other signals - handle it as usual.
return;
}
ucontext_t *context = (ucontext_t *)raw_context;
int sicode = info->si_code;
if (sicode != SEGV_MAPERR && sicode != SEGV_ACCERR)
{
// Huh? Return.
return;
}
// Get all the information we can out of the context.
mcontext_t *ctx = &context->uc_mcontext;
// comex says hello, and is most curious whether this is arm_r10 for a
// reason as opposed to si_addr like the x64MemTools.cpp version. Is there
// even a need for this file to be architecture specific?
uintptr_t fault_memory_ptr = (uintptr_t)ctx->arm_r10;
if (!JitInterface::HandleFault(fault_memory_ptr, ctx))
{
// retry and crash
signal(SIGSEGV, SIG_DFL);
}
}
void InstallExceptionHandler()
{
struct sigaction sa;
sa.sa_handler = 0;
sa.sa_sigaction = &sigsegv_handler;
sa.sa_flags = SA_SIGINFO;
sigemptyset(&sa.sa_mask);
sigaction(SIGSEGV, &sa, nullptr);
}
void UninstallExceptionHandler() {}
} // namespace

View File

@ -9,6 +9,7 @@ set(SRCS ActionReplay.cpp
ec_wii.cpp ec_wii.cpp
GeckoCodeConfig.cpp GeckoCodeConfig.cpp
GeckoCode.cpp GeckoCode.cpp
MemTools.cpp
Movie.cpp Movie.cpp
NetPlayClient.cpp NetPlayClient.cpp
NetPlayServer.cpp NetPlayServer.cpp
@ -179,7 +180,6 @@ set(SRCS ActionReplay.cpp
if(_M_X86) if(_M_X86)
set(SRCS ${SRCS} set(SRCS ${SRCS}
x64MemTools.cpp
PowerPC/Jit64IL/IR_X86.cpp PowerPC/Jit64IL/IR_X86.cpp
PowerPC/Jit64IL/JitIL.cpp PowerPC/Jit64IL/JitIL.cpp
PowerPC/Jit64IL/JitIL_Tables.cpp PowerPC/Jit64IL/JitIL_Tables.cpp
@ -201,7 +201,6 @@ if(_M_X86)
PowerPC/JitCommon/TrampolineCache.cpp) PowerPC/JitCommon/TrampolineCache.cpp)
elseif(_M_ARM_32) elseif(_M_ARM_32)
set(SRCS ${SRCS} set(SRCS ${SRCS}
ArmMemTools.cpp
PowerPC/JitArm32/Jit.cpp PowerPC/JitArm32/Jit.cpp
PowerPC/JitArm32/JitAsm.cpp PowerPC/JitArm32/JitAsm.cpp
PowerPC/JitArm32/JitArm_BackPatch.cpp PowerPC/JitArm32/JitArm_BackPatch.cpp

View File

@ -255,10 +255,8 @@ static void CpuThread()
g_video_backend->Video_Prepare(); g_video_backend->Video_Prepare();
} }
#if _M_X86_64 || _M_ARM_32
if (_CoreParameter.bFastmem) if (_CoreParameter.bFastmem)
EMM::InstallExceptionHandler(); // Let's run under memory watch EMM::InstallExceptionHandler(); // Let's run under memory watch
#endif
if (!s_state_filename.empty()) if (!s_state_filename.empty())
State::LoadAs(s_state_filename); State::LoadAs(s_state_filename);
@ -283,9 +281,7 @@ static void CpuThread()
if (!_CoreParameter.bCPUThread) if (!_CoreParameter.bCPUThread)
g_video_backend->Video_Cleanup(); g_video_backend->Video_Cleanup();
#if _M_X86_64 || _M_ARM_32
EMM::UninstallExceptionHandler(); EMM::UninstallExceptionHandler();
#endif
return; return;
} }

View File

@ -187,6 +187,7 @@
<ClCompile Include="IPC_HLE\WII_IPC_HLE_Device_usb_kbd.cpp" /> <ClCompile Include="IPC_HLE\WII_IPC_HLE_Device_usb_kbd.cpp" />
<ClCompile Include="IPC_HLE\WII_IPC_HLE_WiiMote.cpp" /> <ClCompile Include="IPC_HLE\WII_IPC_HLE_WiiMote.cpp" />
<ClCompile Include="IPC_HLE\WII_Socket.cpp" /> <ClCompile Include="IPC_HLE\WII_Socket.cpp" />
<ClCompile Include="MemTools.cpp" />
<ClCompile Include="Movie.cpp" /> <ClCompile Include="Movie.cpp" />
<ClCompile Include="NetPlayClient.cpp" /> <ClCompile Include="NetPlayClient.cpp" />
<ClCompile Include="NetPlayServer.cpp" /> <ClCompile Include="NetPlayServer.cpp" />
@ -240,7 +241,6 @@
<ClCompile Include="PowerPC\SignatureDB.cpp" /> <ClCompile Include="PowerPC\SignatureDB.cpp" />
<ClCompile Include="State.cpp" /> <ClCompile Include="State.cpp" />
<ClCompile Include="VolumeHandler.cpp" /> <ClCompile Include="VolumeHandler.cpp" />
<ClCompile Include="x64MemTools.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="ActionReplay.h" /> <ClInclude Include="ActionReplay.h" />
@ -383,6 +383,7 @@
<ClInclude Include="IPC_HLE\WII_IPC_HLE_Device_usb_kbd.h" /> <ClInclude Include="IPC_HLE\WII_IPC_HLE_Device_usb_kbd.h" />
<ClInclude Include="IPC_HLE\WII_IPC_HLE_WiiMote.h" /> <ClInclude Include="IPC_HLE\WII_IPC_HLE_WiiMote.h" />
<ClInclude Include="IPC_HLE\WII_Socket.h" /> <ClInclude Include="IPC_HLE\WII_Socket.h" />
<ClInclude Include="MachineContext.h" />
<ClInclude Include="MemTools.h" /> <ClInclude Include="MemTools.h" />
<ClInclude Include="Movie.h" /> <ClInclude Include="Movie.h" />
<ClInclude Include="NetPlayClient.h" /> <ClInclude Include="NetPlayClient.h" />
@ -403,7 +404,6 @@
<ClInclude Include="PowerPC\JitILCommon\IR.h" /> <ClInclude Include="PowerPC\JitILCommon\IR.h" />
<ClInclude Include="PowerPC\JitILCommon\JitILBase.h" /> <ClInclude Include="PowerPC\JitILCommon\JitILBase.h" />
<ClInclude Include="PowerPC\JitCommon\JitAsmCommon.h" /> <ClInclude Include="PowerPC\JitCommon\JitAsmCommon.h" />
<ClInclude Include="PowerPC\JitCommon\JitBackpatch.h" />
<ClInclude Include="PowerPC\JitCommon\JitBase.h" /> <ClInclude Include="PowerPC\JitCommon\JitBase.h" />
<ClInclude Include="PowerPC\JitCommon\JitCache.h" /> <ClInclude Include="PowerPC\JitCommon\JitCache.h" />
<ClInclude Include="PowerPC\JitCommon\Jit_Util.h" /> <ClInclude Include="PowerPC\JitCommon\Jit_Util.h" />

View File

@ -141,13 +141,13 @@
<ClCompile Include="CoreParameter.cpp" /> <ClCompile Include="CoreParameter.cpp" />
<ClCompile Include="CoreTiming.cpp" /> <ClCompile Include="CoreTiming.cpp" />
<ClCompile Include="ec_wii.cpp" /> <ClCompile Include="ec_wii.cpp" />
<ClCompile Include="MemTools.cpp" />
<ClCompile Include="Movie.cpp" /> <ClCompile Include="Movie.cpp" />
<ClCompile Include="NetPlayClient.cpp" /> <ClCompile Include="NetPlayClient.cpp" />
<ClCompile Include="NetPlayServer.cpp" /> <ClCompile Include="NetPlayServer.cpp" />
<ClCompile Include="PatchEngine.cpp" /> <ClCompile Include="PatchEngine.cpp" />
<ClCompile Include="State.cpp" /> <ClCompile Include="State.cpp" />
<ClCompile Include="VolumeHandler.cpp" /> <ClCompile Include="VolumeHandler.cpp" />
<ClCompile Include="x64MemTools.cpp" />
<ClCompile Include="ActionReplay.cpp"> <ClCompile Include="ActionReplay.cpp">
<Filter>ActionReplay</Filter> <Filter>ActionReplay</Filter>
</ClCompile> </ClCompile>
@ -631,9 +631,6 @@
<ClCompile Include="PowerPC\JitCommon\JitAsmCommon.cpp"> <ClCompile Include="PowerPC\JitCommon\JitAsmCommon.cpp">
<Filter>PowerPC\JitCommon</Filter> <Filter>PowerPC\JitCommon</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="PowerPC\JitCommon\JitBackpatch.cpp">
<Filter>PowerPC\JitCommon</Filter>
</ClCompile>
<ClCompile Include="PowerPC\JitCommon\JitBase.cpp"> <ClCompile Include="PowerPC\JitCommon\JitBase.cpp">
<Filter>PowerPC\JitCommon</Filter> <Filter>PowerPC\JitCommon</Filter>
</ClCompile> </ClCompile>
@ -718,6 +715,7 @@
<ClInclude Include="CoreTiming.h" /> <ClInclude Include="CoreTiming.h" />
<ClInclude Include="ec_wii.h" /> <ClInclude Include="ec_wii.h" />
<ClInclude Include="Host.h" /> <ClInclude Include="Host.h" />
<ClCompile Include="MachineContext.h" />
<ClInclude Include="MemTools.h" /> <ClInclude Include="MemTools.h" />
<ClInclude Include="Movie.h" /> <ClInclude Include="Movie.h" />
<ClInclude Include="NetPlayClient.h" /> <ClInclude Include="NetPlayClient.h" />
@ -1176,9 +1174,6 @@
<ClInclude Include="PowerPC\JitCommon\JitAsmCommon.h"> <ClInclude Include="PowerPC\JitCommon\JitAsmCommon.h">
<Filter>PowerPC\JitCommon</Filter> <Filter>PowerPC\JitCommon</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="PowerPC\JitCommon\JitBackpatch.h">
<Filter>PowerPC\JitCommon</Filter>
</ClInclude>
<ClInclude Include="PowerPC\JitCommon\JitBase.h"> <ClInclude Include="PowerPC\JitCommon\JitBase.h">
<Filter>PowerPC\JitCommon</Filter> <Filter>PowerPC\JitCommon</Filter>
</ClInclude> </ClInclude>

View File

@ -87,9 +87,24 @@
#define CTX_RIP __ss.__rip #define CTX_RIP __ss.__rip
#elif defined(__linux__) #elif defined(__linux__)
#include <signal.h> #include <signal.h>
#if _M_X86_64
#ifdef ANDROID
#include <asm/sigcontext.h>
typedef struct sigcontext mcontext_t;
typedef struct ucontext
{
uint32_t uc_flags;
struct ucontext* uc_link;
stack_t uc_stack;
mcontext_t uc_mcontext;
// ...
} ucontext_t;
#else
#include <ucontext.h> #include <ucontext.h>
#endif
typedef mcontext_t SContext; typedef mcontext_t SContext;
#if _M_X86_64
#define CTX_RAX gregs[REG_RAX] #define CTX_RAX gregs[REG_RAX]
#define CTX_RBX gregs[REG_RBX] #define CTX_RBX gregs[REG_RBX]
#define CTX_RCX gregs[REG_RCX] #define CTX_RCX gregs[REG_RCX]
@ -108,14 +123,11 @@
#define CTX_R15 gregs[REG_R15] #define CTX_R15 gregs[REG_R15]
#define CTX_RIP gregs[REG_RIP] #define CTX_RIP gregs[REG_RIP]
#elif _M_ARM_64 #elif _M_ARM_64
typedef struct sigcontext SContext;
#define CTX_REG(x) regs[x] #define CTX_REG(x) regs[x]
#define CTX_SP sp #define CTX_SP sp
#define CTX_PC pc #define CTX_PC pc
#elif _M_ARM_32 #elif _M_ARM_32
#include <asm/sigcontext.h>
// Add others if required. // Add others if required.
typedef sigcontext SContext;
#define CTX_PC arm_pc #define CTX_PC arm_pc
#else #else
#warning No context definition for OS #warning No context definition for OS

View File

@ -10,6 +10,7 @@
#include "Common/Thread.h" #include "Common/Thread.h"
#include "Common/x64Analyzer.h" #include "Common/x64Analyzer.h"
#include "Core/MachineContext.h"
#include "Core/MemTools.h" #include "Core/MemTools.h"
#include "Core/HW/Memmap.h" #include "Core/HW/Memmap.h"
#include "Core/PowerPC/JitInterface.h" #include "Core/PowerPC/JitInterface.h"
@ -23,6 +24,8 @@ namespace EMM
#ifdef _WIN32 #ifdef _WIN32
const bool g_exception_handlers_supported = true;
LONG NTAPI Handler(PEXCEPTION_POINTERS pPtrs) LONG NTAPI Handler(PEXCEPTION_POINTERS pPtrs)
{ {
switch (pPtrs->ExceptionRecord->ExceptionCode) switch (pPtrs->ExceptionRecord->ExceptionCode)
@ -91,6 +94,8 @@ void UninstallExceptionHandler() {}
#elif defined(__APPLE__) && !defined(USE_SIGACTION_ON_APPLE) #elif defined(__APPLE__) && !defined(USE_SIGACTION_ON_APPLE)
const bool g_exception_handlers_supported = true;
static void CheckKR(const char* name, kern_return_t kr) static void CheckKR(const char* name, kern_return_t kr)
{ {
if (kr) if (kr)
@ -209,7 +214,9 @@ void InstallExceptionHandler()
void UninstallExceptionHandler() {} void UninstallExceptionHandler() {}
#elif defined(_POSIX_VERSION) #elif defined(_POSIX_VERSION) && !defined(_M_GENERIC)
const bool g_exception_handlers_supported = true;
static void sigsegv_handler(int sig, siginfo_t *info, void *raw_context) static void sigsegv_handler(int sig, siginfo_t *info, void *raw_context)
{ {
@ -275,9 +282,11 @@ void UninstallExceptionHandler()
free(old_stack.ss_sp); free(old_stack.ss_sp);
} }
} }
#else #else // _M_GENERIC or unsupported platform
#error Unsupported x86_64 platform! Report this if you support sigaction const bool g_exception_handlers_supported = false;
void InstallExceptionHandler() {}
void UninstallExceptionHandler() {}
#endif #endif

View File

@ -9,7 +9,7 @@
namespace EMM namespace EMM
{ {
typedef u32 EAddr; extern const bool g_exception_handlers_supported;
void InstallExceptionHandler(); void InstallExceptionHandler();
void UninstallExceptionHandler(); void UninstallExceptionHandler();
} }

View File

@ -37,7 +37,6 @@
#include "Core/PowerPC/Jit64/JitAsm.h" #include "Core/PowerPC/Jit64/JitAsm.h"
#include "Core/PowerPC/Jit64/JitRegCache.h" #include "Core/PowerPC/Jit64/JitRegCache.h"
#include "Core/PowerPC/JitCommon/Jit_Util.h" #include "Core/PowerPC/JitCommon/Jit_Util.h"
#include "Core/PowerPC/JitCommon/JitBackpatch.h"
#include "Core/PowerPC/JitCommon/JitBase.h" #include "Core/PowerPC/JitCommon/JitBase.h"
#include "Core/PowerPC/JitCommon/JitCache.h" #include "Core/PowerPC/JitCommon/JitCache.h"

View File

@ -30,7 +30,6 @@
#include "Core/PowerPC/PPCTables.h" #include "Core/PowerPC/PPCTables.h"
#include "Core/PowerPC/Jit64/JitAsm.h" #include "Core/PowerPC/Jit64/JitAsm.h"
#include "Core/PowerPC/JitCommon/Jit_Util.h" #include "Core/PowerPC/JitCommon/Jit_Util.h"
#include "Core/PowerPC/JitCommon/JitBackpatch.h"
#include "Core/PowerPC/JitCommon/JitBase.h" #include "Core/PowerPC/JitCommon/JitBase.h"
#include "Core/PowerPC/JitCommon/JitCache.h" #include "Core/PowerPC/JitCommon/JitCache.h"
#include "Core/PowerPC/JitILCommon/IR.h" #include "Core/PowerPC/JitILCommon/IR.h"

View File

@ -9,7 +9,6 @@
#include "Core/HW/Memmap.h" #include "Core/HW/Memmap.h"
#include "Core/PowerPC/JitArm32/Jit.h" #include "Core/PowerPC/JitArm32/Jit.h"
#include "Core/PowerPC/JitCommon/JitBackpatch.h"
using namespace ArmGen; using namespace ArmGen;

View File

@ -6,7 +6,6 @@
#include "disasm.h" #include "disasm.h"
#include "Core/PowerPC/JitCommon/JitBackpatch.h"
#include "Core/PowerPC/JitCommon/JitBase.h" #include "Core/PowerPC/JitCommon/JitBase.h"
using namespace Gen; using namespace Gen;

View File

@ -16,6 +16,7 @@
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/CoreTiming.h" #include "Core/CoreTiming.h"
#include "Core/MachineContext.h"
#include "Core/HW/GPFifo.h" #include "Core/HW/GPFifo.h"
#include "Core/HW/Memmap.h" #include "Core/HW/Memmap.h"
#include "Core/PowerPC/CPUCoreBase.h" #include "Core/PowerPC/CPUCoreBase.h"
@ -24,7 +25,6 @@
#include "Core/PowerPC/PPCTables.h" #include "Core/PowerPC/PPCTables.h"
#include "Core/PowerPC/JitCommon/Jit_Util.h" #include "Core/PowerPC/JitCommon/Jit_Util.h"
#include "Core/PowerPC/JitCommon/JitAsmCommon.h" #include "Core/PowerPC/JitCommon/JitAsmCommon.h"
#include "Core/PowerPC/JitCommon/JitBackpatch.h"
#include "Core/PowerPC/JitCommon/JitCache.h" #include "Core/PowerPC/JitCommon/JitCache.h"
#include "Core/PowerPC/JitCommon/TrampolineCache.h" #include "Core/PowerPC/JitCommon/TrampolineCache.h"

View File

@ -6,8 +6,8 @@
#include <string> #include <string>
#include "Common/ChunkFile.h" #include "Common/ChunkFile.h"
#include "Core/MachineContext.h"
#include "Core/PowerPC/CPUCoreBase.h" #include "Core/PowerPC/CPUCoreBase.h"
#include "Core/PowerPC/JitCommon/JitBackpatch.h"
namespace JitInterface namespace JitInterface
{ {