阅读:1322回复:3
小弟刚开始学WINCE,调试时有个问题求助
两种方法实现,物理内存分配:
1 pOpen->pDriverInfo->pVIMRegs[VIN_MB1 ] = (unsigned long)AllocPhysMem(0x80000, PAGE_READWRITE, 0, 0, (PULONG)0x09000000); 2 pOpen->pDriverInfo->pVIMRegs[VIN_MB1 ] = (unsigned long)VirtualAlloc(NULL, 0x80000, MEM_RESERVE, PAGE_READWRITE); VirtualCopy( (PVOID)(pOpen->pDriverInfo->pVIMRegs[VIN_MB1 ]), (PVOID)(0x09000000),0x80000, PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL); 如果使用"AllocPhysMem" 参数设为 PAGE_NOACCESS , WINCE加载dll时没有问题, 但是此参数应设为 READWRITE! 如果参数设为 PAGE_READWRITE, 当WINCE 加载dll时 程序会自动停在 virtmen.C //NK/KERNEL LPVOID SC_AllocPhysMem( DWORD cbSize, DWORD fdwProtect, // type of access protection DWORD dwAlignmentMask, DWORD dwFlags, // Reserved for now, must be zero PULONG pPhysicalAddress ) { LPVOID pVirtualBuffer = NULL; ULONG ulPFN; DWORD dwPages = (cbSize + (PAGE_SIZE - 1)) / PAGE_SIZE; TRUSTED_API (L"SC_AllocPhysMem", NULL); if (!cbSize || !pPhysicalAddress || dwFlags) { KSetLastError(pCurThread, ERROR_INVALID_PARAMETER); return NULL; } if ((ulPFN = GetContiguousPages(dwPages, dwAlignmentMask, dwFlags)) == INVALID_PHYSICAL_ADDRESS) { KSetLastError(pCurThread, ERROR_NOT_ENOUGH_MEMORY); DEBUGMSG(ZONE_VIRTMEM, (TEXT("Couldn't get %d pages contiguous\r\n"), dwPages)); } else { DEBUGMSG(ZONE_VIRTMEM, (TEXT("Got %d pages contiguous @ 0x%08X\r\n"), dwPages, ulPFN)); // // Allocate the virtual memory with contiguous physical pages // pVirtualBuffer = DoVirtualAlloc(0, cbSize, MEM_COMMIT, fdwProtect|PAGE_NOCACHE, MEM_CONTIGUOUS, ulPFN); if (pVirtualBuffer) { *pPhysicalAddress = PFN2PA(ulPFN); // <------- 此处 } } DEBUGMSG(ZONE_VIRTMEM, (TEXT("CeAllocPhysMem - VA: %08X PA:%08X \r\n"), pVirtualBuffer, *pPhysicalAddress)); return pVirtualBuffer; } 在PB的 debug信息中 : 20497 PID:cdf76b72 TID:cdf7bfda 0x8dfa6000: Exception 060 Thread=8dfa6000 Proc=cdf76b72 'device.exe' 20497 PID:cdf76b72 TID:cdf7bfda 0x8dfa6000: AKY=0000000b PC=8822ba48(NK.EXE+0x0002ba48) RA=8822ba34(NK.EXE+0x0002ba34) TEA=09000000 不知为何? 向前辈请教 对应的两种 free的写法,不知对否? FreePhysMem((PULONG)0x09000000); VirtualFree((PVOID)(pOpen->pDriverInfo->pVIMRegs[VIN_MB1 ]),0, MEM_RELEASE); |
|
沙发#
发布于:2007-08-30 22:17
兄弟你细心一点,
pOpen->pDriverInfo->pVIMRegs[VIN_MB1 ] = (unsigned long)AllocPhysMem(0x80000, PAGE_READWRITE, 0, 0, (PULONG)0x09000000); 这一句的最后一个参数是有问题的,你把一个数转化成PULONG,查查文档里面怎么讲的吧. |
|
|
板凳#
发布于:2007-08-31 20:57
谢谢版主,我去查一下
|
|
地板#
发布于:2007-11-25 23:27
学习~~
|
|
|