ui/virtio-gpu: add and use qemu_create_displaysurface_pixman
PATCH 1/1 ui/virtio-gpu: add and use qemu_create_displaysurface_pixman
Add a the new qemu_create_displaysurface_pixman function, to create a DisplaySurface backed by an existing pixman image. In that case there is no need to create a new pixman image pointing to the same backing storage. We can just use the existing image directly.
This does not only simplify things a bit, but most importantly it gets the reference counting right, so the backing storage for the pixman image wouldn't be released underneath us.
Use new function in virtio-gpu, where using it actually fixes use-after-free crashes.
Signed-off-by Gerd Hoffmann <[email protected]>
--- hw/display/virtio-gpu.c | 5 +---- include/ui/console.h | 1 + trace-events | 1 + ui/console.c | 11 +++++++++++ 4 files changed, 14 insertions(+), 4 deletions(-)
hw/display/virtio-gpu.c +1 -4
@@ -572,10 +572,7 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, scanout->width != ss.r.width || scanout->height != ss.r.height) {/* realloc the surface ptr */ - scanout->ds =qemu_create_displaysurface_from - (ss.r.width, ss.r.height, format, -pixman_image_get_stride (res->image), - (uint8_t *)pixman_image_get_data (res->image) + offset); + scanout->ds =qemu_create_displaysurface_pixman (res->image);if (!scanout->ds) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;return ;
include/ui/console.h +1 -0
@@ -234,6 +234,7 @@ DisplayState *init_displaystate(void);DisplaySurface *qemu_create_displaysurface_from (int width,int height,pixman_format_code_t format,int linesize,uint8_t *data); +DisplaySurface *qemu_create_displaysurface_pixman (pixman_image_t *image); DisplaySurface *qemu_create_displaysurface_guestmem(int width, int height, pixman_format_code_t format, int linesize,
trace-events +1 -0
@@ -1161,6 +1161,7 @@ console_select(int nr) "%d" console_refresh(int interval) "interval %d ms" displaysurface_create(void *display_surface, int w, int h) "surface=%p, %dx%d" displaysurface_create_from(void *display_surface, int w, int h, uint32_t format) "surface=%p, %dx%d, format 0x%x" +displaysurface_create_pixman(void *display_surface) "surface=%p" displaysurface_free(void *display_surface) "surface=%p" displaychangelistener_register(void *dcl, const char *name) "%p [ %s ]" displaychangelistener_unregister(void *dcl, const char *name) "%p [ %s ]"
ui/console.c +11 -0
@@ -1292,6 +1292,17 @@ DisplaySurface *qemu_create_displaysurface_from(int width, int height,return surface; } +DisplaySurface *qemu_create_displaysurface_pixman (pixman_image_t *image) +{ +DisplaySurface *surface =g_new0 (DisplaySurface,1 ); + +trace_displaysurface_create_pixman (surface); + surface->format =pixman_image_get_format (image); + surface->image =pixman_image_ref (image); + +return surface; +} +static void qemu_unmap_displaysurface_guestmem (pixman_image_t *image,void *unused) {
Signature · 1 line
1.8.3.1