mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-25 01:57:47 +01:00
add testing code for privileged instructions
This commit is contained in:
parent
7febf01343
commit
e0e59cd9fa
@ -64,6 +64,7 @@ typedef struct CNCDDRAWCONFIG
|
|||||||
BOOL fix_alt_key_stuck;
|
BOOL fix_alt_key_stuck;
|
||||||
BOOL fix_not_responding;
|
BOOL fix_not_responding;
|
||||||
BOOL no_compat_warning;
|
BOOL no_compat_warning;
|
||||||
|
BOOL ignore_exceptions;
|
||||||
BOOL wine_allow_resize;
|
BOOL wine_allow_resize;
|
||||||
int guard_lines;
|
int guard_lines;
|
||||||
int max_resolutions;
|
int max_resolutions;
|
||||||
|
@ -77,6 +77,7 @@ void cfg_load()
|
|||||||
GET_BOOL(GameHandlesClose, "game_handles_close", FALSE);
|
GET_BOOL(GameHandlesClose, "game_handles_close", FALSE);
|
||||||
GET_BOOL(g_config.fix_not_responding, "fix_not_responding", FALSE);
|
GET_BOOL(g_config.fix_not_responding, "fix_not_responding", FALSE);
|
||||||
GET_BOOL(g_config.no_compat_warning, "no_compat_warning", FALSE);
|
GET_BOOL(g_config.no_compat_warning, "no_compat_warning", FALSE);
|
||||||
|
GET_BOOL(g_config.ignore_exceptions, "ignore_exceptions", FALSE);
|
||||||
GET_BOOL(g_config.wine_allow_resize, "wine_allow_resize", FALSE);
|
GET_BOOL(g_config.wine_allow_resize, "wine_allow_resize", FALSE);
|
||||||
GET_INT(g_config.guard_lines, "guard_lines", 200);
|
GET_INT(g_config.guard_lines, "guard_lines", 200);
|
||||||
GET_INT(g_config.max_resolutions, "max_resolutions", 0);
|
GET_INT(g_config.max_resolutions, "max_resolutions", 0);
|
||||||
@ -309,6 +310,7 @@ static void cfg_create_ini()
|
|||||||
"game_handles_close=false\n"
|
"game_handles_close=false\n"
|
||||||
"fix_not_responding=false\n"
|
"fix_not_responding=false\n"
|
||||||
"no_compat_warning=false\n"
|
"no_compat_warning=false\n"
|
||||||
|
"ignore_exceptions=false\n"
|
||||||
"wine_allow_resize=false\n"
|
"wine_allow_resize=false\n"
|
||||||
"guard_lines=200\n"
|
"guard_lines=200\n"
|
||||||
"max_resolutions=0\n"
|
"max_resolutions=0\n"
|
||||||
|
85
src/debug.c
85
src/debug.c
@ -14,6 +14,8 @@
|
|||||||
#include "versionhelpers.h"
|
#include "versionhelpers.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "dllmain.h"
|
#include "dllmain.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "patch.h"
|
||||||
|
|
||||||
|
|
||||||
double g_dbg_frame_time = 0;
|
double g_dbg_frame_time = 0;
|
||||||
@ -34,6 +36,16 @@ static BOOL g_dbg_log_rotate;
|
|||||||
static int g_dbg_crash_count = 0;
|
static int g_dbg_crash_count = 0;
|
||||||
|
|
||||||
LONG WINAPI dbg_exception_handler(EXCEPTION_POINTERS* exception)
|
LONG WINAPI dbg_exception_handler(EXCEPTION_POINTERS* exception)
|
||||||
|
{
|
||||||
|
if (!exception || !exception->ExceptionRecord)
|
||||||
|
{
|
||||||
|
if (g_dbg_exception_filter)
|
||||||
|
return g_dbg_exception_filter(exception);
|
||||||
|
|
||||||
|
return EXCEPTION_EXECUTE_HANDLER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exception->ExceptionRecord->ExceptionCode != STATUS_PRIVILEGED_INSTRUCTION || !g_config.ignore_exceptions)
|
||||||
{
|
{
|
||||||
g_dbg_crash_count++;
|
g_dbg_crash_count++;
|
||||||
|
|
||||||
@ -65,9 +77,8 @@ LONG WINAPI dbg_exception_handler(EXCEPTION_POINTERS* exception)
|
|||||||
|
|
||||||
CloseHandle(dmp);
|
CloseHandle(dmp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (exception && exception->ExceptionRecord)
|
|
||||||
{
|
|
||||||
HMODULE mod = NULL;
|
HMODULE mod = NULL;
|
||||||
char filename[MAX_PATH] = { 0 };
|
char filename[MAX_PATH] = { 0 };
|
||||||
|
|
||||||
@ -88,6 +99,36 @@ LONG WINAPI dbg_exception_handler(EXCEPTION_POINTERS* exception)
|
|||||||
(int)exception->ExceptionRecord->ExceptionAddress - (int)mod,
|
(int)exception->ExceptionRecord->ExceptionAddress - (int)mod,
|
||||||
exception->ExceptionRecord->ExceptionCode,
|
exception->ExceptionRecord->ExceptionCode,
|
||||||
filename);
|
filename);
|
||||||
|
|
||||||
|
if (g_config.ignore_exceptions &&
|
||||||
|
exception->ContextRecord &&
|
||||||
|
exception->ExceptionRecord->ExceptionAddress &&
|
||||||
|
exception->ExceptionRecord->ExceptionCode == STATUS_PRIVILEGED_INSTRUCTION)
|
||||||
|
{
|
||||||
|
size_t size = 0;
|
||||||
|
BYTE* addr = exception->ExceptionRecord->ExceptionAddress;
|
||||||
|
switch (*addr)
|
||||||
|
{
|
||||||
|
case 0xE4: // IN ib
|
||||||
|
case 0xE5: // IN id
|
||||||
|
case 0xE6: // OUT ib
|
||||||
|
case 0xE7: // OUT ib
|
||||||
|
size = 2;
|
||||||
|
break;
|
||||||
|
case 0xEC: // IN ib
|
||||||
|
case 0xED: // IN id
|
||||||
|
case 0xEE: // OUT
|
||||||
|
case 0xEF: // OUT
|
||||||
|
size = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size)
|
||||||
|
{
|
||||||
|
exception->ContextRecord->Eip += size;
|
||||||
|
patch_clear((void*)addr, 0x90, (char*)addr + size);
|
||||||
|
return EXCEPTION_CONTINUE_EXECUTION;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_dbg_exception_filter)
|
if (g_dbg_exception_filter)
|
||||||
@ -111,6 +152,46 @@ void __cdecl dbg_invoke_watson(
|
|||||||
|
|
||||||
TerminateProcess(GetCurrentProcess(), STATUS_INVALID_CRUNTIME_PARAMETER);
|
TerminateProcess(GetCurrentProcess(), STATUS_INVALID_CRUNTIME_PARAMETER);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
LONG WINAPI dbg_exception_handler(EXCEPTION_POINTERS* exception)
|
||||||
|
{
|
||||||
|
if (exception &&
|
||||||
|
exception->ContextRecord &&
|
||||||
|
exception->ExceptionRecord &&
|
||||||
|
exception->ExceptionRecord->ExceptionAddress &&
|
||||||
|
exception->ExceptionRecord->ExceptionCode == STATUS_PRIVILEGED_INSTRUCTION)
|
||||||
|
{
|
||||||
|
size_t size = 0;
|
||||||
|
BYTE* addr = exception->ExceptionRecord->ExceptionAddress;
|
||||||
|
switch (*addr)
|
||||||
|
{
|
||||||
|
case 0xE4: // IN ib
|
||||||
|
case 0xE5: // IN id
|
||||||
|
case 0xE6: // OUT ib
|
||||||
|
case 0xE7: // OUT ib
|
||||||
|
size = 2;
|
||||||
|
break;
|
||||||
|
case 0xEC: // IN ib
|
||||||
|
case 0xED: // IN id
|
||||||
|
case 0xEE: // OUT
|
||||||
|
case 0xEF: // OUT
|
||||||
|
size = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size)
|
||||||
|
{
|
||||||
|
exception->ContextRecord->Eip += size;
|
||||||
|
patch_clear((void*)addr, 0x90, (char*)addr + size);
|
||||||
|
return EXCEPTION_CONTINUE_EXECUTION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_dbg_exception_filter)
|
||||||
|
return g_dbg_exception_filter(exception);
|
||||||
|
|
||||||
|
return EXCEPTION_EXECUTE_HANDLER;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void dbg_init()
|
void dbg_init()
|
||||||
|
@ -43,9 +43,14 @@ BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
|
|||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
dbg_init();
|
dbg_init();
|
||||||
g_dbg_exception_filter = real_SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)dbg_exception_handler);
|
g_dbg_exception_filter = real_SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)dbg_exception_handler);
|
||||||
#endif
|
|
||||||
|
|
||||||
cfg_load();
|
cfg_load();
|
||||||
|
#else
|
||||||
|
cfg_load();
|
||||||
|
if (g_config.ignore_exceptions)
|
||||||
|
{
|
||||||
|
g_dbg_exception_filter = real_SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)dbg_exception_handler);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user