[c-host] added windows ivshmem unmap support

This commit is contained in:
Geoffrey McRae 2019-02-28 19:27:17 +11:00
parent 810fb73362
commit a8622be1c6
2 changed files with 22 additions and 4 deletions

View file

@ -65,5 +65,7 @@ int app_main()
iface->deinit(); iface->deinit();
iface->free(); iface->free();
os_shmemUnmap();
return 0; return 0;
} }

View file

@ -25,7 +25,9 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include "windebug.h" #include "windebug.h"
#include "ivshmem/Public.h" #include "ivshmem/Public.h"
static HANDLE shmemHandle = INVALID_HANDLE_VALUE; static HANDLE shmemHandle = INVALID_HANDLE_VALUE;
static bool shmemOwned = false;
static IVSHMEM_MMAP shmemMap = {0};
int WINAPI WinMain(HINSTANCE hInstnace, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) int WINAPI WinMain(HINSTANCE hInstnace, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{ {
@ -81,6 +83,7 @@ int WINAPI WinMain(HINSTANCE hInstnace, HINSTANCE hPrevInstance, LPSTR lpCmdLine
int result = app_main(); int result = app_main();
os_shmemUnmap();
CloseHandle(shmemHandle); CloseHandle(shmemHandle);
return result; return result;
} }
@ -99,23 +102,36 @@ unsigned int os_shmemSize()
bool os_shmemMmap(void **ptr) bool os_shmemMmap(void **ptr)
{ {
IVSHMEM_MMAP map = {0}; if (shmemOwned)
{
*ptr = shmemMap.ptr;
return true;
}
memset(&shmemMap, 0, sizeof(IVSHMEM_MMAP));
if (!DeviceIoControl( if (!DeviceIoControl(
shmemHandle, shmemHandle,
IOCTL_IVSHMEM_REQUEST_MMAP, IOCTL_IVSHMEM_REQUEST_MMAP,
NULL, 0, NULL, 0,
&map, sizeof(IVSHMEM_MMAP), &shmemMap, sizeof(IVSHMEM_MMAP),
NULL, NULL)) NULL, NULL))
{ {
DEBUG_WINERROR("DeviceIoControl Failed", GetLastError()); DEBUG_WINERROR("DeviceIoControl Failed", GetLastError());
return false; return false;
} }
*ptr = map.ptr; *ptr = shmemMap.ptr;
shmemOwned = true;
return true; return true;
} }
void os_shmemUnmap() void os_shmemUnmap()
{ {
if (!shmemOwned)
return;
if (!DeviceIoControl(shmemHandle, IOCTL_IVSHMEM_RELEASE_MMAP, NULL, 0, NULL, 0, NULL, NULL))
DEBUG_WINERROR("DeviceIoControl failed", GetLastError());
else
shmemOwned = false;
} }