ReactOS  0.4.15-dev-3302-ga37d9a4
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 KeInitExceptions (VOID)
 
static VOID KiDispatchExceptionToUser (IN PKTRAP_FRAME TrapFrame, IN PCONTEXT Context, IN PEXCEPTION_RECORD ExceptionRecord)
 
static VOID KiPageInDirectory (PVOID ImageBase, USHORT Directory)
 
VOID KiPrepareUserDebugData (void)
 
VOID NTAPI KiDispatchException (IN PEXCEPTION_RECORD ExceptionRecord, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame, IN KPROCESSOR_MODE PreviousMode, IN BOOLEAN FirstChance)
 
NTSTATUS NTAPI KeRaiseUserException (IN NTSTATUS ExceptionCode)
 
VOID DECLSPEC_NORETURN KiSystemFatalException (IN ULONG ExceptionCode, IN PKTRAP_FRAME TrapFrame)
 
NTSTATUS NTAPI KiNpxNotAvailableFaultHandler (IN PKTRAP_FRAME TrapFrame)
 
NTSTATUS NTAPI KiGeneralProtectionFaultHandler (IN PKTRAP_FRAME TrapFrame)
 
NTSTATUS NTAPI KiXmmExceptionHandler (IN PKTRAP_FRAME TrapFrame)
 

Variables

KI_INTERRUPT_DISPATCH_ENTRY KiUnexpectedRange [256]
 
KIDT_INIT KiInterruptInitTable []
 
KIDTENTRY64 KiIdt [256]
 
KDESCRIPTOR KiIdtDescriptor = {{0}, sizeof(KiIdt) - 1, KiIdt}
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file except.c.

Function Documentation

◆ KeInitExceptions()

VOID NTAPI KeInitExceptions ( VOID  )

Definition at line 59 of file except.c.

60 {
61  int i, j;
62 
63  /* Initialize the Idt */
64  for (j = i = 0; i < 256; i++)
65  {
67 
68  if (KiInterruptInitTable[j].InterruptId == i)
69  {
73  j++;
74  }
75  else
76  {
77  Offset = (ULONG64)&KiUnexpectedRange[i]._Op_push;
78  KiIdt[i].Dpl = 0;
79  KiIdt[i].IstIndex = 0;
80  }
81  KiIdt[i].OffsetLow = Offset & 0xffff;
83  KiIdt[i].Type = 0x0e;
84  KiIdt[i].Reserved0 = 0;
85  KiIdt[i].Present = 1;
86  KiIdt[i].OffsetMiddle = (Offset >> 16) & 0xffff;
87  KiIdt[i].OffsetHigh = (Offset >> 32);
88  KiIdt[i].Reserved1 = 0;
89  }
90 
91  KeGetPcr()->IdtBase = KiIdt;
93 }
UCHAR IstIndex
Definition: ke.h:93
KIDTENTRY64 KiIdt[256]
Definition: except.c:50
__INTRIN_INLINE void __lidt(void *Source)
Definition: intrin_x86.h:2019
UCHAR Dpl
Definition: ke.h:92
#define KeGetPcr()
Definition: ke.h:26
USHORT Selector
Definition: ketypes.h:471
USHORT Limit
Definition: ketypes.h:489
USHORT OffsetLow
Definition: ketypes.h:470
USHORT Reserved0
Definition: ketypes.h:473
USHORT Type
Definition: ketypes.h:474
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
USHORT Present
Definition: ketypes.h:476
USHORT OffsetMiddle
Definition: ketypes.h:477
#define KGDT64_R0_CODE
Definition: ketypes.h:72
USHORT IstIndex
Definition: ketypes.h:472
unsigned __int64 ULONG64
Definition: imports.h:198
USHORT Dpl
Definition: ketypes.h:475
ULONG Reserved1
Definition: ketypes.h:479
KI_INTERRUPT_DISPATCH_ENTRY KiUnexpectedRange[256]
KIDT_INIT KiInterruptInitTable[]
Definition: except.c:20
KDESCRIPTOR KiIdtDescriptor
Definition: except.c:51
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ULONG OffsetHigh
Definition: ketypes.h:478
_In_ PKSERVICE_ROUTINE ServiceRoutine
Definition: iofuncs.h:800

◆ KeRaiseUserException()

NTSTATUS NTAPI KeRaiseUserException ( IN NTSTATUS  ExceptionCode)

Definition at line 397 of file except.c.

398 {
400  return STATUS_UNSUCCESSFUL;
401 }
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by ObpCloseHandle(), and ObpCloseHandleTableEntry().

◆ KiDispatchException()

VOID NTAPI KiDispatchException ( IN PEXCEPTION_RECORD  ExceptionRecord,
IN PKEXCEPTION_FRAME  ExceptionFrame,
IN PKTRAP_FRAME  TrapFrame,
IN KPROCESSOR_MODE  PreviousMode,
IN BOOLEAN  FirstChance 
)

Definition at line 237 of file except.c.

242 {
244 
245  /* Increase number of Exception Dispatches */
246  KeGetCurrentPrcb()->KeExceptionDispatchCount++;
247 
248  /* Zero out the context to avoid leaking kernel stack memor to user mode */
249  RtlZeroMemory(&Context, sizeof(Context));
250 
251  /* Set the context flags */
252  Context.ContextFlags = CONTEXT_ALL;
253 
254  /* Get the Context from the trap and exception frame */
255  KeTrapFrameToContext(TrapFrame, ExceptionFrame, &Context);
256 
257  /* Look at our exception code */
258  switch (ExceptionRecord->ExceptionCode)
259  {
260  /* Breakpoint */
261  case STATUS_BREAKPOINT:
262 
263  /* Decrement RIP by one */
264  Context.Rip--;
265  break;
266 
267  /* Internal exception */
269 
270  /* Set correct code */
271  ExceptionRecord->ExceptionCode = STATUS_ACCESS_VIOLATION;
272  if (PreviousMode == UserMode)
273  {
274  /* FIXME: Handle no execute */
275  }
276  break;
277  }
278 
279  /* Handle kernel-mode first, it's simpler */
280  if (PreviousMode == KernelMode)
281  {
282  /* Check if this is a first-chance exception */
283  if (FirstChance)
284  {
285  /* Break into the debugger for the first time */
286  if (KiDebugRoutine(TrapFrame,
287  ExceptionFrame,
288  ExceptionRecord,
289  &Context,
290  PreviousMode,
291  FALSE))
292  {
293  /* Exception was handled */
294  goto Handled;
295  }
296 
297  /* If the Debugger couldn't handle it, dispatch the exception */
298  if (RtlDispatchException(ExceptionRecord, &Context)) goto Handled;
299  }
300 
301  /* This is a second-chance exception, only for the debugger */
302  if (KiDebugRoutine(TrapFrame,
303  ExceptionFrame,
304  ExceptionRecord,
305  &Context,
306  PreviousMode,
307  TRUE))
308  {
309  /* Exception was handled */
310  goto Handled;
311  }
312 
313  /* Third strike; you're out */
314  KeBugCheckEx(KMODE_EXCEPTION_NOT_HANDLED,
315  ExceptionRecord->ExceptionCode,
316  (ULONG_PTR)ExceptionRecord->ExceptionAddress,
317  (ULONG_PTR)TrapFrame,
318  0);
319  }
320  else
321  {
322  /* User mode exception, was it first-chance? */
323  if (FirstChance)
324  {
325  /*
326  * Break into the kernel debugger unless a user mode debugger
327  * is present or user mode exceptions are ignored, except if this
328  * is a debug service which we must always pass to KD
329  */
330  if ((!(PsGetCurrentProcess()->DebugPort) &&
331  !(KdIgnoreUmExceptions)) ||
332  (KdIsThisAKdTrap(ExceptionRecord, &Context, PreviousMode)))
333  {
334  /* Make sure the debugger can access debug directories */
336 
337  /* Call the kernel debugger */
338  if (KiDebugRoutine(TrapFrame,
339  ExceptionFrame,
340  ExceptionRecord,
341  &Context,
342  PreviousMode,
343  FALSE))
344  {
345  /* Exception was handled */
346  goto Handled;
347  }
348  }
349 
350  /* Forward exception to user mode debugger */
351  if (DbgkForwardException(ExceptionRecord, TRUE, FALSE)) return;
352 
353  /* Forward exception to user mode (does not return) */
354  KiDispatchExceptionToUser(TrapFrame, &Context, ExceptionRecord);
355  NT_ASSERT(FALSE);
356  }
357 
358  /* Try second chance */
359  if (DbgkForwardException(ExceptionRecord, TRUE, TRUE))
360  {
361  /* Handled, get out */
362  return;
363  }
364  else if (DbgkForwardException(ExceptionRecord, FALSE, TRUE))
365  {
366  /* Handled, get out */
367  return;
368  }
369 
370  /* 3rd strike, kill the process */
371  DPRINT1("Kill %.16s, ExceptionCode: %lx, ExceptionAddress: %lx, BaseAddress: %lx\n",
372  PsGetCurrentProcess()->ImageFileName,
373  ExceptionRecord->ExceptionCode,
374  ExceptionRecord->ExceptionAddress,
375  PsGetCurrentProcess()->SectionBaseAddress);
376 
377  ZwTerminateProcess(NtCurrentProcess(), ExceptionRecord->ExceptionCode);
378  KeBugCheckEx(KMODE_EXCEPTION_NOT_HANDLED,
379  ExceptionRecord->ExceptionCode,
380  (ULONG_PTR)ExceptionRecord->ExceptionAddress,
381  (ULONG_PTR)TrapFrame,
382  0);
383  }
384 
385 Handled:
386  /* Convert the context back into Trap/Exception Frames */
388  ExceptionFrame,
389  TrapFrame,
390  Context.ContextFlags,
391  PreviousMode);
392  return;
393 }
VOID NTAPI KeContextToTrapFrame(PCONTEXT Context, PKEXCEPTION_FRAME ExeptionFrame, PKTRAP_FRAME TrapFrame, ULONG ContextFlags, KPROCESSOR_MODE PreviousMode)
PKDEBUG_ROUTINE KiDebugRoutine
Definition: kddata.c:74
#define TRUE
Definition: types.h:120
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1079
static VOID KiDispatchExceptionToUser(IN PKTRAP_FRAME TrapFrame, IN PCONTEXT Context, IN PEXCEPTION_RECORD ExceptionRecord)
Definition: except.c:97
uint32_t ULONG_PTR
Definition: typedefs.h:65
VOID KiPrepareUserDebugData(void)
Definition: except.c:194
#define FALSE
Definition: types.h:117
#define PsGetCurrentProcess
Definition: psfuncs.h:17
#define STATUS_BREAKPOINT
Definition: ntstatus.h:184
VOID NTAPI KeTrapFrameToContext(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame, IN OUT PCONTEXT Context)
Definition: context.c:169
#define NtCurrentProcess()
Definition: nt_native.h:1657
BOOLEAN KdIgnoreUmExceptions
Definition: kddata.c:86
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
BOOLEAN NTAPI DbgkForwardException(IN PEXCEPTION_RECORD ExceptionRecord, IN BOOLEAN DebugPort, IN BOOLEAN SecondChance)
Definition: dbgkobj.c:317
_In_ BOOLEAN Handled
Definition: ketypes.h:337
BOOLEAN NTAPI KdIsThisAKdTrap(IN PEXCEPTION_RECORD ExceptionRecord, IN PCONTEXT Context, IN KPROCESSOR_MODE PreviousMode)
Definition: kdtrap.c:317
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1034
BOOLEAN NTAPI RtlDispatchException(_In_ PEXCEPTION_RECORD ExceptionRecord, _In_ PCONTEXT ContextRecord)
Definition: except.c:87
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define CONTEXT_ALL
#define KI_EXCEPTION_ACCESS_VIOLATION
Definition: ketypes.h:177
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
#define NT_ASSERT
Definition: rtlfuncs.h:3310

Referenced by KiRaiseException().

◆ KiDispatchExceptionToUser()

static VOID KiDispatchExceptionToUser ( IN PKTRAP_FRAME  TrapFrame,
IN PCONTEXT  Context,
IN PEXCEPTION_RECORD  ExceptionRecord 
)
static

Definition at line 97 of file except.c.

101 {
102  EXCEPTION_RECORD LocalExceptRecord;
103  ULONG64 UserRsp;
104  PKUSER_EXCEPTION_STACK UserStack;
105 
106  /* Make sure we have a valid SS */
107  if (TrapFrame->SegSs != (KGDT64_R3_DATA | RPL_MASK))
108  {
109  /* Raise an access violation instead */
110  LocalExceptRecord.ExceptionCode = STATUS_ACCESS_VIOLATION;
111  LocalExceptRecord.ExceptionFlags = 0;
112  LocalExceptRecord.NumberParameters = 0;
113  ExceptionRecord = &LocalExceptRecord;
114  }
115 
116  /* Get new stack pointer and align it to 16 bytes */
117  UserRsp = (Context->Rsp - sizeof(KUSER_EXCEPTION_STACK)) & ~15;
118 
119  /* Get pointer to the usermode context, exception record and machine frame */
120  UserStack = (PKUSER_EXCEPTION_STACK)UserRsp;
121 
122  /* Set up the user-stack */
123  _SEH2_TRY
124  {
125  /* Probe the user stack frame and zero it out */
126  ProbeForWrite(UserStack, sizeof(*UserStack), TYPE_ALIGNMENT(KUSER_EXCEPTION_STACK));
127  RtlZeroMemory(UserStack, sizeof(*UserStack));
128 
129  /* Copy Context and ExceptionFrame */
130  UserStack->Context = *Context;
131  UserStack->ExceptionRecord = *ExceptionRecord;
132 
133  /* Setup the machine frame */
134  UserStack->MachineFrame.Rip = Context->Rip;
135  UserStack->MachineFrame.SegCs = Context->SegCs;
136  UserStack->MachineFrame.EFlags = Context->EFlags;
137  UserStack->MachineFrame.Rsp = Context->Rsp;
138  UserStack->MachineFrame.SegSs = Context->SegSs;
139  }
140  _SEH2_EXCEPT((LocalExceptRecord = *_SEH2_GetExceptionInformation()->ExceptionRecord),
142  {
143  // FIXME: handle stack overflow
144 
145  /* Nothing we can do here */
146  _SEH2_YIELD(return);
147  }
148  _SEH2_END;
149 
150  /* Now set the two params for the user-mode dispatcher */
151  TrapFrame->Rcx = (ULONG64)&UserStack->ExceptionRecord;
152  TrapFrame->Rdx = (ULONG64)&UserStack->Context;
153 
154  /* Set new Stack Pointer */
155  TrapFrame->Rsp = UserRsp;
156 
157  /* Force correct segments */
158  TrapFrame->SegCs = KGDT64_R3_CODE | RPL_MASK;
159  TrapFrame->SegDs = KGDT64_R3_DATA | RPL_MASK;
160  TrapFrame->SegEs = KGDT64_R3_DATA | RPL_MASK;
161  TrapFrame->SegFs = KGDT64_R3_CMTEB | RPL_MASK;
162  TrapFrame->SegGs = KGDT64_R3_DATA | RPL_MASK;
163  TrapFrame->SegSs = KGDT64_R3_DATA | RPL_MASK;
164 
165  /* Set RIP to the User-mode Dispatcher */
166  TrapFrame->Rip = (ULONG64)KeUserExceptionDispatcher;
167 
168  /* Exit to usermode */
169  KiServiceExit2(TrapFrame);
170 }
#define KGDT64_R3_CODE
Definition: ketypes.h:76
#define TYPE_ALIGNMENT(t)
Definition: ntbasedef.h:117
struct _KUSER_EXCEPTION_STACK * PKUSER_EXCEPTION_STACK
#define KGDT64_R3_CMTEB
Definition: ketypes.h:78
USHORT SegSs
Definition: ketypes.h:981
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
_SEH2_TRY
Definition: create.c:4226
DWORD ExceptionCode
Definition: compat.h:208
MACHINE_FRAME MachineFrame
Definition: ketypes.h:1014
#define KGDT64_R3_DATA
Definition: ketypes.h:75
EXCEPTION_RECORD ExceptionRecord
Definition: ketypes.h:1012
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:164
#define RPL_MASK
Definition: ketypes.h:69
ULONG SegCs
Definition: nt_native.h:1477
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
PVOID KeUserExceptionDispatcher
Definition: ke.h:144
unsigned __int64 ULONG64
Definition: imports.h:198
ULONG EFlags
Definition: ketypes.h:978
ULONG64 Rip
Definition: ketypes.h:975
ULONG64 Rsp
Definition: ketypes.h:980
_SEH2_END
Definition: create.c:4400
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define KiServiceExit2
Definition: ke.h:5
USHORT SegCs
Definition: ketypes.h:976
struct _KUSER_EXCEPTION_STACK KUSER_EXCEPTION_STACK
struct tagContext Context
Definition: acpixf.h:1034
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
DWORD ExceptionFlags
Definition: compat.h:209
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
DWORD NumberParameters
Definition: compat.h:212

Referenced by KiDispatchException().

◆ KiGeneralProtectionFaultHandler()

NTSTATUS NTAPI KiGeneralProtectionFaultHandler ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 431 of file except.c.

433 {
434  PUCHAR Instructions;
435 
436  /* Check for user-mode GPF */
437  if (TrapFrame->SegCs & 3)
438  {
440  ASSERT(FALSE);
441  }
442 
443  /* Check for lazy segment load */
444  if (TrapFrame->SegDs != (KGDT64_R3_DATA | RPL_MASK))
445  {
446  /* Fix it */
447  TrapFrame->SegDs = (KGDT64_R3_DATA | RPL_MASK);
448  return STATUS_SUCCESS;
449  }
450  else if (TrapFrame->SegEs != (KGDT64_R3_DATA | RPL_MASK))
451  {
452  /* Fix it */
453  TrapFrame->SegEs = (KGDT64_R3_DATA | RPL_MASK);
454  return STATUS_SUCCESS;
455  }
456 
457  /* Check for nested exception */
458  if ((TrapFrame->Rip >= (ULONG64)KiGeneralProtectionFaultHandler) &&
459  (TrapFrame->Rip < (ULONG64)KiGeneralProtectionFaultHandler))
460  {
461  /* Not implemented */
463  ASSERT(FALSE);
464  }
465 
466  /* Get Instruction Pointer */
467  Instructions = (PUCHAR)TrapFrame->Rip;
468 
469  /* Check for IRET */
470  if (Instructions[0] == 0x48 && Instructions[1] == 0xCF)
471  {
472  /* Not implemented */
474  ASSERT(FALSE);
475  }
476 
477  /* Check for RDMSR/WRMSR */
478  if ((Instructions[0] == 0xF) && // 2-byte opcode
479  ((Instructions[1] == 0x30) || // RDMSR
480  (Instructions[1] == 0x32))) // WRMSR
481  {
482  /* Unknown CPU MSR, so raise an access violation */
484  }
485 
486  ASSERT(FALSE);
487  return STATUS_UNSUCCESSFUL;
488 }
unsigned char * PUCHAR
Definition: retypes.h:3
if(dx==0 &&dy==0)
Definition: linetemp.h:174
#define FALSE
Definition: types.h:117
#define KGDT64_R3_DATA
Definition: ketypes.h:75
#define RPL_MASK
Definition: ketypes.h:69
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
unsigned __int64 ULONG64
Definition: imports.h:198
NTSTATUS NTAPI KiGeneralProtectionFaultHandler(IN PKTRAP_FRAME TrapFrame)
Definition: except.c:431
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define UNIMPLEMENTED
Definition: debug.h:115
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ KiNpxNotAvailableFaultHandler()

NTSTATUS NTAPI KiNpxNotAvailableFaultHandler ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 420 of file except.c.

422 {
424  KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN, 13, 0, 0, 1, TrapFrame);
425  return -1;
426 }
DECLSPEC_NORETURN VOID NTAPI KeBugCheckWithTf(ULONG BugCheckCode, ULONG_PTR BugCheckParameter1, ULONG_PTR BugCheckParameter2, ULONG_PTR BugCheckParameter3, ULONG_PTR BugCheckParameter4, PKTRAP_FRAME Tf)
#define UNIMPLEMENTED
Definition: debug.h:115

◆ KiPageInDirectory()

static VOID KiPageInDirectory ( PVOID  ImageBase,
USHORT  Directory 
)
static

Definition at line 174 of file except.c.

175 {
176  volatile CHAR *Pointer;
177  ULONG Size;
178 
179  /* Get a pointer to the debug directory */
180  Pointer = RtlImageDirectoryEntryToData(ImageBase, 1, Directory, &Size);
181  if (!Pointer) return;
182 
183  /* Loop all pages */
184  while ((LONG)Size > 0)
185  {
186  /* Touch it, to page it in */
187  (void)*Pointer;
188  Pointer += PAGE_SIZE;
189  Size -= PAGE_SIZE;
190  }
191 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
char CHAR
Definition: xmlstorage.h:175
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
long LONG
Definition: pedump.c:60
#define RtlImageDirectoryEntryToData
Definition: compat.h:668
#define PAGE_SIZE
Definition: env_spec_w32.h:49
unsigned int ULONG
Definition: retypes.h:1
base for all directory entries
Definition: entries.h:138

Referenced by KiPrepareUserDebugData().

◆ KiPrepareUserDebugData()

VOID KiPrepareUserDebugData ( void  )

Definition at line 194 of file except.c.

195 {
196  PLDR_DATA_TABLE_ENTRY LdrEntry;
198  PLIST_ENTRY ListEntry;
199  PTEB Teb;
200 
201  /* Get the Teb for this process */
202  Teb = KeGetCurrentThread()->Teb;
203  if (!Teb) return;
204 
205  _SEH2_TRY
206  {
207  /* Get a pointer to the loader data */
209  if (!PebLdr) _SEH2_YIELD(return);
210 
211  /* Now loop all entries in the module list */
212  for (ListEntry = PebLdr->InLoadOrderModuleList.Flink;
213  ListEntry != &PebLdr->InLoadOrderModuleList;
214  ListEntry = ListEntry->Flink)
215  {
216  /* Get the loader entry */
217  LdrEntry = CONTAINING_RECORD(ListEntry,
219  InLoadOrderLinks);
220 
221  KiPageInDirectory((PVOID)LdrEntry->DllBase,
223 
224  KiPageInDirectory((PVOID)LdrEntry->DllBase,
226  }
227 
228  }
230  {
231  }
232  _SEH2_END;
233 }
PPEB ProcessEnvironmentBlock
Definition: ntddk_ex.h:337
LIST_ENTRY InLoadOrderModuleList
Definition: ldrtypes.h:120
_SEH2_TRY
Definition: create.c:4226
PVOID DllBase
Definition: btrfs_drv.h:1926
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
PEB_LDR_DATA PebLdr
Definition: ldrinit.c:67
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
Definition: btrfs_drv.h:1922
Definition: typedefs.h:119
Definition: compat.h:694
_SEH2_END
Definition: create.c:4400
#define IMAGE_DIRECTORY_ENTRY_DEBUG
Definition: compat.h:152
PPEB_LDR_DATA Ldr
Definition: btrfs_drv.h:1958
static VOID KiPageInDirectory(PVOID ImageBase, USHORT Directory)
Definition: except.c:174
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define KeGetCurrentThread
Definition: hal.h:55
#define IMAGE_DIRECTORY_ENTRY_EXCEPTION
Definition: pedump.c:262

Referenced by KiDispatchException().

◆ KiSystemFatalException()

VOID DECLSPEC_NORETURN KiSystemFatalException ( IN ULONG  ExceptionCode,
IN PKTRAP_FRAME  TrapFrame 
)

Definition at line 406 of file except.c.

408 {
409  /* Bugcheck the system */
410  KeBugCheckWithTf(UNEXPECTED_KERNEL_MODE_TRAP,
412  0,
413  0,
414  0,
415  TrapFrame);
416 }
_Inout_ PIRP _In_ NTSTATUS ExceptionCode
Definition: cdprocs.h:1772
DECLSPEC_NORETURN VOID NTAPI KeBugCheckWithTf(ULONG BugCheckCode, ULONG_PTR BugCheckParameter1, ULONG_PTR BugCheckParameter2, ULONG_PTR BugCheckParameter3, ULONG_PTR BugCheckParameter4, PKTRAP_FRAME Tf)

◆ KiXmmExceptionHandler()

NTSTATUS NTAPI KiXmmExceptionHandler ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 492 of file except.c.

494 {
496  KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN, 13, 0, 0, 1, TrapFrame);
497  return -1;
498 }
DECLSPEC_NORETURN VOID NTAPI KeBugCheckWithTf(ULONG BugCheckCode, ULONG_PTR BugCheckParameter1, ULONG_PTR BugCheckParameter2, ULONG_PTR BugCheckParameter3, ULONG_PTR BugCheckParameter4, PKTRAP_FRAME Tf)
#define UNIMPLEMENTED
Definition: debug.h:115

Variable Documentation

◆ KiIdt

KIDTENTRY64 KiIdt[256]

Definition at line 50 of file except.c.

Referenced by KeInitExceptions().

◆ KiIdtDescriptor

KDESCRIPTOR KiIdtDescriptor = {{0}, sizeof(KiIdt) - 1, KiIdt}

Definition at line 51 of file except.c.

Referenced by KeInitExceptions(), and KiSystemStartup().

◆ KiInterruptInitTable

KIDT_INIT KiInterruptInitTable[]
Initial value:
=
{
{0x00, 0x00, 0x00, KiDivideErrorFault},
{0x01, 0x00, 0x00, KiDebugTrapOrFault},
{0x02, 0x00, 0x03, KiNmiInterrupt},
{0x03, 0x03, 0x00, KiBreakpointTrap},
{0x04, 0x03, 0x00, KiOverflowTrap},
{0x05, 0x00, 0x00, KiBoundFault},
{0x06, 0x00, 0x00, KiInvalidOpcodeFault},
{0x07, 0x00, 0x00, KiNpxNotAvailableFault},
{0x08, 0x00, 0x01, KiDoubleFaultAbort},
{0x09, 0x00, 0x00, KiNpxSegmentOverrunAbort},
{0x0A, 0x00, 0x00, KiInvalidTssFault},
{0x0B, 0x00, 0x00, KiSegmentNotPresentFault},
{0x0C, 0x00, 0x00, KiStackFault},
{0x0D, 0x00, 0x00, KiGeneralProtectionFault},
{0x0E, 0x00, 0x00, KiPageFault},
{0x10, 0x00, 0x00, KiFloatingErrorFault},
{0x11, 0x00, 0x00, KiAlignmentFault},
{0x12, 0x00, 0x02, KiMcheckAbort},
{0x13, 0x00, 0x00, KiXmmException},
{0x1F, 0x00, 0x00, KiApcInterrupt},
{0x2C, 0x03, 0x00, KiRaiseAssertion},
{0x2D, 0x03, 0x00, KiDebugServiceTrap},
{0x2F, 0x00, 0x00, KiDpcInterrupt},
{0xE1, 0x00, 0x00, KiIpiInterrupt},
{0, 0, 0, 0}
}
VOID KiSegmentNotPresentFault(VOID)
VOID KiMcheckAbort(VOID)
VOID KiPageFault(VOID)
VOID KiGeneralProtectionFault(VOID)
VOID KiDivideErrorFault(VOID)
VOID KiInvalidOpcodeFault(VOID)
VOID KiDebugTrapOrFault(VOID)
VOID KiBoundFault(VOID)
VOID KiApcInterrupt(VOID)
Definition: trapc.c:229
VOID KiNpxSegmentOverrunAbort(VOID)
VOID KiIpiInterrupt(VOID)
VOID KiDoubleFaultAbort(VOID)
VOID KiNmiInterrupt(VOID)
VOID KiInvalidTssFault(VOID)
VOID KiNpxNotAvailableFault(VOID)
VOID KiDpcInterrupt(VOID)
VOID KiStackFault(VOID)
VOID KiXmmException(VOID)
VOID KiAlignmentFault(VOID)
VOID KiBreakpointTrap(VOID)
VOID KiFloatingErrorFault(VOID)
VOID KiDebugServiceTrap(VOID)
VOID KiOverflowTrap(VOID)
VOID KiRaiseAssertion(VOID)

Definition at line 20 of file except.c.

Referenced by KeInitExceptions().

◆ KiUnexpectedRange

KI_INTERRUPT_DISPATCH_ENTRY KiUnexpectedRange[256]

Referenced by KeInitExceptions().