我正在为IO过滤器驱动程序编写内核模式测试。当我运行我的测试时,它们都通过了,但是如果我连续运行3次,测试就会开始失败。我把这个问题缩小到了ExAllocatePoolWithTag
,它在一段时间后开始返回STATUS_INSUFFICIENT_RESOURCES
。为了重现这个问题,我写了一个专门的测试。
static void __stdcall TestFoo_StressLoad()
{
int i;
for(i = 0; i < 100; i++)
{
CFIX_ASSERT(QueueInitialize() == 0); // Soon returns STATUS_INSUFFICIENT_RESOURCES
CFIX_ASSERT(QueueDestroy() == 0);
}
}
我的使用模式是:
ExAllocatePoolWithTag
)ExFreePoolWithTag
)我的问题是:如何正确使用STATUS_INSUFFICIENT_RESOURCES
**?** ExAllocatePoolWithTag ,使其不返回
以下是QueueInitialize
和QueueDestroy
的摘录
int QueueInitialize()
{
SIZE_T poolSize;
poolSize = sizeof(Event) * 1024;
Queue = (Event *)ExAllocatePoolWithTag(NonPagedPool, poolSize, '9gaT');
if( Queue == NULL )
return STATUS_INSUFFICIENT_RESOURCES;
return 0;
}
int QueueDestroy()
{
SIZE_T poolSize;
if(Queue != NULL)
{
poolSize = sizeof(Event) * 1024;
ExFreePoolWithTag((void *)Queue, '9gaT');
ProcessQueue = NULL;
return 0;
}
}
我使用cfix进行内核测试,并在Windows7 x64上运行测试。
发布于 2015-06-06 14:14:41
我建议使用查找列表,因为您的缓冲区总是相同的大小。这将大大减少内核堆碎片。
https://stackoverflow.com/questions/30321750
复制相似问题