我正在写一个Windows设备驱动程序。司机非常简单。它没什么特别的。我只是想熟悉Windows驱动程序开发。
在我的驱动程序中,我正在从NonPagedPool
分配一些内存,但是有一个非常奇怪的错误。
这是我的代码段:
pMyNode = (PMY_NODE)ExAllocatePoolWithTag(NonPagedPool, sizeof(MY_NODE), 'TEST');
if (pMyNode == NULL){
DbgPrint("Not Enough Memory\n");
}
else{
// Do Some Stuffs and free memory
}
相应的汇编代码(来自IDA Pro Disassembler)是:
call ds:__imp__ExAllocatePoolWithTag
mov [ebp+pMyNode], eax
cmp [ebp+pMyNode], 0
jnz SOME_OFFSET
call _DbgPrint
SOME_OFFSET:
.........
.........
此代码段进入PsSetCreateProcessNotifyRoutine
的处理函数。因此,每次创建新进程时,都会执行此代码段。现在,如果我长时间运行驱动程序,我会突然出现BSoD
错误。并且WinDbg
触发指令mov [ebp+pMyNode], eax
作为错误指令。该行实际上将ExAllocatePoolWithTag
的返回值指定为pMyNode
指针。我不明白这可能是一个错误的指示。
BSoD
屏幕中的错误消息为A Device Driver Has Pool
。查看下面的WinDbg
日志:
DRIVER_CORRUPTED_EXPOOL (c5)
An attempt was made to access a pageable (or completely invalid) address at an
interrupt request level (IRQL) that is too high. This is
caused by drivers that have corrupted the system pool. Run the driver
verifier against any new (or suspect) drivers, and if that doesn't turn up
the culprit, then use gflags to enable special pool.
Arguments:
Arg1: e252a000, memory referenced
Arg2: 0000000d, IRQL
Arg3: 00000001, value 0 = read operation, 1 = write operation
Arg4: 8054baee, address which referenced memory
任何帮助都是值得的。