ReactOS 0.4.15-dev-8021-g7ce96fd
except.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for except.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI KiContinuePreviousModeUser (_In_ PCONTEXT Context, _Out_ PKEXCEPTION_FRAME ExceptionFrame, _Out_ PKTRAP_FRAME TrapFrame)
 
NTSTATUS NTAPI KiContinue (IN PCONTEXT Context, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
 
NTSTATUS NTAPI KiRaiseException (_In_ PEXCEPTION_RECORD ExceptionRecord, _In_ PCONTEXT Context, _Out_ PKEXCEPTION_FRAME ExceptionFrame, _Out_ PKTRAP_FRAME TrapFrame, _In_ BOOLEAN SearchFrames)
 
NTSTATUS NTAPI NtRaiseException (_In_ PEXCEPTION_RECORD ExceptionRecord, _In_ PCONTEXT Context, _In_ BOOLEAN FirstChance)
 
NTSTATUS NTAPI NtContinue (_In_ PCONTEXT Context, _In_ BOOLEAN TestAlert)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file except.c.

Function Documentation

◆ KiContinue()

NTSTATUS NTAPI KiContinue ( IN PCONTEXT  Context,
IN PKEXCEPTION_FRAME  ExceptionFrame,
IN PKTRAP_FRAME  TrapFrame 
)

Definition at line 42 of file except.c.

45{
49
50 /* Raise to APC_LEVEL, only if needed */
52
53 /* Set up SEH to validate the context */
55 {
56 /* Check the previous mode */
58 {
59 /* Validate from user-mode */
61 ExceptionFrame,
62 TrapFrame);
63 }
64 else
65 {
66 /* Convert the context into Exception/Trap Frames */
68 ExceptionFrame,
69 TrapFrame,
70 Context->ContextFlags,
72 }
73 }
75 {
76 /* Save the exception code */
78 }
80
81 /* Lower the IRQL if needed */
83
84 /* Return status */
85 return Status;
86}
LONG NTSTATUS
Definition: precomp.h:26
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
Status
Definition: gdiplustypes.h:25
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define KernelMode
Definition: asm.h:34
#define KeGetPreviousMode()
Definition: ketypes.h:1115
VOID NTAPI KeContextToTrapFrame(PCONTEXT Context, PKEXCEPTION_FRAME ExeptionFrame, PKTRAP_FRAME TrapFrame, ULONG ContextFlags, KPROCESSOR_MODE PreviousMode)
VOID NTAPI KiContinuePreviousModeUser(_In_ PCONTEXT Context, _Out_ PKEXCEPTION_FRAME ExceptionFrame, _Out_ PKTRAP_FRAME TrapFrame)
Definition: except.c:20
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define STATUS_SUCCESS
Definition: shellext.h:65
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103

Referenced by NtContinue().

◆ KiContinuePreviousModeUser()

VOID NTAPI KiContinuePreviousModeUser ( _In_ PCONTEXT  Context,
_Out_ PKEXCEPTION_FRAME  ExceptionFrame,
_Out_ PKTRAP_FRAME  TrapFrame 
)

Definition at line 20 of file except.c.

24{
25 CONTEXT LocalContext;
26
27 /* We'll have to make a copy and probe it */
28 ProbeForRead(Context, sizeof(CONTEXT), sizeof(ULONG));
29 RtlCopyMemory(&LocalContext, Context, sizeof(CONTEXT));
30 Context = &LocalContext;
31
32 /* Convert the context into Exception/Trap Frames */
33 KeContextToTrapFrame(&LocalContext,
34 ExceptionFrame,
35 TrapFrame,
36 LocalContext.ContextFlags,
37 UserMode);
38}
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define UserMode
Definition: asm.h:35
ULONG ContextFlags
Definition: nt_native.h:1426
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59

Referenced by KiContinue().

◆ KiRaiseException()

NTSTATUS NTAPI KiRaiseException ( _In_ PEXCEPTION_RECORD  ExceptionRecord,
_In_ PCONTEXT  Context,
_Out_ PKEXCEPTION_FRAME  ExceptionFrame,
_Out_ PKTRAP_FRAME  TrapFrame,
_In_ BOOLEAN  SearchFrames 
)

Definition at line 90 of file except.c.

96{
98 CONTEXT LocalContext;
99 EXCEPTION_RECORD LocalExceptionRecord;
100 ULONG ParameterCount, Size;
101
102 /* Check if we need to probe */
104 {
105 /* Set up SEH */
107 {
108 /* Probe the context */
109 ProbeForRead(Context, sizeof(CONTEXT), sizeof(ULONG));
110
111 /* Probe the Exception Record */
112 ProbeForRead(ExceptionRecord,
113 FIELD_OFFSET(EXCEPTION_RECORD, NumberParameters) +
114 sizeof(ULONG),
115 sizeof(ULONG));
116
117 /* Validate the maximum parameters */
118 if ((ParameterCount = ExceptionRecord->NumberParameters) >
120 {
121 /* Too large */
123 }
124
125 /* Probe the entire parameters now*/
126 Size = (sizeof(EXCEPTION_RECORD) -
127 ((EXCEPTION_MAXIMUM_PARAMETERS - ParameterCount) * sizeof(ULONG)));
128 ProbeForRead(ExceptionRecord, Size, sizeof(ULONG));
129
130 /* Now make copies in the stack */
131 RtlCopyMemory(&LocalContext, Context, sizeof(CONTEXT));
132 RtlCopyMemory(&LocalExceptionRecord, ExceptionRecord, Size);
133 Context = &LocalContext;
134 ExceptionRecord = &LocalExceptionRecord;
135
136 /* Update the parameter count */
137 ExceptionRecord->NumberParameters = ParameterCount;
138 }
140 {
141 /* Don't fail silently */
142 DPRINT1("KiRaiseException: Failed to Probe\n");
143
144 /* Return the exception code */
146 }
147 _SEH2_END;
148 }
149
150 /* Convert the context record */
152 ExceptionFrame,
153 TrapFrame,
154 Context->ContextFlags,
156
157 /* Dispatch the exception */
158 ExceptionRecord->ExceptionCode &= ~KI_EXCEPTION_INTERNAL;
159 KiDispatchException(ExceptionRecord,
160 ExceptionFrame,
161 TrapFrame,
163 SearchFrames);
164
165 /* We are done */
166 return STATUS_SUCCESS;
167}
#define DPRINT1
Definition: precomp.h:8
#define EXCEPTION_MAXIMUM_PARAMETERS
Definition: compat.h:206
struct _EXCEPTION_RECORD EXCEPTION_RECORD
VOID NTAPI KiDispatchException(PEXCEPTION_RECORD ExceptionRecord, PKEXCEPTION_FRAME ExceptionFrame, PKTRAP_FRAME Tf, KPROCESSOR_MODE PreviousMode, BOOLEAN SearchFrames)
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:162
DWORD NumberParameters
Definition: compat.h:212
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by NtRaiseException().

◆ NtContinue()

NTSTATUS NTAPI NtContinue ( _In_ PCONTEXT  Context,
_In_ BOOLEAN  TestAlert 
)

Definition at line 216 of file except.c.

219{
222 PKTRAP_FRAME TrapFrame;
223#ifdef _M_IX86
224 PKEXCEPTION_FRAME ExceptionFrame = NULL;
225#else
226 KEXCEPTION_FRAME LocalExceptionFrame;
227 PKEXCEPTION_FRAME ExceptionFrame = &LocalExceptionFrame;
228#endif
229
230 /* Get trap frame and link previous one*/
232 TrapFrame = Thread->TrapFrame;
233 Thread->TrapFrame = KiGetLinkedTrapFrame(TrapFrame);
234
235 /* Continue from this point on */
236 Status = KiContinue(Context, ExceptionFrame, TrapFrame);
237 if (!NT_SUCCESS(Status))
238 {
239 DPRINT1("KiContinue failed. Status = 0x%lx\n", Status);
240 return Status;
241 }
242
243 /* Check if alert was requested */
244 if (TestAlert)
245 {
246 KeTestAlertThread(Thread->PreviousMode);
247 }
248
249 /* Exit to new context */
250 KiExceptionExit(TrapFrame, ExceptionFrame);
251}
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define KeGetCurrentThread
Definition: hal.h:55
DECLSPEC_NORETURN VOID KiExceptionExit(_In_ PKTRAP_FRAME TrapFrame, _In_ PKEXCEPTION_FRAME ExceptionFrame)
Definition: ke.h:689
#define KiGetLinkedTrapFrame(x)
Definition: ke.h:177
BOOLEAN NTAPI KeTestAlertThread(IN KPROCESSOR_MODE AlertMode)
Definition: thrdobj.c:722
NTSTATUS NTAPI KiContinue(IN PCONTEXT Context, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: except.c:42

Referenced by KiUserExceptionDispatcher(), and START_TEST().

◆ NtRaiseException()

NTSTATUS NTAPI NtRaiseException ( _In_ PEXCEPTION_RECORD  ExceptionRecord,
_In_ PCONTEXT  Context,
_In_ BOOLEAN  FirstChance 
)

Definition at line 173 of file except.c.

177{
180 PKTRAP_FRAME TrapFrame;
181#ifdef _M_IX86
182 PKEXCEPTION_FRAME ExceptionFrame = NULL;
183#else
184 KEXCEPTION_FRAME LocalExceptionFrame;
185 PKEXCEPTION_FRAME ExceptionFrame = &LocalExceptionFrame;
186#endif
187
188 /* Get trap frame and link previous one */
190 TrapFrame = Thread->TrapFrame;
191 Thread->TrapFrame = KiGetLinkedTrapFrame(TrapFrame);
192
193 /* Set exception list */
194#ifdef _M_IX86
195 KeGetPcr()->NtTib.ExceptionList = TrapFrame->ExceptionList;
196#endif
197
198 /* Raise the exception */
199 Status = KiRaiseException(ExceptionRecord,
200 Context,
201 ExceptionFrame,
202 TrapFrame,
203 FirstChance);
204 if (!NT_SUCCESS(Status))
205 {
206 DPRINT1("KiRaiseException failed. Status = 0x%lx\n", Status);
207 return Status;
208 }
209
210 /* It was handled, so exit restoring all state */
211 KiExceptionExit(TrapFrame, ExceptionFrame);
212}
#define KeGetPcr()
Definition: ketypes.h:81
NTSTATUS NTAPI KiRaiseException(_In_ PEXCEPTION_RECORD ExceptionRecord, _In_ PCONTEXT Context, _Out_ PKEXCEPTION_FRAME ExceptionFrame, _Out_ PKTRAP_FRAME TrapFrame, _In_ BOOLEAN SearchFrames)
Definition: except.c:90
struct _EXCEPTION_REGISTRATION_RECORD FAR * ExceptionList
Definition: ketypes.h:314

Referenced by KiUserExceptionDispatcher().