kvm-guest-drivers-windows icon indicating copy to clipboard operation
kvm-guest-drivers-windows copied to clipboard

IVSHMEM: Allow multiple processes to map the same shared memory

Open polloloco opened this issue 1 year ago • 1 comments

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).

polloloco avatar Feb 08 '24 18:02 polloloco

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

YanVugenfirer avatar Feb 11 '24 13:02 YanVugenfirer

@polloloco Are you planning to fix the comments?

Thanks, Yan.

YanVugenfirer avatar Feb 22 '24 08:02 YanVugenfirer