mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 07:13:54 -06:00
console/win32: allocate shareable display surface
Introduce qemu_win32_map_alloc() and qemu_win32_map_free() to allocate shared memory mapping. The handle can be used to share the mapping with another process. Teach qemu_create_displaysurface() to allocate shared memory. Following patches will introduce other places for shared memory allocation. Other patches for -display dbus will share the memory when possible with the client, to avoid expensive memory copy between the processes. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20230606115658.677673-10-marcandre.lureau@redhat.com>
This commit is contained in:
parent
439e0164cd
commit
09b4c198b8
7 changed files with 102 additions and 8 deletions
|
@ -835,3 +835,36 @@ int qemu_msync(void *addr, size_t length, int fd)
|
|||
*/
|
||||
return qemu_fdatasync(fd);
|
||||
}
|
||||
|
||||
void *qemu_win32_map_alloc(size_t size, HANDLE *h, Error **errp)
|
||||
{
|
||||
void *bits;
|
||||
|
||||
trace_win32_map_alloc(size);
|
||||
|
||||
*h = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0,
|
||||
size, NULL);
|
||||
if (*h == NULL) {
|
||||
error_setg_win32(errp, GetLastError(), "Failed to CreateFileMapping");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bits = MapViewOfFile(*h, FILE_MAP_ALL_ACCESS, 0, 0, size);
|
||||
if (bits == NULL) {
|
||||
error_setg_win32(errp, GetLastError(), "Failed to MapViewOfFile");
|
||||
CloseHandle(*h);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return bits;
|
||||
}
|
||||
|
||||
void qemu_win32_map_free(void *ptr, HANDLE h, Error **errp)
|
||||
{
|
||||
trace_win32_map_free(ptr, h);
|
||||
|
||||
if (UnmapViewOfFile(ptr) == 0) {
|
||||
error_setg_win32(errp, GetLastError(), "Failed to UnmapViewOfFile");
|
||||
}
|
||||
CloseHandle(h);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue