Skip to content

Commit

Permalink
fault fix caching
Browse files Browse the repository at this point in the history
  • Loading branch information
jxy-s committed Sep 20, 2024
1 parent 2bd8bfa commit 9251007
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions vfdynf/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,20 +384,24 @@ VOID AVrfEnableCurrentThreadFaultInjection(

BOOLEAN AVrfpShouldFaultInjectCached(
_In_ ULONG FaultType,
_In_ ULONG StackHash
_In_ ULONG StackHash,
_Inout_ PBOOLEAN FaultInject
)
{
BOOLEAN result;
PAVRF_STACK_ENTRY stackEntry;

result = FALSE;

AVrfEnterCriticalSection(&AVrfpFaultContext.CriticalSection);

if (AVrfpFaultContext.CriticalSection.RecursionCount > 1)
{
//
// Do not fault inject if we're recursing on this lock.
//
result = FALSE;
*FaultInject = FALSE;
result = TRUE;
goto Exit;
}

Expand All @@ -415,8 +419,6 @@ BOOLEAN AVrfpShouldFaultInjectCached(
{
AVrfpFaultContext.LastClear = NtGetTickCount64();
AVrfClearStackTable(&AVrfpFaultContext.StackTable);

result = TRUE;
goto Exit;
}
}
Expand All @@ -425,7 +427,6 @@ BOOLEAN AVrfpShouldFaultInjectCached(
StackHash);
if (!stackEntry || (stackEntry->Hash != StackHash))
{
result = TRUE;
goto Exit;
}

Expand All @@ -437,18 +438,20 @@ BOOLEAN AVrfpShouldFaultInjectCached(
//
if (stackEntry->Excluded)
{
result = FALSE;
*FaultInject = FALSE;
}
else if (!BooleanFlagOn(stackEntry->FaultMask, FaultType))
{
SetFlag(stackEntry->FaultMask, FaultType);
result = TRUE;
*FaultInject = TRUE;
}
else
{
result = FALSE;
*FaultInject = FALSE;
}

result = TRUE;

Exit:

AVrfLeaveCriticalSection(&AVrfpFaultContext.CriticalSection);
Expand Down Expand Up @@ -562,7 +565,7 @@ BOOLEAN AVrfShouldFaultInject(

count = RtlCaptureStackBackTrace(1, ARRAYSIZE(frames), frames, &stackHash);

if (!AVrfpShouldFaultInjectCached(FaultType, stackHash))
if (AVrfpShouldFaultInjectCached(FaultType, stackHash, &result))
{
goto Exit;
}
Expand Down

0 comments on commit 9251007

Please sign in to comment.