阅读:1523回复:9
求救:WDM中,怎么才能获得物理地址?
win2000中WDM驱动,现在我要在内存中分配一段内存,设备需要得到其物理地址?怎么操作啊?
又不能用MmGetPhysicalAddress |
|
|
沙发#
发布于:2004-07-19 11:08
win2000中WDM驱动,现在我要在内存中分配一段内存,设备需要得到其物理地址?怎么操作啊? 为什么不能使用MmGetPhysicalAddress? |
|
|
板凳#
发布于:2004-07-19 12:59
自己搜索页表.
|
|
|
地板#
发布于:2004-07-19 13:51
wowocock兄,怎么操作,以前的帖子找了半天也没找着~~~
AllenZh,WDM中可以用MmGetPhysicalAddress的啊,说没有定义嘛,怎么导出来啊~~ 大哥门,帮帮我啊~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
|
地下室#
发布于:2004-07-19 15:55
MmGetPhysicalAddress 只在 NTDDK.h 中有声明,但在WDM驱动中也是可以用的,你可以从 NTDDK.h 中将它的声明拷贝过来。
|
|
|
5楼#
发布于:2004-07-19 16:37
seaquester,我试试看啊~~
|
|
|
6楼#
发布于:2004-07-19 17:09
seaquester,我不会这样用啊~~~~
------------------- link error: unresolved external symbol __imp__MmGetPhysicalAddress 还有其他方法吗?? |
|
|
7楼#
发布于:2004-07-19 19:02
BIT0 EQU 0001H
BIT16 EQU 00010000H ;---------------------------------------------------------------------------- ;Description :Convert Linear Address to Phyical Address ;Input param :Entry ==> Virtual Address ;Output :EDX:EAX=: Physical Address ;Notice :The subroutine required Ring0 . MmGetPhysicalAddress proc VirtualAddress:dword mov ecx,[VirtualAddress] mov eax,ecx shr eax,20 and eax,0FFCH push esi lea esi,[eax+0C0300000H] mov edx,[esi] test dl,BIT0 ;P Flag jz .NotPresent test dl,BIT7 ;PS Flag jnz .Page4M mov eax,ecx and eax,NOT 0FFFH shr eax,10 add eax,0C0000000H mov eax,[eax] test al,BIT0 ;P Flag jz .NotPresent and eax,NOT 0FFFH and ecx,0FFFH add eax,ecx xor edx,edx pop esi jmp .L2PQuit Page4M: mov eax,ecx and eax,NOT 0FFC00000H ;Clear 31-22 Bits and edx,NOT 01FFFH ;0-12 Bits add eax,edx push eax ;Save 0-31 Bits mov eax,1 cpuid test edx,BIT17 ;PSE feature Flag jnz @f pop eax xor edx,edx pop esi jmp .L2PQuit @@: pop eax mov edx,[esi] shr edx,12 and edx,0FH ;Get 32-35 Bits pop esi jmp .L2PQuit NotPresent: pop esi xor eax,eax xor edx,edx L2PQuit: ret MmGetPhysicalAddress endp ULONG LinearAddressToPhysicalAddress(ULONG lAddress) { unsigned int *pAddr; unsigned int *PageDirectoryEntry=(unsigned int *)0xC0300000; unsigned int *PageTableEntry=(unsigned int *)0xC0000000; if((!(PageDirectoryEntry[lAddress>>22]&0xFFFFF000)) &&(!(PageDirectoryEntry[lAddress>>22]&0x00000001))) return 0; pAddr=(int *)((int)PageTableEntry+((lAddress&0xFFFFF000)>>10)); if((*pAddr)&1) return ((*pAddr) &0xFFFFF000) |(lAddress&0x00000FFF); return 0; } |
|
|
8楼#
发布于:2004-07-19 19:52
seaquester,包含ntoskrnl.lib库就可以了~~~~
wowocock,你的东东很好,收下先。不过PS什么的蛮烦的。有时间再看了~~,再次谢谢各位拉~~~~~~~~~~~~~ |
|
|
9楼#
发布于:2004-07-20 10:47
后来使用了 MmAllocateContiguousMemory
MmGetPhysicalAddress 搞定了~~~~~~~~~ |
|
|