Skip to content

Commit

Permalink
ivshmem: add API for kernel space mapping
Browse files Browse the repository at this point in the history
Let also kernel mode clients to use shared memory.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
  • Loading branch information
ybendito authored and YanVugenfirer committed May 5, 2020
1 parent e6d9d7a commit 1716901
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions ivshmem/Public.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ IVSHMEM_EVENT, *PIVSHMEM_EVENT;
#define IOCTL_IVSHMEM_RELEASE_MMAP CTL_CODE(FILE_DEVICE_UNKNOWN, 0x803, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_IVSHMEM_RING_DOORBELL CTL_CODE(FILE_DEVICE_UNKNOWN, 0x804, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_IVSHMEM_REGISTER_EVENT CTL_CODE(FILE_DEVICE_UNKNOWN, 0x805, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_IVSHMEM_REQUEST_KMAP CTL_CODE(FILE_DEVICE_UNKNOWN, 0x806, METHOD_BUFFERED, FILE_ANY_ACCESS)
14 changes: 9 additions & 5 deletions ivshmem/Queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ static NTSTATUS ioctl_request_mmap(
const size_t InputBufferLength,
const size_t OutputBufferLength,
const WDFREQUEST Request,
size_t * BytesReturned
size_t * BytesReturned,
BOOLEAN ForKernel
);

static NTSTATUS ioctl_release_mmap(
Expand Down Expand Up @@ -108,9 +109,11 @@ IVSHMEMEvtIoDeviceControl(
break;

case IOCTL_IVSHMEM_REQUEST_MMAP:
status = ioctl_request_mmap(deviceContext, InputBufferLength, OutputBufferLength, Request, &bytesReturned);
status = ioctl_request_mmap(deviceContext, InputBufferLength, OutputBufferLength, Request, &bytesReturned, FALSE);
break;
case IOCTL_IVSHMEM_REQUEST_KMAP:
status = ioctl_request_mmap(deviceContext, InputBufferLength, OutputBufferLength, Request, &bytesReturned, TRUE);
break;

case IOCTL_IVSHMEM_RELEASE_MMAP:
status = ioctl_release_mmap(deviceContext, Request, &bytesReturned);
break;
Expand Down Expand Up @@ -235,7 +238,8 @@ static NTSTATUS ioctl_request_mmap(
const size_t InputBufferLength,
const size_t OutputBufferLength,
const WDFREQUEST Request,
size_t * BytesReturned
size_t * BytesReturned,
BOOLEAN ForKernel
)
{
// only one mapping at a time is allowed
Expand Down Expand Up @@ -291,7 +295,7 @@ static NTSTATUS ioctl_request_mmap(
{
DeviceContext->shmemMap = MmMapLockedPagesSpecifyCache(
DeviceContext->shmemMDL,
UserMode,
ForKernel ? KernelMode : UserMode,
cacheType,
NULL,
FALSE,
Expand Down

0 comments on commit 1716901

Please sign in to comment.