set eol-style:native
[reactos.git] / reactos / lib / rtl / exception.c
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>
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <rtl.h>
14
15 #define NDEBUG
16 #include <debug.h>
17
18 /* FUNCTIONS ***************************************************************/
19
20 /*
21 * @implemented
22 */
23 VOID
24 NTAPI
25 RtlRaiseException(PEXCEPTION_RECORD ExceptionRecord)
26 {
27 CONTEXT Context;
28 NTSTATUS Status;
29 DPRINT1("RtlRaiseException(Status %p)\n", ExceptionRecord);
30
31 /* Capture the context */
32 RtlCaptureContext(&Context);
33
34 /* Save the exception address */
35 ExceptionRecord->ExceptionAddress = RtlpGetExceptionAddress();
36 DPRINT1("ExceptionAddress %p\n", ExceptionRecord->ExceptionAddress);
37
38 /* Write the context flag */
39 Context.ContextFlags = CONTEXT_FULL;
40
41 /* Check if we're being debugged (user-mode only) */
42 if (!RtlpCheckForActiveDebugger(TRUE))
43 {
44 /* Raise an exception immediately */
45 Status = ZwRaiseException(ExceptionRecord, &Context, TRUE);
46 }
47 else
48 {
49 /* Dispatch the exception and check if we should continue */
50 if (RtlDispatchException(ExceptionRecord, &Context))
51 {
52 /* Raise the exception */
53 Status = ZwRaiseException(ExceptionRecord, &Context, FALSE);
54 }
55 else
56 {
57 /* Continue, go back to previous context */
58 Status = ZwContinue(&Context, FALSE);
59 }
60 }
61
62 /* If we returned, raise a status */
63 RtlRaiseStatus(Status);
64 }
65
66 /*
67 * @implemented
68 */
69 VOID
70 NTAPI
71 RtlRaiseStatus(NTSTATUS Status)
72 {
73 EXCEPTION_RECORD ExceptionRecord;
74 CONTEXT Context;
75 DPRINT1("RtlRaiseStatus(Status 0x%.08lx)\n", Status);
76
77 /* Capture the context */
78 RtlCaptureContext(&Context);
79
80 /* Add one argument to ESP */
81 Context.Esp += sizeof(PVOID);
82
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;
89
90 /* Write the context flag */
91 Context.ContextFlags = CONTEXT_FULL;
92
93 /* Check if we're being debugged (user-mode only) */
94 if (!RtlpCheckForActiveDebugger(TRUE))
95 {
96 /* Raise an exception immediately */
97 ZwRaiseException(&ExceptionRecord, &Context, TRUE);
98 }
99 else
100 {
101 /* Dispatch the exception */
102 RtlDispatchException(&ExceptionRecord, &Context);
103
104 /* Raise exception if we got here */
105 Status = ZwRaiseException(&ExceptionRecord, &Context, FALSE);
106 }
107
108 /* If we returned, raise a status */
109 RtlRaiseStatus(Status);
110 }
111
112 /*
113 * @unimplemented
114 */
115 USHORT
116 NTAPI
117 RtlCaptureStackBackTrace(IN ULONG FramesToSkip,
118 IN ULONG FramesToCapture,
119 OUT PVOID *BackTrace,
120 OUT PULONG BackTraceHash OPTIONAL)
121 {
122 UNIMPLEMENTED;
123 return 0;
124 }
125
126 /*
127 * @unimplemented
128 */
129 ULONG
130 NTAPI
131 RtlWalkFrameChain(OUT PVOID *Callers,
132 IN ULONG Count,
133 IN ULONG Flags)
134 {
135 UNIMPLEMENTED;
136 return 0;
137 }
138
139 /* EOF */