/*++

    Copyright (c) Microsoft Corporation.  All rights reserved.

Rule Name:

    NdisOpenConfigurationEx

Domain:

    ndis

Rule ID:

    Not Applicable

Description:

    This rule checks that NdisOpenConfigurationEx and NdisCloseConfiguration are called 
    in alternate order. The ultimate goal is to make sure that conifguration handles are closed
    when MiniportHaltEx ends.
    
    Description:
    The rule uses three different states. State changes when a configuraion is opened or closed.
    If a configuration handle is still open when the MiniportHaltEx exits, then the rule will fail. 
    
    Related Rule:

Help Link:

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

--*/




#include "slic_base.h"

state{
   enum {initial, set, not_set} s = initial;
}
watch NdisOpenConfigurationEx.entry.(*$2);

NdisOpenConfigurationEx.exit[guard *$2]
{  
    if ($return == NDIS_STATUS_SUCCESS)
    {
        s = set;
    }
    
}

NdisCloseConfiguration.exit[guard $1]
{
    if ( s == not_set)
    {
        abort "Closing a configuration that was not open.";
    }
  
    s = not_set;
}

sdv_MINIPORT_HALT.exit
{
    if (s == set) 
    {
        abort "You are halting the miniport but still have some handles to configuration open.";
    }
}
