Condividi tramite


Aggiornamento delle chiamate ExAllocatePool deprecate a ExAllocatePool2 e ExAllocatePool3

Le DDI seguenti sono deprecate a partire da Windows 10, versione 2004 e devono essere sostituite come descritto in questo articolo.

exAllocatePool

ExAllocatePoolWithTag

ExAllocatePoolWithQuota

ExAllocatePoolWithQuotaTag

ExAllocatePoolWithTagPriority

Aggiornamenti dei driver per le versioni di Windows 10, versione 2004 e successive

Se stai creando un driver destinato a Windows 10, versione 2004 e successive, usa invece le API di sostituzione ExAllocatePool2 e ExAllocatePool3 .

API precedente Nuova API
ExAllocatePool exAllocatePool2
ExAllocatePoolWithTag exAllocatePool2
ExAllocatePoolWithQuota exAllocatePool2
ExAllocatePoolWithQuotaTag exAllocatePool2
ExAllocatePoolWithTagPriority exAllocatePool3

Le nuove API non eseguiranno allocazioni di pool per impostazione predefinita, per evitare possibili bug di divulgazione della memoria.

ExAllocatePool/ExAllocatePoolWithTag

// Old code
PVOID Allocation = ExAllocatePoolWithTag(PagedPool, 100, 'abcd');
RtlZeroMemory(Allocation, 100);

// New code
PVOID Allocation = ExAllocatePool2(POOL_FLAG_PAGED, 100, 'abcd');

Le API di allocazione del pool precedenti accettano un argomento POOL_TYPE , ma le nuove API di allocazione accettano un argomento POOL_FLAGS . Aggiornare qualsiasi codice associato per usare il nuovo argomento POOL_FLAGS .

ExAllocatePoolWithQuota/ExAllocatePoolWithQuotaTag

La nuova funzione restituirà NULL in caso di fallimento dell'allocazione di default. Per fare invece che l'allocatore generi un'eccezione in caso di errore, il flag POOL_FLAG_RAISE_ON_FAILURE deve essere passato come descritto in ExAllocatePool2.

// Old code
PVOID Allocation = ExAllocatePoolWithQuotaTag(PagedPool | POOL_QUOTA_FAIL_INSTEAD_OF_RAISE, 100, 'abcd');
RtlZeroMemory(Allocation, 100);

// New code
PVOID Allocation = ExAllocatePool2(POOL_FLAG_PAGED | POOL_FLAG_USE_QUOTA, 100, 'abcd');

ExAllocatePoolWithTagPriority

// Old code
PVOID Allocation = ExAllocatePoolWithTagPriority(PagedPool, 100, 'abcd', HighPoolPriority);
RtlZeroMemory(Allocation, 100);

// New code
POOL_EXTENDED_PARAMETER params = {0};
params.Type = PoolExtendedParameterPriority;
params.Priority = HighPoolPriority;
PVOID Allocation = ExAllocatePool3(POOL_FLAG_PAGED, 100, 'abcd', &params, 1);

Aggiornamenti dei driver per le versioni di Windows precedenti a Windows 10, versione 2004

Se stai creando un driver destinato alle versioni di Windows precedenti a Windows 10, versione 2004, devi usare le seguenti funzioni wrapper force inline.

È inoltre necessario #define POOL_ZERO_DOWN_LEVEL_SUPPORT e chiamare ExInitializeDriverRuntime durante l'inizializzazione del driver, prima di chiamare le funzioni di allocazione del pool.

Funzioni inline definite in locale

PVOID
NTAPI
ExAllocatePoolZero (
    _In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
    _In_ SIZE_T NumberOfBytes,
    _In_ ULONG Tag
    )

PVOID
NTAPI
ExAllocatePoolQuotaZero (
    _In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
    _In_ SIZE_T NumberOfBytes,
    _In_ ULONG Tag
    )

PVOID
NTAPI
ExAllocatePoolPriorityZero (
    _In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
    _In_ SIZE_T NumberOfBytes,
    _In_ ULONG Tag,
    _In_ EX_POOL_PRIORITY Priority
    )

Fare riferimento all'intestazione più recente wdm.h per il codice di implementazione relativo a questi contenitori di codice. Ad esempio, questa è l'implementazione per ExAllocatePoolPriorityZero, che mostra l'uso di RtlZeroMemory.

{
    PVOID Allocation;

    Allocation = ExAllocatePoolWithTagPriority((POOL_TYPE) (PoolType | POOL_ZERO_ALLOCATION),
                                               NumberOfBytes,
                                               Tag,
                                               Priority);

#if defined(POOL_ZERO_DOWN_LEVEL_SUPPORT)

    if ((!ExPoolZeroingNativelySupported) && (Allocation != NULL)) {
        RtlZeroMemory(Allocation, NumberOfBytes);
    }

#endif

    return Allocation;
}

Mapping delle API precedenti alle nuove API

API precedente Nuova API
ExAllocatePool ExAllocatePoolZero
ExAllocatePoolWithTag ExAllocatePoolZero
ExAllocatePoolWithQuota ExAllocatePoolQuotaZero
ExAllocatePoolWithQuotaTag ExAllocatePoolQuotaZero
ExAllocatePoolWithTagPriority ExAllocatePoolPriorityZero

Esempio

// Old code
PVOID Allocation = ExAllocatePoolWithTag(PagedPool, 100, 'abcd');
RtlZeroMemory(Allocation, 100);

// New code

// Before headers are pulled in (or compiler defined)
#define POOL_ZERO_DOWN_LEVEL_SUPPORT

// Once during driver initialization
// Argument can be any value
ExInitializeDriverRuntime(0);

// Replacement for each pool allocation
PVOID Allocation = ExAllocatePoolZero(PagedPool, 100, 'abcd');

Regole UnSafeAllocatePool del verificatore del driver

La regola UnSafeAllocatePool del driver è una regola di sicurezza importante che verifica che un driver non usi DDI deprecati per allocare memoria. Questa regola è disponibile in anteprima nelle build del WDK 20236 e successive.

Vedere anche

exAllocatePool2

exAllocatePool3

exAllocatePool

ExAllocatePoolWithTag

ExAllocatePoolWithQuota

ExAllocatePoolWithQuotaTag

ExAllocatePoolWithTagPriority