1 /* COPYRIGHT: See COPYING in the top level directory
2 * PROJECT: ReactOS Runtime Library
3 * PURPOSE: User-Mode Exception Support
4 * FILE: lib/rtl/exception.c
5 * PROGRAMERS: Alex Ionescu (alex@relsoft.net)
6 * David Welch <welch@cwcom.net>
7 * Skywing <skywing@valhallalegends.com>
8 * KJK::Hyperion <noog@libero.it>
11 /* INCLUDES *****************************************************************/
18 /* FUNCTIONS ***************************************************************/
25 RtlRaiseException(PEXCEPTION_RECORD ExceptionRecord
)
29 DPRINT1("RtlRaiseException(Status %p)\n", ExceptionRecord
);
31 /* Capture the context */
32 RtlCaptureContext(&Context
);
34 /* Save the exception address */
35 ExceptionRecord
->ExceptionAddress
= RtlpGetExceptionAddress();
36 DPRINT1("ExceptionAddress %p\n", ExceptionRecord
->ExceptionAddress
);
38 /* Write the context flag */
39 Context
.ContextFlags
= CONTEXT_FULL
;
41 /* Check if we're being debugged (user-mode only) */
42 if (!RtlpCheckForActiveDebugger(TRUE
))
44 /* Raise an exception immediately */
45 Status
= ZwRaiseException(ExceptionRecord
, &Context
, TRUE
);
49 /* Dispatch the exception and check if we should continue */
50 if (RtlDispatchException(ExceptionRecord
, &Context
))
52 /* Raise the exception */
53 Status
= ZwRaiseException(ExceptionRecord
, &Context
, FALSE
);
57 /* Continue, go back to previous context */
58 Status
= ZwContinue(&Context
, FALSE
);
62 /* If we returned, raise a status */
63 RtlRaiseStatus(Status
);
71 RtlRaiseStatus(NTSTATUS Status
)
73 EXCEPTION_RECORD ExceptionRecord
;
75 DPRINT1("RtlRaiseStatus(Status 0x%.08lx)\n", Status
);
77 /* Capture the context */
78 RtlCaptureContext(&Context
);
80 /* Add one argument to ESP */
81 Context
.Esp
+= sizeof(PVOID
);
83 /* Create an exception record */
84 ExceptionRecord
.ExceptionAddress
= RtlpGetExceptionAddress();
85 ExceptionRecord
.ExceptionCode
= Status
;
86 ExceptionRecord
.ExceptionRecord
= NULL
;
87 ExceptionRecord
.NumberParameters
= 0;
88 ExceptionRecord
.ExceptionFlags
= EXCEPTION_NONCONTINUABLE
;
90 /* Write the context flag */
91 Context
.ContextFlags
= CONTEXT_FULL
;
93 /* Check if we're being debugged (user-mode only) */
94 if (!RtlpCheckForActiveDebugger(TRUE
))
96 /* Raise an exception immediately */
97 ZwRaiseException(&ExceptionRecord
, &Context
, TRUE
);
101 /* Dispatch the exception */
102 RtlDispatchException(&ExceptionRecord
, &Context
);
104 /* Raise exception if we got here */
105 Status
= ZwRaiseException(&ExceptionRecord
, &Context
, FALSE
);
108 /* If we returned, raise a status */
109 RtlRaiseStatus(Status
);
117 RtlCaptureStackBackTrace(IN ULONG FramesToSkip
,
118 IN ULONG FramesToCapture
,
119 OUT PVOID
*BackTrace
,
120 OUT PULONG BackTraceHash OPTIONAL
)
131 RtlWalkFrameChain(OUT PVOID
*Callers
,