From: Vizzini Date: Sat, 13 Sep 2003 06:17:52 +0000 (+0000) Subject: Patch by skywing: X-Git-Tag: ReactOS-0.1.4~103 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=a9aabdaaf1f25614cee906e73749684aec0c75fc Patch by skywing: - wrote RtlRaiseException user mode implementation - wrote KiRaiseUserExceptionDispatcher/KeRaiseUserException to raise user exceptions from kernel mode - implemented raise STATUS_INVALID_HANDLE-if-debugged in NtClose svn path=/trunk/; revision=6057 --- diff --git a/reactos/lib/ntdll/def/ntdll.def b/reactos/lib/ntdll/def/ntdll.def index 7a86854a2e3..0b2c139e2ce 100644 --- a/reactos/lib/ntdll/def/ntdll.def +++ b/reactos/lib/ntdll/def/ntdll.def @@ -1,4 +1,4 @@ -; $Id: ntdll.def,v 1.111 2003/09/12 17:51:47 vizzini Exp $ +; $Id: ntdll.def,v 1.112 2003/09/13 06:17:51 vizzini Exp $ ; ; ReactOS Operating System ; @@ -32,7 +32,7 @@ DbgUiIssueRemoteBreakin@4 DbgUiRemoteBreakin@0 DbgUiWaitStateChange@8 DbgUserBreakPoint@0 -;KiRaiseUserExceptionDispatcher +KiRaiseUserExceptionDispatcher KiUserApcDispatcher KiUserCallbackDispatcher KiUserExceptionDispatcher diff --git a/reactos/lib/ntdll/def/ntdll.edf b/reactos/lib/ntdll/def/ntdll.edf index e95caa1ae9c..25be82f32c6 100644 --- a/reactos/lib/ntdll/def/ntdll.edf +++ b/reactos/lib/ntdll/def/ntdll.edf @@ -1,4 +1,4 @@ -; $Id: ntdll.edf,v 1.101 2003/09/12 17:51:47 vizzini Exp $ +; $Id: ntdll.edf,v 1.102 2003/09/13 06:17:51 vizzini Exp $ ; ; ReactOS Operating System ; @@ -32,7 +32,7 @@ DbgUiIssueRemoteBreakin=DbgUiIssueRemoteBreakin@4 DbgUiRemoteBreakin=DbgUiRemoteBreakin@0 DbgUiWaitStateChange=DbgUiWaitStateChange@8 DbgUserBreakPoint=DbgUserBreakPoint@0 -;KiRaiseUserExceptionDispatcher +KiRaiseUserExceptionDispatcher=KiRaiseUserExceptionDispatcher@0 KiUserApcDispatcher=KiUserApcDispatcher@20 KiUserCallbackDispatcher=KiUserCallbackDispatcher@12 KiUserExceptionDispatcher=KiUserExceptionDispatcher@8 diff --git a/reactos/lib/ntdll/rtl/exception.c b/reactos/lib/ntdll/rtl/exception.c index c111cd67b9d..16ce69ffe62 100644 --- a/reactos/lib/ntdll/rtl/exception.c +++ b/reactos/lib/ntdll/rtl/exception.c @@ -1,10 +1,13 @@ -/* $Id: exception.c,v 1.15 2003/07/11 13:50:23 royce Exp $ +/* $Id: exception.c,v 1.16 2003/09/13 06:17:51 vizzini Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel * PURPOSE: User-mode exception support * FILE: lib/ntdll/rtl/exception.c - * PROGRAMER: David Welch + * PROGRAMERS: David Welch + * Skywing + * UPDATES: Skywing, 09/11/2003: Implemented RtlRaiseException and + * KiUserRaiseExceptionDispatcher. */ /* INCLUDES *****************************************************************/ @@ -12,6 +15,7 @@ #include #include #include +#include #define NDEBUG #include @@ -55,13 +59,43 @@ KiUserExceptionDispatcher(PEXCEPTION_RECORD ExceptionRecord, RtlRaiseException(&NestedExceptionRecord); } +/* implemented in except.s */ +VOID +RtlpCaptureContext(PCONTEXT Context); + /* - * @unimplemented + * @implemented */ VOID STDCALL RtlRaiseException(PEXCEPTION_RECORD ExceptionRecord) { - DPRINT("RtlRaiseException()\n"); + CONTEXT Context; + NTSTATUS Status; + + RtlpCaptureContext(&Context); + + ExceptionRecord->ExceptionAddress = (PVOID)(*(((PULONG)Context.Ebp)+1)); + Context.ContextFlags = CONTEXT_FULL; + + Status = ZwRaiseException(ExceptionRecord, &Context, TRUE); + RtlRaiseException(ExceptionRecord); + RtlRaiseStatus(Status); /* If we get to this point, something is seriously wrong... */ +} + +/* + * @implemented + */ +VOID STDCALL +KiRaiseUserExceptionDispatcher(VOID) +{ + EXCEPTION_RECORD ExceptionRecord; + + ExceptionRecord.ExceptionCode = ((PTEB)NtCurrentTeb())->ExceptionCode; + ExceptionRecord.ExceptionFlags = 0; + ExceptionRecord.ExceptionRecord = NULL; + ExceptionRecord.NumberParameters = 0; + + RtlRaiseException(&ExceptionRecord); } VOID STDCALL diff --git a/reactos/ntoskrnl/include/internal/ke.h b/reactos/ntoskrnl/include/internal/ke.h index 7fe870f2685..6a5d3dcacff 100644 --- a/reactos/ntoskrnl/include/internal/ke.h +++ b/reactos/ntoskrnl/include/internal/ke.h @@ -61,6 +61,9 @@ KiDeliverNormalApc(VOID); BOOLEAN STDCALL KeRemoveQueueApc (PKAPC Apc); PLIST_ENTRY STDCALL KeRundownQueue(IN PKQUEUE Queue); +VOID STDCALL +KeRaiseUserException(NTSTATUS ExceptionCode); + /* INITIALIZATION FUNCTIONS *************************************************/ diff --git a/reactos/ntoskrnl/include/internal/ldr.h b/reactos/ntoskrnl/include/internal/ldr.h index c1c326aa901..95feea6a3d2 100644 --- a/reactos/ntoskrnl/include/internal/ldr.h +++ b/reactos/ntoskrnl/include/internal/ldr.h @@ -52,6 +52,8 @@ PVOID LdrpGetSystemDllExceptionDispatcher(VOID); PVOID LdrpGetSystemDllCallbackDispatcher(VOID); +PVOID +LdrpGetSystemDllRaiseExceptionDispatcher(VOID); NTSTATUS LdrpMapImage ( HANDLE ProcessHandle, diff --git a/reactos/ntoskrnl/ke/i386/exp.c b/reactos/ntoskrnl/ke/i386/exp.c index 8ec9b024594..40cd51ba43f 100644 --- a/reactos/ntoskrnl/ke/i386/exp.c +++ b/reactos/ntoskrnl/ke/i386/exp.c @@ -20,9 +20,11 @@ * PROJECT: ReactOS kernel * FILE: ntoskrnl/ke/i386/exp.c * PURPOSE: Handling exceptions - * PROGRAMMER: David Welch (welch@cwcom.net) + * PROGRAMMERS: David Welch (welch@cwcom.net) + * Skywing (skywing@valhallalegends.com) * REVISION HISTORY: * ??/??/??: Created + * 09/12/03: KeRaiseUserException added (Skywing). */ /* INCLUDES *****************************************************************/ @@ -40,6 +42,7 @@ #include #include #include +#include #define NDEBUG #include @@ -645,3 +648,19 @@ KeInitExceptions(VOID) set_system_call_gate(0x2d,(int)interrupt_handler2d); set_system_call_gate(0x2e,(int)interrupt_handler2e); } + +/* + * @implemented + */ + +VOID STDCALL +KeRaiseUserException(IN NTSTATUS ExceptionCode) +{ + /* FIXME: This needs SEH */ + + PKTHREAD Thread = KeGetCurrentThread(); + + ProbeForWrite(&Thread->Teb->ExceptionCode, sizeof(NTSTATUS), sizeof(NTSTATUS)); /* NT doesn't check this -- bad? */ + Thread->TrapFrame->Eip = (ULONG_PTR)LdrpGetSystemDllRaiseExceptionDispatcher(); + Thread->Teb->ExceptionCode = ExceptionCode; +} diff --git a/reactos/ntoskrnl/ldr/sysdll.c b/reactos/ntoskrnl/ldr/sysdll.c index 11a8fa65b8a..58ecd32b3a1 100644 --- a/reactos/ntoskrnl/ldr/sysdll.c +++ b/reactos/ntoskrnl/ldr/sysdll.c @@ -7,6 +7,7 @@ * Rex Jolliff (rex@lvcablemodem.com) * UPDATE HISTORY: * DW 26/01/00 Created + * Skywing 09/11/2003 Added support for KiRaiseUserExceptionDispatcher */ /* INCLUDES *****************************************************************/ @@ -27,6 +28,7 @@ static PVOID SystemDllEntryPoint = NULL; static PVOID SystemDllApcDispatcher = NULL; static PVOID SystemDllCallbackDispatcher = NULL; static PVOID SystemDllExceptionDispatcher = NULL; +static PVOID SystemDllRaiseExceptionDispatcher = NULL; /* FUNCTIONS *****************************************************************/ @@ -50,6 +52,11 @@ PVOID LdrpGetSystemDllApcDispatcher(VOID) return(SystemDllApcDispatcher); } +PVOID LdrpGetSystemDllRaiseExceptionDispatcher(VOID) +{ + return(SystemDllRaiseExceptionDispatcher); +} + NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle, PVOID* LdrStartupAddr) /* @@ -276,6 +283,27 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle, return (Status); } } + + /* + * Retrieve the offset of the raise exception dispatcher from NTDLL + */ + if (SystemDllRaiseExceptionDispatcher == NULL) + { + RtlInitAnsiString (&ProcedureName, + "KiRaiseUserExceptionDispatcher"); + Status = LdrGetProcedureAddress ((PVOID)ImageBase, + &ProcedureName, + 0, + &SystemDllRaiseExceptionDispatcher); + if (!NT_SUCCESS(Status)) + { + DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status); + KeDetachProcess(); + ObDereferenceObject(Process); + ZwClose(NTDllSectionHandle); + return (Status); + } + } KeDetachProcess(); ObDereferenceObject(Process); diff --git a/reactos/ntoskrnl/ob/handle.c b/reactos/ntoskrnl/ob/handle.c index 558e14f9fe6..ee0281b4f45 100644 --- a/reactos/ntoskrnl/ob/handle.c +++ b/reactos/ntoskrnl/ob/handle.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: handle.c,v 1.48 2003/08/18 10:20:57 hbirr Exp $ +/* $Id: handle.c,v 1.49 2003/09/13 06:17:52 vizzini Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -757,6 +757,8 @@ NTSTATUS STDCALL NtClose(HANDLE Handle) ObjectBody = ObDeleteHandle(PsGetCurrentProcess(), Handle); if (ObjectBody == NULL) { + if(((PEPROCESS)(KeGetCurrentThread()->ApcState.Process))->ExceptionPort) + KeRaiseUserException(STATUS_INVALID_HANDLE); return(STATUS_INVALID_HANDLE); }