/*++

    Copyright (c) Microsoft Corporation.  All rights reserved.

Rule Name:

    Irql_Miscellaneous_Function

Domain:

    ndis

Rule ID:

    Not Applicable

Description:

    This rule verifies that DDIs are only called at proper IRQL levels.

    Check for the proper IRQL when the function is entering.
    
    Related Rule:

Help Link:

    https://go.microsoft.com/fwlink/?LinkId=507178

--*/



#include "slic_base.h"

KeGetCurrentProcessorNumber.entry
{
    if ( LTDISPATCH(sdv_irql_current) ) {
        abort "Warning:If the call to $fname occurs at IRQL <= APC_LEVEL, a processor switch can occur between instructions. Consequently, callers of $fname usually should run at IRQL >= DISPATCH_LEVEL.";
    }
}

NdisAllocateFromNPagedLookasideList.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisAllocateGenericObject.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisAllocateIoWorkItem.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisAllocateMemoryWithTagPriority.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisAnsiStringToUnicodeString.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisCloseConfiguration.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisCloseFile.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisDeleteNPagedLookasideList.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisDeregisterDeviceEx.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisEqualMemory.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisEqualString.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisEqualUnicodeString.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisFreeGenericObject.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisFreeIoWorkItem.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisFreeMemory.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisFreeString.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisFreeToNPagedLookasideList.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisGeneratePartialCancelId.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisGetCurrentProcessorCounts.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

/* Not supported in NDIS 6.X NDIS 5.X DDI
sdv_NdisGetDriverHandle.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}*/

NdisGetRoutineAddress.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisGetSharedDataAlignment.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisGetVersion.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisInitAnsiString.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisInitializeNPagedLookasideList.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisInitializeString.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisInitUnicodeString.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisMapFile.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisOpenConfigurationEx.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisOpenConfigurationKeyByIndex.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL && sdv_irql_current != APC_LEVEL ) {
        abort "$fname should only be called at IRQL < DISPATCH_LEVEL.";
    }
}

NdisOpenConfigurationKeyByName.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL && sdv_irql_current != APC_LEVEL ) {
        abort "$fname should only be called at IRQL < DISPATCH_LEVEL.";
    }
}

NdisOpenFile.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisQueryAdapterInstanceName.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisQueryDepthSList.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisQueueIoWorkItem.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisReadConfiguration.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisReadNetworkAddress.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisReEnumerateProtocolBindings.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisRegisterDeviceEx.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisSetOptionalHandlers.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisSystemProcessorCount.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisUnicodeStringToAnsiString.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisUnmapFile.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisUpcaseUnicodeString.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisWaitEvent.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisWriteConfiguration.entry
{
    if ( sdv_irql_current != PASSIVE_LEVEL ) {
        abort "$fname should only be called at IRQL  = PASSIVE_LEVEL.";
    }
}

NdisWriteErrorLogEntry.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

NdisWriteEventLogEntry.entry
{
    if ( SDV_IRQL_ELEVATED_LEVEL(sdv_irql_current) ) {
        abort "$fname should only be called at IRQL <= DISPATCH_LEVEL.";
    }
}

