mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 01:15:09 +00:00
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
This commit is contained in:
parent
4eec93eae2
commit
a9aabdaaf1
8 changed files with 98 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <welch@cwcom.net>
|
||||
* PROGRAMERS: David Welch <welch@cwcom.net>
|
||||
* Skywing <skywing@valhallalegends.com>
|
||||
* UPDATES: Skywing, 09/11/2003: Implemented RtlRaiseException and
|
||||
* KiUserRaiseExceptionDispatcher.
|
||||
*/
|
||||
|
||||
/* INCLUDES *****************************************************************/
|
||||
|
@ -12,6 +15,7 @@
|
|||
#include <ddk/ntddk.h>
|
||||
#include <windows.h>
|
||||
#include <string.h>
|
||||
#include <napi/teb.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
@ -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
|
||||
|
|
|
@ -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 *************************************************/
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ PVOID
|
|||
LdrpGetSystemDllExceptionDispatcher(VOID);
|
||||
PVOID
|
||||
LdrpGetSystemDllCallbackDispatcher(VOID);
|
||||
PVOID
|
||||
LdrpGetSystemDllRaiseExceptionDispatcher(VOID);
|
||||
NTSTATUS
|
||||
LdrpMapImage (
|
||||
HANDLE ProcessHandle,
|
||||
|
|
|
@ -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 <ntdll/ldr.h>
|
||||
#include <internal/safe.h>
|
||||
#include <internal/kd.h>
|
||||
#include <internal/ldr.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <internal/debug.h>
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue