ReactOS  0.4.15-dev-994-ga9f6032
kdb.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * FILE: ntoskrnl/kdbg/amd64/kdb.c
5  * PURPOSE: Kernel Debugger
6  * PROGRAMMERS:
7  */
8 
9 
10 /* INCLUDES ******************************************************************/
11 
12 #include <ntoskrnl.h>
13 #define NDEBUG
14 #include <debug.h>
15 
16 ULONG
17 NTAPI
19 {
20  return TrapFrame->Rsp;
21 }
22 
23 VOID
24 NTAPI
26  IN ULONG_PTR Esp)
27 {
28  KIRQL OldIrql;
29  ULONG Previous;
30 
31  /* Raise to APC_LEVEL if needed */
34 
35  /* Get the old ESP */
36  Previous = KiEspFromTrapFrame(TrapFrame);
37 
38  /* Check if this is user-mode */
39  if ((TrapFrame->SegCs & MODE_MASK))
40  {
41  /* Write it directly */
42  TrapFrame->Rsp = Esp;
43  }
44  else
45  {
46  /* Don't allow ESP to be lowered, this is illegal */
47  if (Esp < Previous) KeBugCheckEx(SET_OF_INVALID_CONTEXT,
48  Esp,
49  Previous,
50  (ULONG_PTR)TrapFrame,
51  0);
52 
53  /* Create an edit frame, check if it was alrady */
54  if (!(TrapFrame->SegCs & FRAME_EDITED))
55  {
56  /* Update the value */
57  TrapFrame->Rsp = Esp;
58  }
59  else
60  {
61  /* Check if ESP changed */
62  if (Previous != Esp)
63  {
64  /* Save CS */
65  TrapFrame->SegCs &= ~FRAME_EDITED;
66 
67  /* Save ESP */
68  TrapFrame->Rsp = Esp;
69  }
70  }
71  }
72 
73  /* Restore IRQL */
75 
76 }
77 
78 ULONG
79 NTAPI
81 {
82  if (TrapFrame->SegCs & MODE_MASK)
83  {
84  /* User mode, return the User SS */
85  return TrapFrame->SegSs | RPL_MASK;
86  }
87  else
88  {
89  /* Kernel mode */
90  return KGDT64_SYS_TSS;
91  }
92 }
93 
94 VOID
95 NTAPI
97  IN ULONG Ss)
98 {
99  /* Remove the high-bits */
100  Ss &= 0xFFFF;
101 
102  if (TrapFrame->SegCs & MODE_MASK)
103  {
104  /* Usermode, save the User SS */
105  TrapFrame->SegSs = Ss | RPL_MASK;
106  }
107 
108 }
109 
110 
111 
ULONG NTAPI KiEspFromTrapFrame(IN PKTRAP_FRAME TrapFrame)
Definition: kdb.c:18
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define IN
Definition: typedefs.h:39
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define MODE_MASK
Definition: orders.h:326
uint32_t ULONG_PTR
Definition: typedefs.h:65
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define RPL_MASK
Definition: ketypes.h:69
ULONG NTAPI KiSsFromTrapFrame(IN PKTRAP_FRAME TrapFrame)
Definition: kdb.c:80
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define KGDT64_SYS_TSS
Definition: ketypes.h:77
VOID NTAPI KiEspToTrapFrame(IN PKTRAP_FRAME TrapFrame, IN ULONG_PTR Esp)
Definition: kdb.c:25
unsigned int ULONG
Definition: retypes.h:1
#define FRAME_EDITED
Definition: ke.h:64
VOID NTAPI KiSsToTrapFrame(IN PKTRAP_FRAME TrapFrame, IN ULONG Ss)
Definition: kdb.c:96
#define APC_LEVEL
Definition: env_spec_w32.h:695
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