Skip to content

Commit

Permalink
Assure code analysis that IRQL is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsaiviking committed Apr 4, 2022
1 parent 3a274c8 commit 78c851c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
29 changes: 15 additions & 14 deletions packetWin7/npf/npf/Openclos.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,16 +763,17 @@ NPF_StartUsingOpenInstance(
}

FILTER_ACQUIRE_LOCK(&pOpen->OpenInUseLock, AtDispatchLevel);
if (MaxState == OpenRunning && pOpen->OpenStatus == OpenAttached)
if (MaxState == OpenRunning)
{
pOpen->OpenStatus = OpenInitializing;
// NPF_EnableOps must be called at PASSIVE_LEVEL. Release the lock first.
NT_ASSERT(!AtDispatchLevel);
if (AtDispatchLevel) {
// This is really bad! We should never be able to get here.
returnStatus = FALSE;
}
else {
else if (pOpen->OpenStatus == OpenAttached)
{
pOpen->OpenStatus = OpenInitializing;
FILTER_RELEASE_LOCK(&pOpen->OpenInUseLock, AtDispatchLevel);
returnStatus = NT_SUCCESS(NPF_EnableOps(pOpen->pFiltMod));
FILTER_ACQUIRE_LOCK(&pOpen->OpenInUseLock, AtDispatchLevel);
Expand All @@ -798,18 +799,18 @@ NPF_StartUsingOpenInstance(
pOpen->OpenStatus = OpenAttached;
}
}
}
else if (MaxState == OpenRunning && pOpen->OpenStatus == OpenInitializing)
{
// Wait until it's ready...
NdisInitializeEvent(&Event);
NdisResetEvent(&Event);
// Wait for other thread to finish enabling
while (pOpen->OpenStatus == OpenInitializing)
else if (pOpen->OpenStatus == OpenInitializing)
{
FILTER_RELEASE_LOCK(&pOpen->OpenInUseLock, AtDispatchLevel);
NdisWaitEvent(&Event, 1);
FILTER_ACQUIRE_LOCK(&pOpen->OpenInUseLock, AtDispatchLevel);
// Wait until it's ready...
NdisInitializeEvent(&Event);
NdisResetEvent(&Event);
// Wait for other thread to finish enabling
while (pOpen->OpenStatus == OpenInitializing)
{
FILTER_RELEASE_LOCK(&pOpen->OpenInUseLock, AtDispatchLevel);
NdisWaitEvent(&Event, 1);
FILTER_ACQUIRE_LOCK(&pOpen->OpenInUseLock, AtDispatchLevel);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packetWin7/npf/npf/Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ _When_(AtDispatchLevel != FALSE, _IRQL_requires_(DISPATCH_LEVEL))
VOID NPF_StopUsingBinding(_Inout_ PNPCAP_FILTER_MODULE pFiltMod, _In_ BOOLEAN AtDispatchLevel);

_When_(AtDispatchLevel != FALSE, _IRQL_requires_(DISPATCH_LEVEL))
_When_(pOpen->OpenStatus > OpenRunning, _IRQL_requires_(PASSIVE_LEVEL))
_When_(MaxOpen == OpenRunning, _IRQL_requires_(PASSIVE_LEVEL))
BOOLEAN NPF_StartUsingOpenInstance(_Inout_ POPEN_INSTANCE pOpen, _In_range_(OpenRunning,OpenDetached) OPEN_STATE MaxOpen, _In_ BOOLEAN AtDispatchLevel);

_When_(AtDispatchLevel != FALSE, _IRQL_requires_(DISPATCH_LEVEL))
Expand Down

0 comments on commit 78c851c

Please sign in to comment.