MmAllocateContiguousMemory sharing

I’m trying to share memory between applications for memory allocated in my driver.

I allocate and map the buffer using these steps(roughly):
MmAllocateContiguousMemory
MmGetPhysicalAddress
IoAllocateMdl
MmBuildMdlForNonPagedPool
PAGE_ALIGN(MmMapLockedPagesSpecifyCache(devCtx->AddOnMdl, UserMode, MmNonCached, NULL, FALSE, NormalPagePriority))) + MmGetMdlByteOffset(devCtx->AddOnMdl)));

It works great but I’d like to be able to open another handle to the driver and access the same memory if possible. I tried using the virtual address I use in the first host application but that fails. I assume the second application doesn’t see the virtual address the same way. Is there a way to share this memory across the applications? The values used to set up the driver/host shared region are all saved in the devctx so I can’t tell where the sharing ends in a new application. I don’t see what I could use to connect my new application to this same memory.

You should be able to lock the pages again for the new process.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

xxxxx@yahoo.com” wrote in
message news:xxxxx@ntdev:

> I’m trying to share memory between applications for memory allocated in my driver.
>
> I allocate and map the buffer using these steps(roughly):
> MmAllocateContiguousMemory
> MmGetPhysicalAddress
> IoAllocateMdl
> MmBuildMdlForNonPagedPool
> PAGE_ALIGN(MmMapLockedPagesSpecifyCache(devCtx->AddOnMdl, UserMode, MmNonCached, NULL, FALSE, NormalPagePriority))) + MmGetMdlByteOffset(devCtx->AddOnMdl)));
>
> It works great but I’d like to be able to open another handle to the driver and access the same memory if possible. I tried using the virtual address I use in the first host application but that fails. I assume the second application doesn’t see the virtual address the same way. Is there a way to share this memory across the applications? The values used to set up the driver/host shared region are all saved in the devctx so I can’t tell where the sharing ends in a new application. I don’t see what I could use to connect my new application to this same memory.

Thanks. That worked just as I needed.

These pages are already locked, so all you need to do is call MmMapLockedPagesSpecifyCache again.

You also shouldn’t need MmGetPhysicalAddress in the list of steps below.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: Wednesday, March 21, 2012 4:03 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] MmAllocateContiguousMemory sharing

You should be able to lock the pages again for the new process.

xxxxx@yahoo.com” wrote in message news:xxxxx@ntdev:

> I’m trying to share memory between applications for memory allocated in my driver.
>
> I allocate and map the buffer using these steps(roughly):
> MmAllocateContiguousMemory
> MmGetPhysicalAddress
> IoAllocateMdl
> MmBuildMdlForNonPagedPool
> PAGE_ALIGN(MmMapLockedPagesSpecifyCache(devCtx->AddOnMdl, UserMode,
> MmNonCached, NULL, FALSE, NormalPagePriority))) +
> MmGetMdlByteOffset(devCtx->AddOnMdl)));
>
> It works great but I’d like to be able to open another handle to the driver and access the same memory if possible. I tried using the virtual address I use in the first host application but that fails. I assume the second application doesn’t see the virtual address the same way. Is there a way to share this memory across the applications? The values used to set up the driver/host shared region are all saved in the devctx so I can’t tell where the sharing ends in a new application. I don’t see what I could use to connect my new application to this same memory.

> MmAllocateContiguousMemory

Why do you need this? Just call ExAllocatePoolWithTag

MmGetPhysicalAddress

Why do you need this?

assume the second application doesn’t see the virtual address the same way.

You must MmMapXxx for second app too.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

The Physical address is for the pci board to find the shared memory when crossing the bus.

> The Physical address is for the pci board to find the shared memory when crossing the bus.

Then DMA APIs must be used and not MmGetPhysicalAddress


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

It appears to work correctly. Do I still use the DMA APUs for non-DMA operations?

> It appears to work correctly. Do I still use the DMA APUs for non-DMA operations?

Are you passing the physical addresses to hardware?


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com