当前位置: 代码迷 >> 综合 >> pcie 驱动卸载 蓝屏
  详细解决方案

pcie 驱动卸载 蓝屏

热度:50   发布时间:2024-01-10 05:49:56.0

pcie 驱动程序卸载时偶尔出现蓝屏现象, 根据打印信息初步定位是释放资源时出错。使用Windbg单步调试时,蓝屏的概率要高很多。  代码如下:

VOID PciReturnResources(PPCI_DEVICE_EXT pDevExt)
{int    i;{// Release IO/Memory Resourcefor(i=0; i<PCI_TYPE0_ADDRESSES ; i++ ){if (pDevExt->base[i].WhichMapped == TYPE_MEM){MmUnmapIoSpace(pDevExt->base[i].MemoryMappedAddress, pDevExt->base[i].MemorySize);}if(pDevExt->base[i].WhichMapped == TYPE_IO){pDevExt->base[i].IoPortMappedAddress    = (PVOID)0;}pDevExt->base[i].WhichMapped = TYPE_NONE;}}{// Release Interrupt Resourceif(pDevExt->InterruptObject != NULL){IoDisconnectInterrupt(pDevExt->InterruptObject);pDevExt->InterruptObject = NULL;}}{// Release Adapter Resourceif(pDevExt->DmaAdapter != NULL){(*pDevExt->DmaAdapter->DmaOperations->PutDmaAdapter)(pDevExt->DmaAdapter);}}}


仔细分析代码后结论如下:

问题原因: IO/Memory 资源释放之后,中断资源释放之前的时间段中,其他设备中断产生(共享中断)导致进入该驱动的中断处理程序,驱动处理程序中的寄存器操作导致蓝屏发生(此时IO/Memory 资源已经释放)。

解决方法: IO/Memory 资源和 中断资源释放的位置调换(先释放中断资源后释放 IO/Memory 资源)。