最近在写过滤驱动,要用链表,拿了DDK的 LIST_ENTRY 双向链表用了用觉得挺爽的,但调试过程中却不断蓝屏,问题出在什么地方?望大牛帮忙看看,谢谢了!
typedef struct _MY_DIRECTORY
{
LIST_ENTRY ListEntry;
int TestData;
} MY_DIRECTORY, *PMY_DIRECTORY;
LIST_ENTRY LinkListHead; //声明为全局变量
// 将对象插入链表
//
VOID MyObjectToSet ( IN PVOID pObject )
{
PMY_DIRECTORY pMyDirectory = ( PMY_DIRECTORY ) ExAllocatePool ( PagedPool, sizeof ( MY_DIRECTORY ) );
pMyDirectory ->TestData = *(int *)pObject;
#if DBG
KdPrint (("pass through value: %d\n", pMyDirectory ->TestData ));
#endif
//
// 插入链表
//
InsertHeadList ( &LinkListHead, &pMyDirectory ->ListEntry );
ExFreePool ( pMyDirectory );
}
// 将对象从链表中删除
//
VOID MyObjectToRemove ( OUT PVOID pObject )
{
#if DBG
KdPrint (("IsListEmpty Value: %d\n",IsListEmpty ( &LinkListHead )));
#endif
if ( !IsListEmpty ( &LinkListHead ) )
{
PLIST_ENTRY pEntry = RemoveHeadList ( &LinkListHead );
PMY_DIRECTORY pMyDirectory = ( PMY_DIRECTORY ) ExAllocatePool ( PagedPool, sizeof ( MY_DIRECTORY ) );
pMyDirectory = CONTAINING_RECORD ( pEntry, MY_DIRECTORY, ListEntry );
pObject = (PVOID)&pMyDirectory ->TestData;
ExFreePool ( pMyDirectory );
}
}
//
// MyTest() 是测试函数
VOID MyTest()
{
// 初始化链表头
//
InitializeListHead ( &LinkListHead );
for ( int i = 0; i<100; i++ )
{
MyObjectToSet ( (PVOID)&i );
}
while ( !IsListEmpty ( &LinkListHead ))
{
int num = 0;
MyObjectToRemove ( &num );
KdPrint (("Num: %d\n",num ));
}
}
问题:将 MyTest() 函数放在 DriverEntry() 执行后,蓝屏。调试查看调用堆栈后,提示在
RemoveHeadList ( &LinkListHead ) 此行出错,仔细检查后,似乎并没有什么问题!麻烦
大牛们帮着看看,问题出在什么地方了?先谢谢了!
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课