Regola irqlExAllocatePool (wdm)

La regola IrqlExAllocatePool specifica che il driver chiama ExAllocatePoolWithTag e ExAllocatePoolWithTagWithTagPriority solo quando viene eseguito in IRQL<=DISPATCH_LEVEL.

Un chiamante in esecuzione in DISPATCH_LEVEL deve specificare un valoreNonPaged Xxx per PoolType. Un chiamante in esecuzione in IRQL <= APC_LEVEL può specificare qualsiasi valore POOL_TYPE .

Modello di driver: WDM

Controllo bug trovato con questa regola: Controllo bug 0xC4: DRIVER_VERIFIER_DETECTED_VIOLATION (0x00020004 ), Verifica bug 0xA: IRQL_NOT_LESS_OR_EQUAL

Esempio

Nell'esempio seguente viene chiamata la routine ExAllocatePoolWithTag dopo la routine KeAcquireSpinLock , che imposta IRQL su DISPATCH_LEVEL. La routine ExAllocatePoolWithTag viene chiamata con PagedPool, che viola la regola.

NTSTATUS
DispatchRequest (
    __in PDEVICE_REQUEST DeviceRequest
    )
{  
    KIRQL OldIrql;
    KSPIN_LOCK SpinLock;
    NTSTATUS Status;
    ...

    KeInitializeSpinLock(&SpinLock);

    //
    // KeAcquireSpinLock sets IRQL to DISPATCH_LEVEL and the previous IRQL is 
    // written to OldIrql after the lock is acquired.
    //

    KeAcquireSpinLock(&SpinLock, &OldIrql);
    ...

    Status = ProcessRequest(DeviceRequest);

    //
    // KeReleaseSpinLock sets IRQL to the OldIrql returned by KeAcquireSpinLock.
    //

    KeReleaseSpinLock(&SpinLock, &OldIrql);
    ...
}

NTSTATUS
ProcessRequest (
    __in PDEVICE_REQUEST DeviceRequest
    )
{
    NTSTATUS Status;
    ...

    //
    // RULE VIOLATION! - IrqlExAllocatePool executing at DISPATCH_LEVEL must specify 
    //                   a NonPagedXxx value for PoolType. 
    //

    DeviceRequest->Context = ExAllocatePool(PagedPool, sizeof(REQUEST_CONTEXT));
    if (DeviceRequest->Context == NULL) {
        Status = STATUS_INSUFFICIENT_RESOURCES;
    }
    ...

    return Status;
}

Come eseguire il test

In fase di compilazione

Eseguire il verifica driver statico e specificare la regola IrqlExAllocatePool .

Usa i passaggi descritti di seguito per eseguire un'analisi del codice:
  1. Prepara il codice (usa dichiarazioni di tipo ruolo).
  2. Esegui Driver Verifier statico.
  3. Visualizza e analizza i risultati.

Per altre informazioni, vedere Uso del verificatore driver statico per trovare i difetti nei driver.

In fase di esecuzione

Eseguire il verifica driver e selezionare l'opzione di controllo della conformità DDI .

Si applica a

ExAllocatePoolWithTag ExAllocatePoolWithTagPriority

Vedi anche

Gestione delle priorità hardwareche impediscono errori e deadlock durante l'uso di blocchi spin