mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 23:07:18 +00:00
[c-host] added windows ivshmem unmap support
This commit is contained in:
parent
810fb73362
commit
a8622be1c6
@ -65,5 +65,7 @@ int app_main()
|
|||||||
|
|
||||||
iface->deinit();
|
iface->deinit();
|
||||||
iface->free();
|
iface->free();
|
||||||
|
|
||||||
|
os_shmemUnmap();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -26,6 +26,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
#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;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user