Skip to content

Commit

Permalink
WIP Add freeze code
Browse files Browse the repository at this point in the history
  • Loading branch information
tkreuzer committed Nov 29, 2023
1 parent 47522dc commit 699b672
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions ntoskrnl/ke/amd64/ipi.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,61 @@ static PKIPI_BROADCAST_WORKER KiIpiBroadcastWorkerTable[] =
NULL, // IPI_FREEZE
};

PKPRCB KiFreezeOwner;

VOID
FreezeOtherProcessors(
VOID)
{
PKPRCB CurrentPrcb = KeGetCurrentPrcb();

/* Try to acquire the freeze owner */
while (InterlockedCOmpareExchangePointer(&KiFreezeOwner, CurrentPrcb, NULL))

This comment has been minimized.

Copy link
@wnstngs

wnstngs Nov 30, 2023

-InterlockedCOmpareExchangePointer
+InterlockedCompareExchangePointer
{
/* Someone else was faster. We expect an NMI to freeze any time.
Spin here until we can grab the lock */
while (KiFreezeOwner != NULL)
{
KeMemoryBarrier();
}
}

/* We are the owner now */
CurrentPrcb->IpiFrozen = IPI_FROZEN_STATE_OWNER;

/* Loop all processors */
for (ULONG i = 0; i < KeNumberProcessors; i++)
{
PKPRCB TargetPrcb = KiProcessorBlock[i];
if (TargetPrcb != CurrentPrcb)
{
ASSERT(TargetPrcb->IpiFrozen == IPI_FROZEN_STATE_RUNNING);

/* Set the target to frozen */
TargetPrcb->IpiFrozen = IPI_FROZEN_STATE_TARGET_FREEZE;
}
}

/* Send the NMI */
HalpSendNMI(KeActiveProcessors & ~CurrentPrcb->SetMember);

/* Wait for all targets to be frozen */
for (ULONG i = 0; i < KeNumberProcessors; i++)
{
PKPRCB TargetPrcb = KiProcessorBlock[i];
if (TargetPrcb != CurrentPrcb)
{
/* Wait for the target to be frozen */
while (TargetPrcb->IpiFrozen != IPI_FROZEN_STATE_FROZEN)
{
KeMemoryBarrier();
}
}
}

/* All targets are frozen, we can continue */
}

VOID
FASTCALL
KiIpiInterruptHandler(
Expand Down

0 comments on commit 699b672

Please sign in to comment.