virtio-win / kvm-guest-drivers-windows

Windows paravirtualized drivers for QEMU\KVM
https://www.linux-kvm.org/page/WindowsGuestDrivers
BSD 3-Clause "New" or "Revised" License
1.92k stars 377 forks source link

IVSHMEM: Allow multiple processes to map the same shared memory #1040

Closed polloloco closed 4 months ago

polloloco commented 4 months ago

Previously there was a shmemMap member inside the DEVICE_CONTEXT which effectively restricted the mapping to a single process only. I've moved that pointer (that holds the virtual address of the mapping in the usermode process) to a new FILE_CONTEXT struct. For each CreateFile call in usermode, a WDFFILEOBJECT is created in the kernel. The WDFDEVICE EvtDeviceFileCreate callback then allocates the file context in the file object.

When a usermode application requests a map via ioctl, we extract the file object (and then file context) from the WDFREQUEST. Instead of updating the shmemMap member in the device context (this was before this pull request), now we update that address in the file context, which is unique to each handle to the driver.

With these changes, one or more applications can map the same memory into their virtual address space. One application could even map the region twice, but only from two driver handles (two calls to CreateFile).

YanVugenfirer commented 4 months ago

There are line-ending issues in the device.c. It will be great if you fix them too. Thanks.

YanVugenfirer commented 4 months ago

@polloloco Are you planning to fix the comments?

Thanks, Yan.