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

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOLEAN KiProcessorFreezeHandler (_In_ PKTRAP_FRAME TrapFrame, _In_ PKEXCEPTION_FRAME ExceptionFrame)
 
VOID NTAPI KxFreezeExecution (VOID)
 
VOID NTAPI KxThawExecution (VOID)
 
KCONTINUE_STATUS NTAPI KxSwitchKdProcessor (_In_ ULONG ProcessorIndex)
 

Variables

PKPRCB KiFreezeOwner
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file freeze.c.

Function Documentation

◆ KiProcessorFreezeHandler()

BOOLEAN KiProcessorFreezeHandler ( _In_ PKTRAP_FRAME  TrapFrame,
_In_ PKEXCEPTION_FRAME  ExceptionFrame 
)

Definition at line 21 of file freeze.c.

24{
25 PKPRCB CurrentPrcb = KeGetCurrentPrcb();
26
27 /* Make sure this is a freeze request */
28 if (CurrentPrcb->IpiFrozen != IPI_FROZEN_STATE_TARGET_FREEZE)
29 {
30 /* Not a freeze request, return FALSE to signal it is unhandled */
31 return FALSE;
32 }
33
34 /* We are frozen now */
36
37 /* Save the processor state */
38 KiSaveProcessorState(TrapFrame, ExceptionFrame);
39
40 /* Wait for the freeze owner to release us */
41 while (CurrentPrcb->IpiFrozen != IPI_FROZEN_STATE_THAW)
42 {
43 /* Check for Kd processor switch */
44 if (CurrentPrcb->IpiFrozen & IPI_FROZEN_FLAG_ACTIVE)
45 {
46 KCONTINUE_STATUS ContinueStatus;
47
48 /* Enter the debugger */
49 ContinueStatus = KdReportProcessorChange();
50
51 /* Set the state back to frozen */
53
54 /* If the status is ContinueSuccess, we need to release the freeze owner */
55 if (ContinueStatus == ContinueSuccess)
56 {
57 /* Release the freeze owner */
59 }
60 }
61
64 }
65
66 /* Restore the processor state */
67 KiRestoreProcessorState(TrapFrame, ExceptionFrame);
68
69 /* We are running again now */
71
72 /* Return TRUE to signal that we handled the freeze */
73 return TRUE;
74}
PKPRCB KiFreezeOwner
Definition: freeze.c:16
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
KCONTINUE_STATUS NTAPI KdReportProcessorChange(VOID)
Definition: kdapi.c:1810
#define IPI_FROZEN_STATE_TARGET_FREEZE
Definition: ketypes.h:315
#define IPI_FROZEN_FLAG_ACTIVE
Definition: ketypes.h:316
#define IPI_FROZEN_STATE_RUNNING
Definition: ketypes.h:311
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1161
#define IPI_FROZEN_STATE_THAW
Definition: ketypes.h:313
#define IPI_FROZEN_STATE_FROZEN
Definition: ketypes.h:312
enum _KCONTINUE_STATUS KCONTINUE_STATUS
@ ContinueSuccess
Definition: ketypes.h:450
VOID NTAPI KiSaveProcessorState(_In_ PKTRAP_FRAME TrapFrame, _In_ PKEXCEPTION_FRAME ExceptionFrame)
Definition: cpu.c:617
VOID NTAPI KiRestoreProcessorState(_Out_ PKTRAP_FRAME TrapFrame, _Out_ PKEXCEPTION_FRAME ExceptionFrame)
Definition: cpu.c:633
#define YieldProcessor
Definition: ke.h:48
FORCEINLINE VOID KeMemoryBarrier(VOID)
Definition: ke.h:58
ULONG IpiFrozen
Definition: ketypes.h:755

Referenced by KiNmiInterruptHandler().

◆ KxFreezeExecution()

VOID NTAPI KxFreezeExecution ( VOID  )

Definition at line 78 of file freeze.c.

80{
81 PKPRCB CurrentPrcb = KeGetCurrentPrcb();
82
83 /* Avoid blocking on recursive debug action */
84 if (KiFreezeOwner == CurrentPrcb)
85 {
86 return;
87 }
88
89 /* Try to acquire the freeze owner */
91 {
92 /* Someone else was faster. We expect an NMI to freeze any time.
93 Spin here until the freeze owner is available. */
94 while (KiFreezeOwner != NULL)
95 {
98 }
99 }
100
101 /* We are the owner now */
102 CurrentPrcb->IpiFrozen = IPI_FROZEN_STATE_OWNER;
103
104 /* Loop all processors */
105 for (ULONG i = 0; i < KeNumberProcessors; i++)
106 {
107 PKPRCB TargetPrcb = KiProcessorBlock[i];
108 if (TargetPrcb != CurrentPrcb)
109 {
110 /* Nobody else is allowed to change IpiFrozen, except the freeze owner */
112
113 /* Request target to freeze */
115 }
116 }
117
118 /* Send the freeze IPI */
120
121 /* Wait for all targets to be frozen */
122 for (ULONG i = 0; i < KeNumberProcessors; i++)
123 {
124 PKPRCB TargetPrcb = KiProcessorBlock[i];
125 if (TargetPrcb != CurrentPrcb)
126 {
127 /* Wait for the target to be frozen */
128 while (TargetPrcb->IpiFrozen != IPI_FROZEN_STATE_FROZEN)
129 {
132 }
133 }
134 }
135
136 /* All targets are frozen, we can continue */
137}
#define NULL
Definition: types.h:112
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
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
#define ASSERT(a)
Definition: mode.c:44
#define IPI_FREEZE
Definition: ketypes.h:299
#define IPI_FROZEN_STATE_OWNER
Definition: ketypes.h:314
PKPRCB KiProcessorBlock[]
Definition: krnlinit.c:32
KAFFINITY KeActiveProcessors
Definition: krnlinit.c:23
VOID FASTCALL KiIpiSend(KAFFINITY TargetSet, ULONG IpiRequest)
UINT64 SetMember
Definition: ketypes.h:662
uint32_t ULONG
Definition: typedefs.h:59

Referenced by KeFreezeExecution().

◆ KxSwitchKdProcessor()

KCONTINUE_STATUS NTAPI KxSwitchKdProcessor ( _In_ ULONG  ProcessorIndex)

Definition at line 184 of file freeze.c.

186{
187 PKPRCB CurrentPrcb = KeGetCurrentPrcb();
188 PKPRCB TargetPrcb;
189
190 /* Make sure that the processor index is valid */
191 ASSERT(ProcessorIndex < KeNumberProcessors);
192
193 /* Inform the target processor that it's his turn now */
194 TargetPrcb = KiProcessorBlock[ProcessorIndex];
195 TargetPrcb->IpiFrozen |= IPI_FROZEN_FLAG_ACTIVE;
196
197 /* If we are not the freeze owner, we return back to the freeze loop */
198 if (KiFreezeOwner != CurrentPrcb)
199 {
201 }
202
203 /* Loop until it's our turn again */
204 while (CurrentPrcb->IpiFrozen == IPI_FROZEN_STATE_OWNER)
205 {
208 }
209
210 /* Check if we have been thawed */
211 if (CurrentPrcb->IpiFrozen == IPI_FROZEN_STATE_THAW)
212 {
213 /* Another CPU has completed, we can leave the debugger now */
214 KdpDprintf("[%u] KxSwitchKdProcessor: ContinueSuccess\n", KeGetCurrentProcessorNumber());
215 CurrentPrcb->IpiFrozen = IPI_FROZEN_STATE_OWNER;
216 return ContinueSuccess;
217 }
218
219 /* We have been reselected, return to Kd to continue in the debugger */
220 CurrentPrcb->IpiFrozen = IPI_FROZEN_STATE_OWNER;
221
223}
#define KdpDprintf(...)
Definition: mmdbg.c:19
@ ContinueNextProcessor
Definition: ketypes.h:452
@ ContinueProcessorReselected
Definition: ketypes.h:451
FORCEINLINE ULONG KeGetCurrentProcessorNumber(VOID)
Definition: ke.h:341

◆ KxThawExecution()

VOID NTAPI KxThawExecution ( VOID  )

Definition at line 141 of file freeze.c.

143{
144 PKPRCB CurrentPrcb = KeGetCurrentPrcb();
145
146 /* Loop all processors */
147 for (ULONG i = 0; i < KeNumberProcessors; i++)
148 {
149 PKPRCB TargetPrcb = KiProcessorBlock[i];
150 if (TargetPrcb != CurrentPrcb)
151 {
152 /* Make sure they are still frozen */
154
155 /* Request target to thaw */
156 TargetPrcb->IpiFrozen = IPI_FROZEN_STATE_THAW;
157 }
158 }
159
160 /* Wait for all targets to be running */
161 for (ULONG i = 0; i < KeNumberProcessors; i++)
162 {
163 PKPRCB TargetPrcb = KiProcessorBlock[i];
164 if (TargetPrcb != CurrentPrcb)
165 {
166 /* Wait for the target to be running again */
167 while (TargetPrcb->IpiFrozen != IPI_FROZEN_STATE_RUNNING)
168 {
171 }
172 }
173 }
174
175 /* We are running again now */
176 CurrentPrcb->IpiFrozen = IPI_FROZEN_STATE_RUNNING;
177
178 /* Release the freeze owner */
180}
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45

Referenced by KeThawExecution().

Variable Documentation

◆ KiFreezeOwner

PKPRCB KiFreezeOwner