Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Überblick
Für die Version Windows 10, Version 2004, hat Microsoft neue Pool-Null-APIs eingeführt, die standardmäßig null sind: ExAllocatePool2 und ExAllocatePool3.
Die "wdk-deprecated-apiCodeQL"-Abfrage findet alle Instanzen veralteter APIs, die ein Treiber nicht aufrufen sollte. Die veralteten APIs sind:
Treiberupdates für Versionen von Windows höher als Windows 10, Version 2004
Wenn Sie einen Treiber für Windows 10, Version 2004 und höhere Versionen erstellen, verwenden Sie stattdessen die Ersatz-APIs ExAllocatePool2 und ExAllocatePool3 .
| Alte API | Neue API |
|---|---|
| ExAllocatePool | ExAllocatePool2 |
| ExAllocatePoolWithTag | ExAllocatePool2 |
| ExAllocatePoolWithQuota | ExAllocatePool2 |
| ExAllocatePoolWithQuotaTag | ExAllocatePool2 |
| ExAllocatePoolWithTagPriority | ExAllocatePool3 |
Die neuen APIs stellen standardmäßig keine Poolzuordnungen bereit, um mögliche Speicherveröffentlichungsfehler zu vermeiden.
ExAllocatePoolWithTag
// Old code
PVOID Allocation = ExAllocatePoolWithTag(PagedPool, 100, 'abcd');
RtlZeroMemory(Allocation, 100);
// New code
PVOID Allocation = ExAllocatePool2(POOL_FLAG_PAGED, 100, 'abcd');
Die alten Poolzuordnungs-APIs akzeptieren ein POOL_TYPE Argument, aber die neuen Zuordnungs-APIs akzeptieren ein POOL_FLAGS Argument. Aktualisieren Sie jeden zugehörigen Code, um das neue POOL_FLAGS-Argument zu verwenden.
ExAllocatePoolWithQuota/ExAllocatePoolWithQuotaTag
Die neue Funktion gibt standardmäßig NULL bei Zuordnungsfehlern zurück. Damit der Allocator eine Ausnahme beim Fehlschlagen stattdessen auslöst, muss das POOL_FLAG_RAISE_ON_FAILURE-Flag übergeben werden, wie in ExAllocatePool2 beschrieben.
// 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);
Treiberupdates für Versionen von Windows vor Windows 10, Version 2004
Wenn Sie einen Treiber erstellen, der auf Versionen von Windows ausgerichtet ist, die vor Windows 10, Version 2004, liegen, müssen Sie die folgenden zwingend eingebetteten Inline-Wrap-Funktionen verwenden.
Sie müssen auch `#define POOL_ZERO_DOWN_LEVEL_SUPPORT` definieren und `ExInitializeDriverRuntime` während der Treiberinitialisierung aufrufen, bevor Sie die Poolzuweisungsfunktionen aufrufen.
Lokal definierte Inlinefunktionen
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
)
Bitte konsultieren Sie den neuesten wdm.h-Header, um den Implementierungscode für diese Codewrapper zu finden. Dies ist beispielsweise die Implementierung für ExAllocatePoolPriorityZero, die die Verwendung von RtlZeroMemory zeigt.
{
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;
}
Zuordnung alter APIs zu neuen APIs
| Alte API | Neue API |
|---|---|
| ExAllocatePool | ExAllocatePoolZero |
| ExAllocatePoolWithTag | ExAllocatePoolZero |
| ExAllocatePoolWithQuota | ExAllocatePoolQuotaZero |
| ExAllocatePoolWithQuotaTag | ExAllocatePoolQuotaZero |
| ExAllocatePoolWithTagPriority | ExAllocatePoolPriorityZero |
Beispiel
// 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');
Zusätzliche Details
Diese Abfrage finden Sie im Microsoft GitHub CodeQL-Repository. Details dazu, wie Windows-Treiberentwickler CodeQL herunterladen und ausführen können, finden Sie auf der Seite " CodeQL" und auf der Seite "Logotest für statische Tools ".