Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
Overzicht
Voor de release van Windows 10 versie 2004 heeft Microsoft nieuwe pool-nul-API's geïntroduceerd die standaard nul zijn: ExAllocatePool2 en ExAllocatePool3.
Met de CodeQL-query wdk-deprecated-api worden alle instanties van afgeschafte API's gevonden die niet mogen worden aangeroepen door een stuurprogramma. De afgeschafte API's zijn:
Stuurprogramma-updates voor versies van Windows hoger dan Windows 10, versie 2004
Als u een stuurprogramma bouwt dat is gericht op Windows 10, versie 2004 en nieuwere versies, gebruikt u in plaats daarvan de vervangende API's ExAllocatePool2 en ExAllocatePool3 .
| Oude API | Nieuwe API |
|---|---|
| ExAllocatePool | ExAllocatePool2 |
| ExAllocatePoolWithTag | ExAllocatePool2 |
| ExAllocatePoolWithQuota | ExAllocatePool2 |
| ExAllocatePoolWithQuotaTag | ExAllocatePool2 |
| ExAllocatePoolWithTagPriority | ExAllocatePool3 |
Met de nieuwe API's worden standaard geen pooltoewijzingen toegewezen, om mogelijke fouten in het vrijgeven van geheugen te voorkomen.
ExAllocatePoolWithTag
// Old code
PVOID Allocation = ExAllocatePoolWithTag(PagedPool, 100, 'abcd');
RtlZeroMemory(Allocation, 100);
// New code
PVOID Allocation = ExAllocatePool2(POOL_FLAG_PAGED, 100, 'abcd');
De oude pooltoewijzings-API's accepteren een POOL_TYPE argument, maar de nieuwe toewijzings-API's accepteren een POOL_FLAGS argument. Werk alle bijbehorende code bij om het nieuwe POOL_FLAGS argument te gebruiken.
ExAllocatePoolWithQuota/ExAllocatePoolWithQuotaTag
De nieuwe functie retourneert nu standaard NULL bij toewijzingsfouten. Als u wilt dat de allocator in plaats daarvan een uitzondering op fouten genereert, moet de vlag POOL_FLAG_RAISE_ON_FAILURE worden doorgegeven zoals besproken 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', ¶ms, 1);
Stuurprogramma-updates voor versies van Windows ouder dan Windows 10, versie 2004
Als u een stuurprogramma bouwt dat gericht is op versies van Windows vóór Windows 10 versie 2004, moet u de volgende force inline wrapper-functies gebruiken.
U moet ook #define POOL_ZERO_DOWN_LEVEL_SUPPORT gebruiken en ExInitializeDriverRuntime aanroepen tijdens de initialisatie van het stuurprogramma voordat u de pooltoewijzingsfuncties aanroept.
Lokaal gedefinieerde inlinefuncties
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
)
Raadpleeg de nieuwste wdm.h-header voor de implementatiecode voor deze code-wrappers. Dit is bijvoorbeeld de implementatie voor ExAllocatePoolPriorityZero, met het gebruik van 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;
}
Koppeling van oude API's naar nieuwe API's
| Oude API | Nieuwe API |
|---|---|
| ExAllocatePool | ExAllocatePoolZero |
| ExAllocatePoolWithTag | ExAllocatePoolZero |
| ExAllocatePoolWithQuota | ExAllocatePoolQuotaZero |
| ExAllocatePoolWithQuotaTag | ExAllocatePoolQuotaZero |
| ExAllocatePoolWithTagPriority | ExAllocatePoolPriorityZero |
Voorbeeld
// Old code
PVOID Allocation = ExAllocatePoolWithTag(PagedPool, 100, 'abcd');
// 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');
Aanvullende details
Deze query vindt u in de Microsoft GitHub CodeQL-opslagplaats. Zie de pagina CodeQL en de pagina Logotest voor statische hulpprogramma's voor meer informatie over hoe ontwikkelaars van Windows-stuurprogramma's CodeQL kunnen downloaden en uitvoeren.