mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-12-23 22:31:46 +00:00
[c-host] added windows ivshmem unmap support
This commit is contained in:
parent
810fb73362
commit
a8622be1c6
2 changed files with 22 additions and 4 deletions
|
@ -65,5 +65,7 @@ int app_main()
|
|||
|
||||
iface->deinit();
|
||||
iface->free();
|
||||
|
||||
os_shmemUnmap();
|
||||
return 0;
|
||||
}
|
|
@ -25,7 +25,9 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
#include "windebug.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)
|
||||
{
|
||||
|
@ -81,6 +83,7 @@ int WINAPI WinMain(HINSTANCE hInstnace, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||
|
||||
int result = app_main();
|
||||
|
||||
os_shmemUnmap();
|
||||
CloseHandle(shmemHandle);
|
||||
return result;
|
||||
}
|
||||
|
@ -99,23 +102,36 @@ unsigned int os_shmemSize()
|
|||
|
||||
bool os_shmemMmap(void **ptr)
|
||||
{
|
||||
IVSHMEM_MMAP map = {0};
|
||||
if (shmemOwned)
|
||||
{
|
||||
*ptr = shmemMap.ptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
memset(&shmemMap, 0, sizeof(IVSHMEM_MMAP));
|
||||
if (!DeviceIoControl(
|
||||
shmemHandle,
|
||||
IOCTL_IVSHMEM_REQUEST_MMAP,
|
||||
NULL, 0,
|
||||
&map, sizeof(IVSHMEM_MMAP),
|
||||
&shmemMap, sizeof(IVSHMEM_MMAP),
|
||||
NULL, NULL))
|
||||
{
|
||||
DEBUG_WINERROR("DeviceIoControl Failed", GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
*ptr = map.ptr;
|
||||
*ptr = shmemMap.ptr;
|
||||
shmemOwned = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
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 a new issue