阅读:1893回复:1
32位win7 驱动共享内存的问题
大家好,我在做一个PCIE DMA驱动,其中分了16M commonbuffer 作为接收数据缓冲区,我把这16M映射到用户层时 蓝屏。主要代码如下:
PULONG pMdlUserAddr = NULL; PMDL BufferMdl = NULL; BufferMdl = IoAllocateMdl(devExt->RecvCommonBufferBase, 4096*DESC_NUMBERS, FALSE, FALSE, NULL); MmBuildMdlForNonPagedPool(BufferMdl);//初始化MDL页码数组 BufferMdl->MdlFlags |= MDL_MAPPED_TO_SYSTEM_VA;// 改变MDL的flags为可读状态 __try { MmProbeAndLockPages(BufferMdl,KernelMode,IoWriteAccess);//在内存中锁定,并且指明对它的改写权力 } __except (EXCEPTION_EXECUTE_HANDLER) { KdPrint((" Exception during MmProbeAndLockPages")); IoFreeMdl (BufferMdl); return STATUS_UNSUCCESSFUL; } //maps the physical pages that are described by an MDL to a virtual address,returns the starting address of the mapped pages. pMdlUserAddr = (PULONG)MmMapLockedPagesSpecifyCache(BufferMdl, UserMode, MmNonCached, NULL, FALSE, NormalPagePriority); if (!pMdlUserAddr) { KdPrint(("MmMapLockedPagesSpecifyCache FAIL!!")); IoFreeMdl(BufferMdl); return STATUS_UNSUCCESSFUL; } devExt->BufferUserVirtualAddress = (PVOID)( ((ULONG)PAGE_ALIGN(pMdlUserAddr)) + MmGetMdlByteOffset(BufferMdl) ); 其中,执行到MmMapLockedPagesSpecifyCache时蓝屏,:KERNEL_DATA_IN_PAGE_ERROR ,但是在XP下代码就不出问题。 其实, 程序中就是依次调用了以下函数: BufferMdl = IoAllocateMdl(devExt->RecvCommonBufferBase, 4096*DESC_NUMBERS, FALSE, FALSE, NULL); MmBuildMdlForNonPagedPool(BufferMdl);//初始化MDL页码数组 MmProbeAndLockPages(BufferMdl,KernelMode,IoWriteAccess); pMdlUserAddr = (PULONG)MmMapLockedPagesSpecifyCache(BufferMdl, UserMode, MmNonCached, NULL, FALSE, NormalPagePriority); 然后MmMapLockedPagesSpecifyCache就出错了,求大神赐教,小弟不胜感激。 |
|
|
沙发#
发布于:2014-10-20 06:30
用windbg追下,然后帖下!analyze -v
|
|
|