2

I need to share memory between userspace and kernelspace. The memory is allocated in userspace and in the kernel I want to build a memory descriptor list with physical addresses to initialize a DMA controller (that resides in FPGA).

I'm using a Zynq (ARM+FPGA) with WEC2013 on it.

Microsoft gives 2 methods, the "IOCTL method" and the "Shared Memory Object" method but I can't use either of them:

  • IOCTL: because the method parameter is ignored by Windows Embedded Compact so I can't use METHOD_xxx_DIRECT. MSDN on IOCTL
  • Shared Memory Object: memory is already allocated by the user and therefore I can't create a named memory object (with CreateFileMapping). Copying the data would take too much time.

Is there another way to do this? Or can I get the MDL in userspace?

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • You should be able to use an IOCTL in much the same way as if you were using METHOD_NEITHER. Just have the userspace code pass a pointer to the buffer rather than the buffer itself. I think you would then use IoAllocateMdl() and MmProbeAndLockPages() but I'm not very familiar with kernel memory management. [This might help](https://msdn.microsoft.com/en-us/library/windows/hardware/ff563839(v=vs.85).aspx) as it talks about doing DMA with a user buffer. – Harry Johnston Nov 12 '15 at 21:32
  • The buffer pointer is a virtual address from userspace and meaningless in kernelspace, so if there's a way to convert the pointer to a useful virtual address in kernelspace, than your method would be OK. I would expect that it's possible, but didn't find how to do it yet. – Jurgen Vandermot Nov 13 '15 at 08:58
  • The `IRP_MJ_DEVICE_CONTROL` generated by a call to DeviceIoControl always goes to the topmost driver, so you know that `DispatchDeviceControl` is running in the context of the calling process. So IoAllocateMdl() and MmProbeAndLockPages() should convert the virtual address into an MDL that describes the physical pages, suitable for use with MapTransfer(). – Harry Johnston Nov 13 '15 at 20:36
  • Note that when an IOCTL uses `METHOD_NEITHER` the device driver receives nothing but the usermode virtual addresses for the buffers. Windows does no pre-processing of any sort on those addresses. So if you can find some open source or sample code using `METHOD_NEITHER`, whatever it does to access the buffer will also work in your scenario. (Well, unless it uses functions that Windows Embedded Compact doesn't provide, I suppose.) – Harry Johnston Nov 13 '15 at 20:40

0 Answers0