Aracılığıyla paylaş


Kullanım dışı bırakılan ExAllocatePool çağrılarını ExAllocatePool2 ve ExAllocatePool3'e güncelleştirme

Aşağıdaki DDI'ler Windows 10, sürüm 2004'den itibaren kullanımdan kaldırılmıştır ve bu makalede açıklandığı gibi değiştirilmelidir.

ExAllocatePool

ExAllocatePoolWithTag

ExAllocatePoolWithQuota

ExAllocatePoolWithQuotaTag

exAllocatePoolWithTagPriority

Windows 10, sürüm 2004 ve üzeri sürümler için sürücü güncelleştirmeleri

Windows 10, sürüm 2004 ve sonraki sürümleri hedefleyen bir sürücü oluşturuyorsanız, bunun yerine ExAllocatePool2 ve ExAllocatePool3 api'lerini kullanın.

Eski API Yeni API
ExAllocatePool ExAllocatePool2
ExAllocatePoolWithTag ExAllocatePool2
ExAllocatePoolWithQuota ExAllocatePool2
ExAllocatePoolWithQuotaTag ExAllocatePool2
Bellek Havuzu Ayırma Etiketi Önceliği ExAllocatePool3

Yeni API'ler, olası bellek açıklama hatalarını önlemeye yardımcı olmak için varsayılan olarak havuz ayırmalarını sıfırlar.

ExAllocatePool/ExAllocatePoolWithTag

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

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

Eski havuz ayırma API'leri POOL_TYPE bağımsız değişkenini kabul etse de yeni ayırma API'leri POOL_FLAGS bağımsız değişkenini kabul etti. yeni POOL_FLAGS bağımsız değişkenini kullanmak için ilgili tüm kodları güncelle.

ExAllocatePoolWithQuota/ExAllocatePoolWithQuotaTag

Yeni işlev artık varsayılan olarak ayırma hatasında NULL döndürür. Bunun yerine ayırıcının hata durumunda bir özel durum yükseltmesini sağlamak için, POOL_FLAG_RAISE_ON_FAILURE bayrağı, ExAllocatePool2'de açıklandığı gibi geçirilmelidir.

// 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);

Windows 10, sürüm 2004'ten önceki Windows sürümleri için sürücü güncelleştirmeleri

Windows 10, sürüm 2004 öncesi Windows sürümlerini hedefleyen bir sürücü oluşturuyorsanız, aşağıdaki satır içi sarmalayıcı işlevlerini kullanmanız gerekir.

Havuz ayırma işlevlerini çağırmadan önce, sürücü başlatma sırasında #define POOL_ZERO_DOWN_LEVEL_SUPPORT tanımını da yapmalı ve ExInitializeDriverRuntime işlevini çağırmalısınız.

Yerel olarak tanımlanmış satır içi işlevler

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
    )

Bu kod sarmalayıcıları için uygulama kodu için en son wdm.h başlık dosyasına bakın. Örneğin bu, RtlZeroMemorykullanımını gösteren ExAllocatePoolPriorityZero uygulamasıdır.

{
    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;
}

Eski API'leri yeni API'lere eşleme

Eski API Yeni API
ExAllocatePool ExAllocatePoolZero
ExAllocatePoolWithTag ExAllocatePoolZero
ExAllocatePoolWithQuota ExAllocatePoolQuotaZero
ExAllocatePoolWithQuotaTag ExAllocatePoolQuotaZero
ExAllocatePoolWithTagPriority ExAllocatePoolPriorityZero

Örnek

// 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');

Sürücü doğrulayıcı UnSafeAllocatePool kuralları

Sürücü doğrulayıcı UnSafeAllocatePool kuralı, bir sürücünün bellek ayırmak için kullanım dışı DDI kullanmadığını denetleyen önemli bir güvenlik kuralıdır. Bu kural, önizleme WDK derlemeleri 20236 ve üzeri sürümlerde kullanılabilir.

Ayrıca Bkz.

ExAllocatePool2

ExAllocatePool3

ExAllocatePool

ExAllocatePoolWithTag

ExAllocatePoolWithQuota

ExAllocatePoolWithQuotaTag

exAllocatePoolWithTagPriority