ReactOS  0.4.15-dev-440-g5f37b68
trap_x.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define KiExitTrapDebugChecks(x, y)
 
#define KiFillTrapFrameDebug(x)
 

Typedefs

typedef VOID(FASTCALLPFAST_SYSTEM_CALL_EXIT) (IN PKTRAP_FRAME TrapFrame)
 

Functions

FORCEINLINE BOOLEAN KiUserTrap (IN PKTRAP_FRAME TrapFrame)
 
FORCEINLINE VOID KiDumpTrapFrame (IN PKTRAP_FRAME TrapFrame)
 
FORCEINLINE VOID KiExitSystemCallDebugChecks (IN ULONG SystemCall, IN PKTRAP_FRAME TrapFrame)
 
DECLSPEC_NORETURN VOID FASTCALL KiSystemCallReturn (IN PKTRAP_FRAME TrapFrame)
 
DECLSPEC_NORETURN VOID FASTCALL KiSystemCallSysExitReturn (IN PKTRAP_FRAME TrapFrame)
 
DECLSPEC_NORETURN VOID FASTCALL KiSystemCallTrapReturn (IN PKTRAP_FRAME TrapFrame)
 
DECLSPEC_NORETURN VOID FASTCALL KiEditedTrapReturn (IN PKTRAP_FRAME TrapFrame)
 
DECLSPEC_NORETURN VOID FASTCALL KiTrapReturn (IN PKTRAP_FRAME TrapFrame)
 
DECLSPEC_NORETURN VOID FASTCALL KiTrapReturnNoSegments (IN PKTRAP_FRAME TrapFrame)
 
DECLSPEC_NORETURN VOID FASTCALL KiTrapReturnNoSegmentsRet8 (IN PKTRAP_FRAME TrapFrame)
 
FORCEINLINE VOID KiHandleDebugRegistersOnTrapEntry (IN PKTRAP_FRAME TrapFrame)
 
FORCEINLINE VOID KiHandleDebugRegistersOnTrapExit (PKTRAP_FRAME TrapFrame)
 
FORCEINLINE DECLSPEC_NORETURN VOID KiExitV86Trap (IN PKTRAP_FRAME TrapFrame)
 
FORCEINLINE VOID KiEnterV86Trap (IN PKTRAP_FRAME TrapFrame)
 
FORCEINLINE VOID KiEnterInterruptTrap (IN PKTRAP_FRAME TrapFrame)
 
FORCEINLINE VOID KiEnterTrap (IN PKTRAP_FRAME TrapFrame)
 

Variables

PFAST_SYSTEM_CALL_EXIT KiFastCallExitHandler
 

Macro Definition Documentation

◆ KiExitTrapDebugChecks

#define KiExitTrapDebugChecks (   x,
  y 
)

Definition at line 188 of file trap_x.h.

◆ KiFillTrapFrameDebug

#define KiFillTrapFrameDebug (   x)

Definition at line 189 of file trap_x.h.

Typedef Documentation

◆ PFAST_SYSTEM_CALL_EXIT

typedef VOID(FASTCALL * PFAST_SYSTEM_CALL_EXIT) (IN PKTRAP_FRAME TrapFrame)

Definition at line 245 of file trap_x.h.

Function Documentation

◆ KiDumpTrapFrame()

FORCEINLINE VOID KiDumpTrapFrame ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 36 of file trap_x.h.

37 {
38  /* Dump the whole thing */
39  DbgPrint("DbgEbp: %x\n", TrapFrame->DbgEbp);
40  DbgPrint("DbgEip: %x\n", TrapFrame->DbgEip);
41  DbgPrint("DbgArgMark: %x\n", TrapFrame->DbgArgMark);
42  DbgPrint("DbgArgPointer: %x\n", TrapFrame->DbgArgPointer);
43  DbgPrint("TempSegCs: %x\n", TrapFrame->TempSegCs);
44  DbgPrint("TempEsp: %x\n", TrapFrame->TempEsp);
45  DbgPrint("Dr0: %x\n", TrapFrame->Dr0);
46  DbgPrint("Dr1: %x\n", TrapFrame->Dr1);
47  DbgPrint("Dr2: %x\n", TrapFrame->Dr2);
48  DbgPrint("Dr3: %x\n", TrapFrame->Dr3);
49  DbgPrint("Dr6: %x\n", TrapFrame->Dr6);
50  DbgPrint("Dr7: %x\n", TrapFrame->Dr7);
51  DbgPrint("SegGs: %x\n", TrapFrame->SegGs);
52  DbgPrint("SegEs: %x\n", TrapFrame->SegEs);
53  DbgPrint("SegDs: %x\n", TrapFrame->SegDs);
54  DbgPrint("Edx: %x\n", TrapFrame->Edx);
55  DbgPrint("Ecx: %x\n", TrapFrame->Ecx);
56  DbgPrint("Eax: %x\n", TrapFrame->Eax);
57  DbgPrint("PreviousPreviousMode: %x\n", TrapFrame->PreviousPreviousMode);
58  DbgPrint("ExceptionList: %p\n", TrapFrame->ExceptionList);
59  DbgPrint("SegFs: %x\n", TrapFrame->SegFs);
60  DbgPrint("Edi: %x\n", TrapFrame->Edi);
61  DbgPrint("Esi: %x\n", TrapFrame->Esi);
62  DbgPrint("Ebx: %x\n", TrapFrame->Ebx);
63  DbgPrint("Ebp: %x\n", TrapFrame->Ebp);
64  DbgPrint("ErrCode: %x\n", TrapFrame->ErrCode);
65  DbgPrint("Eip: %x\n", TrapFrame->Eip);
66  DbgPrint("SegCs: %x\n", TrapFrame->SegCs);
67  DbgPrint("EFlags: %x\n", TrapFrame->EFlags);
68  DbgPrint("HardwareEsp: %x\n", TrapFrame->HardwareEsp);
69  DbgPrint("HardwareSegSs: %x\n", TrapFrame->HardwareSegSs);
70  DbgPrint("V86Es: %x\n", TrapFrame->V86Es);
71  DbgPrint("V86Ds: %x\n", TrapFrame->V86Ds);
72  DbgPrint("V86Fs: %x\n", TrapFrame->V86Fs);
73  DbgPrint("V86Gs: %x\n", TrapFrame->V86Gs);
74 }
#define DbgPrint
Definition: loader.c:25

Referenced by HalpTrap0DHandler().

◆ KiEditedTrapReturn()

DECLSPEC_NORETURN VOID FASTCALL KiEditedTrapReturn ( IN PKTRAP_FRAME  TrapFrame)

Referenced by KiEoiHelper(), and KiServiceExit2().

◆ KiEnterInterruptTrap()

FORCEINLINE VOID KiEnterInterruptTrap ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 373 of file trap_x.h.

374 {
375  PVOID ExceptionList;
376 
377  /* Check exception list and terminate it */
378  ExceptionList = KeGetPcr()->NtTib.ExceptionList;
379  ASSERTMSG("Interrupt handler must not register an SEH frame\n",
380  ExceptionList == TrapFrame->ExceptionList);
381  KeGetPcr()->NtTib.ExceptionList = EXCEPTION_CHAIN_END;
382 
383  /* Default to debugging disabled */
384  TrapFrame->Dr7 = 0;
385 
386  /* Check if the frame was from user mode or v86 mode */
387  if (KiUserTrap(TrapFrame) ||
388  (TrapFrame->EFlags & EFLAGS_V86_MASK))
389  {
390  /* Check for active debugging */
391  if (KeGetCurrentThread()->Header.DebugActive & 0xFF)
392  {
393  /* Handle debug registers */
395  }
396  }
397 
398  /* Set debug header */
399  KiFillTrapFrameDebug(TrapFrame);
400 }
FORCEINLINE VOID KiHandleDebugRegistersOnTrapEntry(IN PKTRAP_FRAME TrapFrame)
Definition: trap_x.h:256
#define KeGetPcr()
Definition: ke.h:25
#define EFLAGS_V86_MASK
Definition: ketypes.h:129
Definition: Header.h:8
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
FORCEINLINE BOOLEAN KiUserTrap(IN PKTRAP_FRAME TrapFrame)
Definition: trap_x.h:25
#define KiFillTrapFrameDebug(x)
Definition: trap_x.h:189
#define EXCEPTION_CHAIN_END
Definition: rtltypes.h:63
#define KeGetCurrentThread
Definition: hal.h:44

Referenced by HalpApcInterruptHandler(), HalpClockInterruptHandler(), HalpDispatchInterruptHandler(), KiInterruptTemplateHandler(), and KiUnexpectedInterruptTailHandler().

◆ KiEnterTrap()

FORCEINLINE VOID KiEnterTrap ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 407 of file trap_x.h.

408 {
409  PVOID ExceptionList;
410 
411  /* Check exception list */
412  ExceptionList = KeGetPcr()->NtTib.ExceptionList;
413  ASSERTMSG("Trap handler must not register an SEH frame\n",
414  ExceptionList == TrapFrame->ExceptionList);
415 
416  /* Default to debugging disabled */
417  TrapFrame->Dr7 = 0;
418 
419  /* Check if the frame was from user mode or v86 mode */
420  if (KiUserTrap(TrapFrame) ||
421  (TrapFrame->EFlags & EFLAGS_V86_MASK))
422  {
423  /* Check for active debugging */
424  if (KeGetCurrentThread()->Header.DebugActive & 0xFF)
425  {
426  /* Handle debug registers */
428  }
429  }
430 
431  /* Set debug header */
432  KiFillTrapFrameDebug(TrapFrame);
433 }
FORCEINLINE VOID KiHandleDebugRegistersOnTrapEntry(IN PKTRAP_FRAME TrapFrame)
Definition: trap_x.h:256
#define KeGetPcr()
Definition: ke.h:25
#define EFLAGS_V86_MASK
Definition: ketypes.h:129
Definition: Header.h:8
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
FORCEINLINE BOOLEAN KiUserTrap(IN PKTRAP_FRAME TrapFrame)
Definition: trap_x.h:25
#define KiFillTrapFrameDebug(x)
Definition: trap_x.h:189
#define KeGetCurrentThread
Definition: hal.h:44

Referenced by HalpTrap0DHandler(), KiDebugServiceHandler(), KiGetTickCountHandler(), KiRaiseAssertionHandler(), KiRaiseSecurityCheckFailureHandler(), KiTrap00Handler(), KiTrap01Handler(), KiTrap03Handler(), KiTrap04Handler(), KiTrap05Handler(), KiTrap06Handler(), KiTrap07Handler(), KiTrap09Handler(), KiTrap0AHandler(), KiTrap0BHandler(), KiTrap0CHandler(), KiTrap0DHandler(), KiTrap0EHandler(), KiTrap0FHandler(), KiTrap10Handler(), KiTrap11Handler(), and KiTrap13Handler().

◆ KiEnterV86Trap()

FORCEINLINE VOID KiEnterV86Trap ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 350 of file trap_x.h.

351 {
352  PVOID ExceptionList;
353 
354  /* Check exception list */
355  ExceptionList = KeGetPcr()->NtTib.ExceptionList;
356  ASSERTMSG("V86 trap handler must not register an SEH frame\n",
357  ExceptionList == TrapFrame->ExceptionList);
358 
359  /* Save DR7 and check for debugging */
360  TrapFrame->Dr7 = __readdr(7);
361  if (__builtin_expect(TrapFrame->Dr7 & ~DR7_RESERVED_MASK, 0))
362  {
363  /* Handle debug registers */
365  }
366 }
FORCEINLINE VOID KiHandleDebugRegistersOnTrapEntry(IN PKTRAP_FRAME TrapFrame)
Definition: trap_x.h:256
#define KeGetPcr()
Definition: ke.h:25
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
#define DR7_RESERVED_MASK
Definition: asm.h:514
__INTRIN_INLINE unsigned int __readdr(unsigned int reg)
Definition: intrin_x86.h:1799

Referenced by KiTrap06Handler(), and KiTrap0DHandler().

◆ KiExitSystemCallDebugChecks()

FORCEINLINE VOID KiExitSystemCallDebugChecks ( IN ULONG  SystemCall,
IN PKTRAP_FRAME  TrapFrame 
)

Definition at line 194 of file trap_x.h.

196 {
197  KIRQL OldIrql;
198 
199  /* Check if this was a user call */
200  if (KiUserTrap(TrapFrame))
201  {
202  /* Make sure we are not returning with elevated IRQL */
204  if (OldIrql != PASSIVE_LEVEL)
205  {
206  /* Forcibly put us in a sane state */
207  KeGetPcr()->Irql = PASSIVE_LEVEL;
208  _disable();
209 
210  /* Fail */
211  KeBugCheckEx(IRQL_GT_ZERO_AT_SYSTEM_SERVICE,
212  SystemCall,
213  OldIrql,
214  0,
215  0);
216  }
217 
218  /* Make sure we're not attached and that APCs are not disabled */
219  if ((KeGetCurrentThread()->ApcStateIndex != OriginalApcEnvironment) ||
220  (KeGetCurrentThread()->CombinedApcDisable != 0))
221  {
222  /* Fail */
223  KeBugCheckEx(APC_INDEX_MISMATCH,
224  SystemCall,
225  KeGetCurrentThread()->ApcStateIndex,
226  KeGetCurrentThread()->CombinedApcDisable,
227  0);
228  }
229  }
230 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define KeGetPcr()
Definition: ke.h:25
UCHAR KIRQL
Definition: env_spec_w32.h:591
FORCEINLINE BOOLEAN KiUserTrap(IN PKTRAP_FRAME TrapFrame)
Definition: trap_x.h:25
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
void __cdecl _disable(void)
Definition: intrin_arm.h:365
#define KeGetCurrentThread
Definition: hal.h:44
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

Referenced by KiSystemServiceHandler().

◆ KiExitV86Trap()

FORCEINLINE DECLSPEC_NORETURN VOID KiExitV86Trap ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 304 of file trap_x.h.

305 {
307  KIRQL OldIrql;
308 
309  /* Get the thread */
311  while (TRUE)
312  {
313  /* Return if this isn't V86 mode anymore */
314  if (!(TrapFrame->EFlags & EFLAGS_V86_MASK)) KiEoiHelper(TrapFrame);
315 
316  /* Turn off the alerted state for kernel mode */
317  Thread->Alerted[KernelMode] = FALSE;
318 
319  /* Are there pending user APCs? */
320  if (__builtin_expect(!Thread->ApcState.UserApcPending, 1)) break;
321 
322  /* Raise to APC level and enable interrupts */
324  _enable();
325 
326  /* Deliver APCs */
327  KiDeliverApc(UserMode, NULL, TrapFrame);
328 
329  /* Restore IRQL and disable interrupts once again */
331  _disable();
332  }
333 
334  /* If we got here, we're still in a valid V8086 context, so quit it */
335  if (__builtin_expect(TrapFrame->Dr7 & ~DR7_RESERVED_MASK, 0))
336  {
337  /* Restore debug registers from the trap frame */
339  }
340 
341  /* Return from interrupt */
342  KiTrapReturnNoSegments(TrapFrame);
343 }
#define TRUE
Definition: types.h:120
DECLSPEC_NORETURN VOID FASTCALL KiTrapReturnNoSegments(IN PKTRAP_FRAME TrapFrame)
void __cdecl _enable(void)
Definition: intrin_arm.h:373
DECLSPEC_NORETURN VOID FASTCALL KiEoiHelper(IN PKTRAP_FRAME TrapFrame)
Definition: traphdlr.c:126
#define EFLAGS_V86_MASK
Definition: ketypes.h:129
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
#define DR7_RESERVED_MASK
Definition: asm.h:514
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
VOID FASTCALL KfLowerIrql(IN KIRQL NewIrql)
Definition: pic.c:232
FORCEINLINE VOID KiHandleDebugRegistersOnTrapExit(PKTRAP_FRAME TrapFrame)
Definition: trap_x.h:283
void __cdecl _disable(void)
Definition: intrin_arm.h:365
#define KeGetCurrentThread
Definition: hal.h:44
VOID NTAPI KiDeliverApc(IN KPROCESSOR_MODE DeliveryMode, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: apc.c:302
#define APC_LEVEL
Definition: env_spec_w32.h:695

Referenced by KiTrap06Handler(), and KiTrap0DHandler().

◆ KiHandleDebugRegistersOnTrapEntry()

FORCEINLINE VOID KiHandleDebugRegistersOnTrapEntry ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 256 of file trap_x.h.

258 {
259  PKPRCB Prcb = KeGetCurrentPrcb();
260 
261  /* Save all debug registers in the trap frame */
262  TrapFrame->Dr0 = __readdr(0);
263  TrapFrame->Dr1 = __readdr(1);
264  TrapFrame->Dr2 = __readdr(2);
265  TrapFrame->Dr3 = __readdr(3);
266  TrapFrame->Dr6 = __readdr(6);
267  TrapFrame->Dr7 = __readdr(7);
268 
269  /* Disable all active debugging */
270  __writedr(7, 0);
271 
272  /* Restore kernel values */
279 }
__INTRIN_INLINE void __writedr(unsigned reg, unsigned int value)
Definition: intrin_x86.h:1832
ULONG64 KernelDr7
Definition: ketypes.h:505
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1063
ULONG64 KernelDr2
Definition: ketypes.h:502
KSPECIAL_REGISTERS SpecialRegisters
Definition: ketypes.h:530
ULONG64 KernelDr1
Definition: ketypes.h:501
KPROCESSOR_STATE ProcessorState
Definition: ketypes.h:579
__INTRIN_INLINE unsigned int __readdr(unsigned int reg)
Definition: intrin_x86.h:1799
ULONG64 KernelDr3
Definition: ketypes.h:503
ULONG64 KernelDr6
Definition: ketypes.h:504
ULONG64 KernelDr0
Definition: ketypes.h:500

Referenced by KiEnterInterruptTrap(), KiEnterTrap(), KiEnterV86Trap(), and KiSystemServiceHandler().

◆ KiHandleDebugRegistersOnTrapExit()

FORCEINLINE VOID KiHandleDebugRegistersOnTrapExit ( PKTRAP_FRAME  TrapFrame)

Definition at line 283 of file trap_x.h.

285 {
286  /* Disable all active debugging */
287  __writedr(7, 0);
288 
289  /* Load all debug registers from the trap frame */
290  __writedr(0, TrapFrame->Dr0);
291  __writedr(1, TrapFrame->Dr1);
292  __writedr(2, TrapFrame->Dr2);
293  __writedr(3, TrapFrame->Dr3);
294  __writedr(6, TrapFrame->Dr6);
295  __writedr(7, TrapFrame->Dr7);
296 }
__INTRIN_INLINE void __writedr(unsigned reg, unsigned int value)
Definition: intrin_x86.h:1832
UINT64 Dr2
Definition: ketypes.h:344
UINT64 Dr6
Definition: ketypes.h:346
UINT64 Dr3
Definition: ketypes.h:345
UINT64 Dr1
Definition: ketypes.h:343
UINT64 Dr0
Definition: ketypes.h:342
UINT64 Dr7
Definition: ketypes.h:347

Referenced by KiCommonExit(), and KiExitV86Trap().

◆ KiSystemCallReturn()

DECLSPEC_NORETURN VOID FASTCALL KiSystemCallReturn ( IN PKTRAP_FRAME  TrapFrame)

Referenced by KiServiceExit().

◆ KiSystemCallSysExitReturn()

DECLSPEC_NORETURN VOID FASTCALL KiSystemCallSysExitReturn ( IN PKTRAP_FRAME  TrapFrame)

◆ KiSystemCallTrapReturn()

DECLSPEC_NORETURN VOID FASTCALL KiSystemCallTrapReturn ( IN PKTRAP_FRAME  TrapFrame)

◆ KiTrapReturn()

◆ KiTrapReturnNoSegments()

DECLSPEC_NORETURN VOID FASTCALL KiTrapReturnNoSegments ( IN PKTRAP_FRAME  TrapFrame)

◆ KiTrapReturnNoSegmentsRet8()

DECLSPEC_NORETURN VOID FASTCALL KiTrapReturnNoSegmentsRet8 ( IN PKTRAP_FRAME  TrapFrame)

Referenced by KiEoiHelper(), and KiServiceExit2().

◆ KiUserTrap()

FORCEINLINE BOOLEAN KiUserTrap ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 25 of file trap_x.h.

26 {
27  /* Anything else but Ring 0 is Ring 3 */
28  return !!(TrapFrame->SegCs & MODE_MASK);
29 }
#define MODE_MASK
Definition: orders.h:326

Referenced by KiEnterInterruptTrap(), KiEnterTrap(), and KiExitSystemCallDebugChecks().

Variable Documentation

◆ KiFastCallExitHandler

PFAST_SYSTEM_CALL_EXIT KiFastCallExitHandler

Definition at line 56 of file traphdlr.c.

Referenced by KiRestoreFastSyscallReturnState(), and KiServiceExit().