Hi,
Just for completness and future refernce, this is how what I did:
************************
In my UM app - call search for a free region big enough to accomedate the
entire virtual memory block that I require:
p = 0x100000; any old address
VirtualQueryEx(GetCurrentProcess(), (VOID*)p, &Buffer, sizeof(Buffer));
while (Buffer.State != MEM_FREE || Buffer.RegionSize < (blocksize * 4))
{
p += Buffer.RegionSize;
VirtualQueryEx(GetCurrentProcess(), (VOID*)p, &Buffer, sizeof(Buffer));
}
//Here we call the IOCTL to request the driver to map pages…
**************************
In my driver:
//UserVa is the free address that the UM code found.
//m_blockSize should be page aligned
for (ULONG i = 0; i < numBlocks; i++)
{
m_memoryChunksArr[i].SystemAddress =
MmAllocateContiguousMemorySpecifyCache(m_blockSize, lowAddress,
highAddress, lowAddress, MmCached);
m_memoryChunksArr[i].pMdl =
IoAllocateMdl(m_memoryChunksArr[i].SystemAddress, m_blockSize, FALSE,
FALSE, NULL);
MmBuildMdlForNonPagedPool(m_memoryChunksArr[i].pMdl);
__try {
MmMapLockedPagesSpecifyCache(m_memoryChunksArr[i].pMdl, UserMode, MmCached,
(PUCHAR)UserVa + m_blockSize * i, FALSE,NormalPagePriority);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
DbgPrint(“MmMapLockedPagesSpecifyCache failed\n”);
Status = STATUS_INSUFFICIENT_RESOURCES;
break;
}
}
On Thu, Mar 2, 2017 at 11:34 PM, Menachem Shapira
wrote:
> Thanks all,
>
> I’m going to try to go with Don’s solution. I’ve managed to get it working
> on some POC level, now i’m just left to work out what to arguments to pass
> to VirtualQueryEx in order to ensure that I get addresses I can use.
> Tim, you solution would work if I didn’t already have a whole lot of
> applications alleady using an interface thats uses void* and treat the
> memory as contiguous.
>
> Thanks again,
>
> On Thu, Mar 2, 2017 at 12:12 AM, Tim Roberts wrote:
>
>> Menachem Shapira wrote:
>> >
>> > In my PCIe driver, I would like to map multiple non contiguous
>> > (virtualy and physicaly) memory pages to a user application, in such a
>> > way that the user sees the entire memory as virtualy contiguous.
>>
>> Although it seems “pretty” to make these regions virtually contiguous,
>> it is a waste of your time to investigate hackery to make that happen.
>> It is trivially easy to create a data structure that hides the
>> discontinuities. The STL std::deque container appears to the user as a
>> single sequential block, but is actually implemented as a set of
>> discontinuous subblocks.
>>
>> –
>> Tim Roberts, xxxxx@probo.com
>> Providenza & Boekelheide, Inc.
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list online at: http:>> lists.cfm?list=ntdev>
>>
>> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
>> software drivers!
>> Details at http:
>>
>> To unsubscribe, visit the List Server section of OSR Online at <
>> http://www.osronline.com/page.cfm?name=ListServer>
>>
>
></http:></http:>