Advertisement

KMDF中未分页内存的类型设置

阅读量:

在内核驱动程序开发过程中,内存空间的动态分配无法采用C语言中常见的malloc等函数,取而代之的是ExAllocatePoolWithTag()和ExFreePool()这两个专用函数。具体的使用方式如下所示:

#define TEST_POOL_TAG (ULONG)'test'

PUCHAR tempBuf = NULL;

tempBuf = ExAllocatePoolWithTag(NonPagedPool, tempBufSize, TEST_POOL_TAG);

ExFreePool((PVOID)tempBuf); // 释放内存

然而,在进行HLK测试时,上述代码会导致系统出现蓝屏现象,错误信息如下:

DRIVER_VERIFIER_DETECTED_VIOLATION(c4)

A device driver attempting to corrupt the system has been caught. This is

because the driver was specified in the registry as being suspect (by the

administrator) and the kernel has enabled substantial checking of this driver.

_If

全部评论 (0)

还没有任何评论哟~