mirror of
https://github.com/reactos/reactos.git
synced 2025-07-23 04:53:40 +00:00
Major refactoring of the exception handling code + misc fixes:
- Fix/add prototypes for RtlCaptureContext, RtlDispatchException and RtlUnwind - Fix EXCEPTION_REGISTRATION_RECORD structure and PEXCEPTION_ROUTINE - Add w32api excpt.h (based on mingw) with PSDK compatibility fixes - Fix seriously broken User-Mode Ldr thunk and APC Callback prototypes - Fix KiUserExceptionDispatcher - Remove useless NTDLL entrypoint - Implement NTDLL Ki* callbacks in ASM - Implement RtlCaptureContext - Fix RtlRaiseException to handle cases when a user-mode debugger is present - Fix RtlRaiseStatus as above, plus set the exception address and capture context - Little cleanup of RTL headers - Implement RtlpGetStackLimits, RtlpGetExceptionList, RtlpSetExceptionList, RtlpGetExceptionAddress in ASM - Fix RtlDispatchException, add cases for exceptions in the DPC stack and validate the validity of the exception frames. Add support for exception logging by the global flag. Use TRAP_FRAME/EXCPETION_FRAME instead of Context. - Fix RtlUnwind logic, support cases where it's called with custom arguments instead of NULL. - Reimplement RtlpCaptureContext to work properly, convert exception handler calling functions to INTEL syntax and fix some bugs (like checking for the right unwind flag, clearing volatile register values, etc. Also use some optimizations to increase speed. - Modify some kernel functions (like KeContextToTrapFrame, KiDispatchException, KiInitializeUserApc, etc.) to support a PKEXCEPTION_FRAME for future PPC compatibility. - Reimplement RtlCaptureUnicodeString/FreeUnicodeString as inlined probe macros and optimize them. - Export ExRaiseStatus/Exception as Rtl* - Reimplement NtContinue to have more platform-independent code, and to protect and validate user-mode context and parameters with SEH. - Implement KiRaiseException, add SEH to all user-mode parameters and when copying data to the user-mode stack. - Fix KiInitializeUserApc to use KeTrapFrameToContext, to save the debug registers, not to deliver APCs during v86 mode, and to protect user-mode stack operations in SEH and probing. Also make it generate the proper stack for the user-mode callback. - Implement KiUnexpectedInterrupt and KiCoprocessorError - Reimplement NtRaiseException in ASM to take advantage of optimizations due to the trap frame being in the stack when called through System call interface. - Fix Ntcontinue to respect AlertThread paramter - Fix some functiosn to return with KiServiceExit2 instead of KiServiceExit when required/needed - Fix KiDispatchException's logic, fix hacks when calling KeUserExceptionDispatcher, use correct context flags,... - Make NTDLL Ki* callbacks have SEH to protect them and return to kernel-mode with notification of any exceptions (the kernel-mode code to handle this isn't written yet though) svn path=/trunk/; revision=17811
This commit is contained in:
parent
801ad7223f
commit
b9020b11dd
48 changed files with 1839 additions and 1345 deletions
|
@ -1,8 +1,9 @@
|
|||
/* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* PURPOSE: User-mode exception support
|
||||
* PROJECT: ReactOS Runtime Library
|
||||
* PURPOSE: User-Mode Exception Support
|
||||
* FILE: lib/rtl/exception.c
|
||||
* PROGRAMERS: David Welch <welch@cwcom.net>
|
||||
* PROGRAMERS: Alex Ionescu (alex@relsoft.net)
|
||||
* David Welch <welch@cwcom.net>
|
||||
* Skywing <skywing@valhallalegends.com>
|
||||
* KJK::Hyperion <noog@libero.it>
|
||||
*/
|
||||
|
@ -16,72 +17,110 @@
|
|||
|
||||
/* FUNCTIONS ***************************************************************/
|
||||
|
||||
/* implemented in except.s */
|
||||
VOID
|
||||
RtlpCaptureContext(PCONTEXT Context);
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
*/
|
||||
NTSTATUS
|
||||
STDCALL
|
||||
RtlDispatchException(
|
||||
PEXCEPTION_RECORD pExcptRec,
|
||||
CONTEXT * pContext
|
||||
)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
return STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
*/
|
||||
VOID
|
||||
STDCALL
|
||||
RtlGetCallersAddress(
|
||||
OUT PVOID *CallersAddress,
|
||||
OUT PVOID *CallersCaller
|
||||
)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
VOID STDCALL
|
||||
VOID
|
||||
STDCALL
|
||||
RtlRaiseException(PEXCEPTION_RECORD ExceptionRecord)
|
||||
{
|
||||
CONTEXT Context;
|
||||
NTSTATUS Status;
|
||||
CONTEXT Context;
|
||||
NTSTATUS Status;
|
||||
DPRINT1("RtlRaiseException(Status %p)\n", ExceptionRecord);
|
||||
|
||||
RtlpCaptureContext(&Context);
|
||||
/* Capture the context */
|
||||
RtlCaptureContext(&Context);
|
||||
|
||||
ExceptionRecord->ExceptionAddress = (PVOID)(*(((PULONG)Context.Ebp)+1));
|
||||
Context.ContextFlags = CONTEXT_FULL;
|
||||
/* Save the exception address */
|
||||
ExceptionRecord->ExceptionAddress = RtlpGetExceptionAddress();
|
||||
DPRINT1("ExceptionAddress %p\n", ExceptionRecord->ExceptionAddress);
|
||||
|
||||
Status = NtRaiseException(ExceptionRecord, &Context, TRUE);
|
||||
RtlRaiseException(ExceptionRecord);
|
||||
RtlRaiseStatus(Status);
|
||||
/* Write the context flag */
|
||||
Context.ContextFlags = CONTEXT_FULL;
|
||||
|
||||
/* Check if we're being debugged (user-mode only) */
|
||||
if (!RtlpCheckForActiveDebugger())
|
||||
{
|
||||
/* Raise an exception immediately */
|
||||
ZwRaiseException(ExceptionRecord, &Context, TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Dispatch the exception and check if we should continue */
|
||||
if (RtlDispatchException(ExceptionRecord, &Context))
|
||||
{
|
||||
/* Raise the exception */
|
||||
Status = ZwRaiseException(ExceptionRecord, &Context, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Continue, go back to previous context */
|
||||
ZwContinue(&Context, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/* If we returned, raise a status */
|
||||
RtlRaiseStatus(Status);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
VOID STDCALL
|
||||
VOID
|
||||
STDCALL
|
||||
RtlRaiseStatus(NTSTATUS Status)
|
||||
{
|
||||
EXCEPTION_RECORD ExceptionRecord;
|
||||
EXCEPTION_RECORD ExceptionRecord;
|
||||
CONTEXT Context;
|
||||
DPRINT1("RtlRaiseStatus(Status 0x%.08x)\n", Status);
|
||||
|
||||
DPRINT("RtlRaiseStatus(Status 0x%.08x)\n", Status);
|
||||
/* Capture the context */
|
||||
RtlCaptureContext(&Context);
|
||||
|
||||
ExceptionRecord.ExceptionCode = Status;
|
||||
ExceptionRecord.ExceptionRecord = NULL;
|
||||
ExceptionRecord.NumberParameters = 0;
|
||||
ExceptionRecord.ExceptionFlags = EXCEPTION_NONCONTINUABLE;
|
||||
RtlRaiseException (& ExceptionRecord);
|
||||
/* Add one argument to ESP */
|
||||
Context.Esp += sizeof(PVOID);
|
||||
|
||||
/* Create an exception record */
|
||||
ExceptionRecord.ExceptionAddress = RtlpGetExceptionAddress();
|
||||
ExceptionRecord.ExceptionCode = Status;
|
||||
ExceptionRecord.ExceptionRecord = NULL;
|
||||
ExceptionRecord.NumberParameters = 0;
|
||||
ExceptionRecord.ExceptionFlags = EXCEPTION_NONCONTINUABLE;
|
||||
|
||||
/* Write the context flag */
|
||||
Context.ContextFlags = CONTEXT_FULL;
|
||||
|
||||
/* Check if we're being debugged (user-mode only) */
|
||||
if (!RtlpCheckForActiveDebugger())
|
||||
{
|
||||
/* Raise an exception immediately */
|
||||
ZwRaiseException(&ExceptionRecord, &Context, TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Dispatch the exception */
|
||||
RtlDispatchException(&ExceptionRecord, &Context);
|
||||
|
||||
/* Raise exception if we got here */
|
||||
Status = ZwRaiseException(&ExceptionRecord, &Context, FALSE);
|
||||
}
|
||||
|
||||
/* If we returned, raise a status */
|
||||
RtlRaiseStatus(Status);
|
||||
}
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
*/
|
||||
USHORT
|
||||
STDCALL
|
||||
RtlCaptureStackBackTrace(IN ULONG FramesToSkip,
|
||||
IN ULONG FramesToCapture,
|
||||
OUT PVOID *BackTrace,
|
||||
OUT PULONG BackTraceHash OPTIONAL)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -89,15 +128,12 @@ RtlRaiseStatus(NTSTATUS Status)
|
|||
*/
|
||||
ULONG
|
||||
STDCALL
|
||||
RtlWalkFrameChain (
|
||||
OUT PVOID *Callers,
|
||||
IN ULONG Count,
|
||||
IN ULONG Flags
|
||||
)
|
||||
RtlWalkFrameChain(OUT PVOID *Callers,
|
||||
IN ULONG Count,
|
||||
IN ULONG Flags)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
return 0;
|
||||
UNIMPLEMENTED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* EOF */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue