From 59022e581892dd393285db5e9c7ab3de9ff0899f Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 28 Oct 2003 21:57:24 +0000 Subject: [PATCH] Restored emulation of protected instructions in 32-bit code when running with a Win9x version. --- dlls/kernel/instr.c | 2 ++ dlls/kernel/wowthunk.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/dlls/kernel/instr.c b/dlls/kernel/instr.c index c67e18333f3..80496771aeb 100644 --- a/dlls/kernel/instr.c +++ b/dlls/kernel/instr.c @@ -688,6 +688,7 @@ DWORD INSTR_EmulateInstruction( EXCEPTION_RECORD *rec, CONTEXT86 *context ) break; /* Unable to emulate it */ case 0xcd: /* int */ + if (IS_SELECTOR_SYSTEM(context->SegCs)) break; /* don't emulate it in 32-bit code */ if (!Dosvm.EmulateInterruptPM && !DPMI_LoadDosSystem()) { ERR("could not initialize interrupt handling\n"); @@ -701,6 +702,7 @@ DWORD INSTR_EmulateInstruction( EXCEPTION_RECORD *rec, CONTEXT86 *context ) break; /* Unable to emulate it */ case 0xcf: /* iret */ + if (IS_SELECTOR_SYSTEM(context->SegCs)) break; /* don't emulate it in 32-bit code */ if (long_op) { DWORD *stack = get_stack( context ); diff --git a/dlls/kernel/wowthunk.c b/dlls/kernel/wowthunk.c index 93909a92733..a95e8f84b57 100644 --- a/dlls/kernel/wowthunk.c +++ b/dlls/kernel/wowthunk.c @@ -91,6 +91,7 @@ extern BYTE Call16_End; extern void RELAY16_InitDebugLists(void); +static LONG CALLBACK vectored_handler( EXCEPTION_POINTERS *ptrs ); static SEGPTR call16_ret_addr; /* segptr to CallTo16_Ret routine */ /*********************************************************************** @@ -114,6 +115,9 @@ BOOL WOWTHUNK_Init(void) MAKESEGPTR( codesel, (char*)CALL32_CBClientEx_Ret - (char*)Call16_Ret_Start ); if (TRACE_ON(relay) || TRACE_ON(snoop)) RELAY16_InitDebugLists(); + + /* setup emulation of protected instructions from 32-bit code (only for Win9x versions) */ + if (GetVersion() & 0x80000000) RtlAddVectoredExceptionHandler( TRUE, vectored_handler ); return TRUE; } @@ -233,6 +237,28 @@ static DWORD vm86_handler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECO } +/*********************************************************************** + * vectored_handler + * + * Vectored exception handler used to emulate protected instructions + * from 32-bit code. + */ +static LONG CALLBACK vectored_handler( EXCEPTION_POINTERS *ptrs ) +{ + EXCEPTION_RECORD *record = ptrs->ExceptionRecord; + CONTEXT *context = ptrs->ContextRecord; + + if (IS_SELECTOR_SYSTEM(context->SegCs) && + (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION || + record->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION)) + { + if (INSTR_EmulateInstruction( record, context ) == ExceptionContinueExecution) + return EXCEPTION_CONTINUE_EXECUTION; + } + return EXCEPTION_CONTINUE_SEARCH; +} + + #else /* __i386__ */ BOOL WOWTHUNK_Init(void)