-
-
[求助]关于MmAllocatePagesForMdl的HighAddress参数
-
发表于:
2016-2-17 14:22
4541
-
[求助]关于MmAllocatePagesForMdl的HighAddress参数
这是一段共享内核和用户空间内存的代码:
NTSTATUS
CreateAndMapMemory(OUT PMDL* PMemMdl,
OUT PVOID* UserVa)
{
PMDL Mdl;
PVOID UserVAToReturn;
PHYSICAL_ADDRESS LowAddress;
PHYSICAL_ADDRESS HighAddress;
SIZE_T TotalBytes;
// 初始化MmAllocatePagesForMdl需要的Physical Address
LowAddress.QuadPart = 0;
MAX_MEM(HighAddress.QuadPart);
TotalBytes = PAGE_SIZE;
// 分配4K的共享缓冲区
Mdl = MmAllocatePagesForMdl(LowAddress,
HighAddress,
LowAddress,
TotalBytes);
if(!Mdl)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
// 映射共享缓冲区到用户地址空间
UserVAToReturn = MmMapLockedPagesSpecifyCache(Mdl,
UserMode,
MmCached,
NULL,
FALSE,
NormalPagePriority);
if(!UserVAToReturn)
{
MmFreePagesFromMdl(Mdl);
IoFreeMdl(Mdl);
return STATUS_INSUFFICIENT_RESOURCES;
}
// 返回,得到MDL和用户层的虚拟地址
*UserVa = UserVAToReturn;
*PMemMdl = Mdl;
return STATUS_SUCCESS;
}
我不知道X64的最大虚拟地址确切是多少。
也就是MAX_MEM(HighAddress.QuadPart);这个宏的定义问题。
是写为:
#if defined(AMD64) || defined(IA64)
#define MAX_MEM(a) (a=0x0000ffffffffffff)
#else
#define MAX_MEM(a) (a=0xffffffff)
#endif
还是写成:
#if defined(AMD64) || defined(IA64)
#define MAX_MEM(a) (a=0xffffffffffffffff)
#else
#define MAX_MEM(a) (a=0xffffffff)
#endif
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!