Skip to content

Commit

Permalink
Use NT_ASSERT, which bugchecks even if debugger not attached. A few a…
Browse files Browse the repository at this point in the history
…nalysis tweaks, too.
  • Loading branch information
bonsaiviking committed Nov 24, 2020
1 parent 05487f2 commit c05b2b0
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 81 deletions.
12 changes: 6 additions & 6 deletions packetWin7/npf/npf/Lo_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ CompletionRoutine(
_In_ PKEVENT CompletionEvent
)
{
ASSERT(CompletionEvent);
NT_ASSERT(CompletionEvent);

UNREFERENCED_PARAMETER(Irp);
UNREFERENCED_PARAMETER(DeviceObject);
Expand All @@ -469,8 +469,8 @@ InitWskData(
_Inout_ PKEVENT CompletionEvent
)
{
ASSERT(pIrp);
ASSERT(CompletionEvent);
NT_ASSERT(pIrp);
NT_ASSERT(CompletionEvent);

TRACE_ENTER();

Expand Down Expand Up @@ -566,8 +566,8 @@ InitWskBuffer_NBL(

TRACE_ENTER();

ASSERT(NetBufferList);
ASSERT(WskBuffer);
NT_ASSERT(NetBufferList);
NT_ASSERT(WskBuffer);

WskBuffer->Offset = BufferOffset;
WskBuffer->Length = NetBufferList->FirstNetBuffer->DataLength - BufferOffset;
Expand Down Expand Up @@ -605,7 +605,7 @@ FreeWskBuffer_NBL(
_Inout_ PWSK_BUF WskBuffer
)
{
ASSERT(WskBuffer);
NT_ASSERT(WskBuffer);

TRACE_ENTER();

Expand Down
10 changes: 4 additions & 6 deletions packetWin7/npf/npf/Loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,12 @@ NPF_TapLoopback(
FirstMDLLen = MmGetMdlByteCount(pMdl);
if (FirstMDLLen != numBytes) {
pTmpBuf = MmGetSystemAddressForMdlSafe(pMdl, HighPagePriority|MdlMappingNoExecute);
if (pTmpBuf != NULL) {
// See NPF_FreeNBCopies for TODO item related to this assert and
// justification for HighPagePriority above.
if (NT_VERIFY(pTmpBuf != NULL)) {
NdisFreeMemory(pTmpBuf, FirstMDLLen, 0);
}
else {
// See NPF_FreeNBCopies for TODO item related to this assert and
// justification for HighPagePriority above.
ASSERT(pTmpBuf);
}
// else? No good way to recover, we've leaked the memory.
}

/* Regardless, free the MDL */
Expand Down
63 changes: 29 additions & 34 deletions packetWin7/npf/npf/Openclos.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ NPF_StopUsingBinding(
PNPCAP_FILTER_MODULE pFiltMod, BOOLEAN AtDispatchLevel
)
{
ASSERT(pFiltMod != NULL);
NT_ASSERT(pFiltMod != NULL);
//
// There is no risk in calling this function from abobe passive level
// (i.e. DISPATCH, in this driver) as we acquire a spinlock and decrement a
Expand All @@ -337,15 +337,15 @@ NPF_StopUsingBinding(

FILTER_ACQUIRE_LOCK(&pFiltMod->AdapterHandleLock, AtDispatchLevel);

ASSERT(pFiltMod->AdapterHandleUsageCounter > 0);
NT_ASSERT(pFiltMod->AdapterHandleUsageCounter > 0);

pFiltMod->AdapterHandleUsageCounter--;

FILTER_RELEASE_LOCK(&pFiltMod->AdapterHandleLock, AtDispatchLevel);
}

//-------------------------------------------------------------------

_IRQL_requires_(PASSIVE_LEVEL)
VOID
NPF_CloseBinding(
_In_ PNPCAP_FILTER_MODULE pFiltMod
Expand All @@ -354,8 +354,7 @@ NPF_CloseBinding(
NDIS_EVENT Event;
NDIS_STATUS Status;

ASSERT(pFiltMod != NULL);
ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
NT_ASSERT(pFiltMod != NULL);

NdisInitializeEvent(&Event);
NdisResetEvent(&Event);
Expand Down Expand Up @@ -401,7 +400,7 @@ NPF_ResetBufferContents(
Curr = Open->PacketQueue.Flink;
while (Curr != &Open->PacketQueue)
{
ASSERT(Curr != NULL);
NT_ASSERT(Curr != NULL);
pCapData = CONTAINING_RECORD(Curr, NPF_CAP_DATA, PacketQueueEntry);
Curr = Curr->Flink;

Expand Down Expand Up @@ -803,7 +802,7 @@ NPF_StopUsingOpenInstance(
)
{
FILTER_ACQUIRE_LOCK(&pOpen->OpenInUseLock, AtDispatchLevel);
ASSERT(pOpen->PendingIrps[MaxState] > 0);
NT_ASSERT(pOpen->PendingIrps[MaxState] > 0);
pOpen->PendingIrps[MaxState]--;
FILTER_RELEASE_LOCK(&pOpen->OpenInUseLock, AtDispatchLevel);

Expand Down Expand Up @@ -924,8 +923,7 @@ NPF_ReleaseOpenInstanceResources(

TRACE_ENTER();

ASSERT(pOpen != NULL);
ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
NT_ASSERT(pOpen != NULL);

TRACE_MESSAGE1(PACKET_DEBUG_LOUD, "Open= %p", pOpen);

Expand Down Expand Up @@ -994,8 +992,7 @@ NPF_ReleaseFilterModuleResources(
{
TRACE_ENTER();

ASSERT(pFiltMod != NULL);
ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
NT_ASSERT(pFiltMod != NULL);

if (pFiltMod->PacketPool) // Release the packet buffer pool
{
Expand Down Expand Up @@ -1029,8 +1026,8 @@ NPF_GetDeviceMTU(
)
{
TRACE_ENTER();
ASSERT(pFiltMod != NULL);
ASSERT(pMtu != NULL);
NT_ASSERT(pFiltMod != NULL);
NT_ASSERT(pMtu != NULL);

UINT Mtu = 0;
ULONG BytesProcessed = 0;
Expand Down Expand Up @@ -1075,13 +1072,13 @@ NPF_GetDeviceMTU(
_Use_decl_annotations_
NTSTATUS
NPF_GetDataRateMappingTable(
IN PNPCAP_FILTER_MODULE pFiltMod,
OUT PDOT11_DATA_RATE_MAPPING_TABLE pDataRateMappingTable
PNPCAP_FILTER_MODULE pFiltMod,
PDOT11_DATA_RATE_MAPPING_TABLE pDataRateMappingTable
)
{
TRACE_ENTER();
ASSERT(pFiltMod != NULL);
ASSERT(pDataRateMappingTable != NULL);
NT_ASSERT(pFiltMod != NULL);
NT_ASSERT(pDataRateMappingTable != NULL);

ULONG BytesProcessed = 0;
PVOID pBuffer = NULL;
Expand Down Expand Up @@ -1163,8 +1160,8 @@ NPF_GetCurrentOperationMode(
)
{
TRACE_ENTER();
ASSERT(pFiltMod != NULL);
ASSERT(pCurrentOperationMode != NULL);
NT_ASSERT(pFiltMod != NULL);
NT_ASSERT(pCurrentOperationMode != NULL);

DOT11_CURRENT_OPERATION_MODE CurrentOperationMode = { 0 };
ULONG BytesProcessed = 0;
Expand Down Expand Up @@ -1237,8 +1234,8 @@ NPF_GetCurrentChannel(
)
{
TRACE_ENTER();
ASSERT(pFiltMod != NULL);
ASSERT(pCurrentChannel != NULL);
NT_ASSERT(pFiltMod != NULL);
NT_ASSERT(pCurrentChannel != NULL);

ULONG CurrentChannel = 0;
ULONG BytesProcessed = 0;
Expand Down Expand Up @@ -1308,8 +1305,8 @@ NPF_GetCurrentFrequency(
)
{
TRACE_ENTER();
ASSERT(pFiltMod != NULL);
ASSERT(pCurrentFrequency != NULL);
NT_ASSERT(pFiltMod != NULL);
NT_ASSERT(pCurrentFrequency != NULL);

ULONG CurrentFrequency = 0;
ULONG BytesProcessed = 0;
Expand Down Expand Up @@ -1437,7 +1434,7 @@ NPF_Cleanup(

TRACE_MESSAGE1(PACKET_DEBUG_LOUD, "Open = %p\n", Open);

ASSERT(Open != NULL);
NT_ASSERT(Open != NULL);

NPF_RemoveFromGroupOpenArray(Open); //Remove the Open from the filter module's list

Expand Down Expand Up @@ -1561,7 +1558,7 @@ NPF_RemoveFromFilterModuleArray(
PSINGLE_LIST_ENTRY Curr = NULL;

TRACE_ENTER();
ASSERT(pFiltMod != NULL);
NT_ASSERT(pFiltMod != NULL);

NdisAcquireSpinLock(&g_FilterArrayLock);

Expand Down Expand Up @@ -2145,8 +2142,7 @@ Return Value:
{
TRACE_ENTER();

ASSERT(FilterDriverContext == (NDIS_HANDLE)FilterDriverObject);
if (FilterDriverContext != (NDIS_HANDLE)FilterDriverObject)
if (!NT_VERIFY(FilterDriverContext == (NDIS_HANDLE)FilterDriverObject))
{
IF_LOUD(DbgPrint("NPF_RegisterOptions: driver doesn't match error, FilterDriverContext = %p, FilterDriverObject = %p.\n", FilterDriverContext, FilterDriverObject);)
return NDIS_STATUS_INVALID_PARAMETER;
Expand Down Expand Up @@ -2219,8 +2215,7 @@ NPF_AttachAdapter(

do
{
ASSERT(FilterDriverContext == (NDIS_HANDLE)FilterDriverObject);
if (FilterDriverContext != (NDIS_HANDLE)FilterDriverObject)
if (!NT_VERIFY(FilterDriverContext == (NDIS_HANDLE)FilterDriverObject))
{
returnStatus = NDIS_STATUS_INVALID_PARAMETER;
break;
Expand Down Expand Up @@ -2435,7 +2430,7 @@ NPF_Pause(
NdisResetEvent(&Event);

NdisAcquireSpinLock(&pFiltMod->AdapterHandleLock);
ASSERT(pFiltMod->AdapterBindingStatus == FilterRunning);
NT_ASSERT(pFiltMod->AdapterBindingStatus == FilterRunning);
pFiltMod->AdapterBindingStatus = FilterPausing;

while (pFiltMod->AdapterHandleUsageCounter > 0)
Expand Down Expand Up @@ -2480,7 +2475,7 @@ NPF_Restart(
}

NdisAcquireSpinLock(&pFiltMod->AdapterHandleLock);
ASSERT(pFiltMod->AdapterBindingStatus == FilterPaused);
NT_ASSERT(pFiltMod->AdapterBindingStatus == FilterPaused);
pFiltMod->AdapterBindingStatus = FilterRestarting;
NdisReleaseSpinLock(&pFiltMod->AdapterHandleLock);

Expand Down Expand Up @@ -2549,7 +2544,7 @@ NOTE: Called at PASSIVE_LEVEL and the filter is in paused state

TRACE_ENTER();

ASSERT(pFiltMod->AdapterBindingStatus == FilterPaused || pFiltMod->Loopback);
NT_ASSERT(pFiltMod->AdapterBindingStatus == FilterPaused || pFiltMod->Loopback);
/* No need to lock the group since we are paused. */
for (Curr = pFiltMod->OpenInstances.Next; Curr != NULL; Curr = Curr->Next)
{
Expand Down Expand Up @@ -2823,7 +2818,7 @@ Routine Description:

FILTER_ACQUIRE_LOCK(&pFiltMod->OIDLock, NPF_IRQL_UNKNOWN);

ASSERT(pFiltMod->PendingOidRequest == Request);
NT_ASSERT(pFiltMod->PendingOidRequest == Request);
pFiltMod->PendingOidRequest = NULL;

FILTER_RELEASE_LOCK(&pFiltMod->OIDLock, NPF_IRQL_UNKNOWN);
Expand Down Expand Up @@ -3197,7 +3192,7 @@ NPF_SetPacketFilter(
PNPCAP_FILTER_MODULE pFiltMod = pOpen->pFiltMod;
LOCK_STATE_EX lockState;

ASSERT(pFiltMod != NULL);
NT_ASSERT(pFiltMod != NULL);

#ifdef HAVE_WFP_LOOPBACK_SUPPORT
if (pFiltMod->Loopback) {
Expand Down
2 changes: 1 addition & 1 deletion packetWin7/npf/npf/Packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,7 @@ NPF_IoControl(

if (OidData->Oid == OID_GEN_CURRENT_PACKET_FILTER && FunctionCode == BIOCSETOID)
{
ASSERT(Open->pFiltMod != NULL);
NT_ASSERT(Open->pFiltMod != NULL);

// Disable setting Packet Filter for wireless adapters, because this will cause limited connectivity.
if (Open->pFiltMod->PhysicalMedium == NdisPhysicalMediumNative802_11)
Expand Down
3 changes: 3 additions & 0 deletions packetWin7/npf/npf/Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,11 @@ NPF_CreateFilterModule(
_In_ UINT SelectedIndex
);

_IRQL_requires_(PASSIVE_LEVEL)
VOID
NPF_ReleaseOpenInstanceResources(_Inout_ POPEN_INSTANCE pOpen);

_IRQL_requires_(PASSIVE_LEVEL)
VOID
NPF_ReleaseFilterModuleResources(_Inout_ PNPCAP_FILTER_MODULE pFiltMod);

Expand Down
Loading

0 comments on commit c05b2b0

Please sign in to comment.