Skip to content

Commit

Permalink
vnc-tight: fix regression with libxenstore
Browse files Browse the repository at this point in the history
commit 095497f added thread local storage for the color counting
palette. Unfortunately, a VncPalette is about 7kB on a x86_64 system.
This memory is reserved from the stack of every thread and it
exhausted the stack space of a libxenstore thread.

Fix this by allocating memory only for the VNC encoding thread.

Fixes: 095497f
Reported-by: Juergen Gross <[email protected]>
Tested-by: Juergen Gross <[email protected]>
Signed-off-by: Peter Lieven <[email protected]>
Message-id: [email protected]
Signed-off-by: Gerd Hoffmann <[email protected]>
  • Loading branch information
plieven authored and kraxel committed Jul 15, 2016
1 parent 3f7e51b commit 66668d1
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions ui/vnc-enc-tight.c
Original file line number Diff line number Diff line change
Expand Up @@ -1458,11 +1458,17 @@ static int send_sub_rect_jpeg(VncState *vs, int x, int y, int w, int h,
}
#endif

static __thread VncPalette color_count_palette;
static __thread VncPalette *color_count_palette;
static __thread Notifier vnc_tight_cleanup_notifier;

static void vnc_tight_cleanup(Notifier *n, void *value)
{
g_free(color_count_palette);
color_count_palette = NULL;
}

static int send_sub_rect(VncState *vs, int x, int y, int w, int h)
{
VncPalette *palette = &color_count_palette;
uint32_t bg = 0, fg = 0;
int colors;
int ret = 0;
Expand All @@ -1471,6 +1477,12 @@ static int send_sub_rect(VncState *vs, int x, int y, int w, int h)
bool allow_jpeg = true;
#endif

if (!color_count_palette) {
color_count_palette = g_malloc(sizeof(VncPalette));
vnc_tight_cleanup_notifier.notify = vnc_tight_cleanup;
qemu_thread_atexit_add(&vnc_tight_cleanup_notifier);
}

vnc_framebuffer_update(vs, x, y, w, h, vs->tight.type);

vnc_tight_start(vs);
Expand All @@ -1491,17 +1503,19 @@ static int send_sub_rect(VncState *vs, int x, int y, int w, int h)
}
#endif

colors = tight_fill_palette(vs, x, y, w * h, &bg, &fg, palette);
colors = tight_fill_palette(vs, x, y, w * h, &bg, &fg, color_count_palette);

#ifdef CONFIG_VNC_JPEG
if (allow_jpeg && vs->tight.quality != (uint8_t)-1) {
ret = send_sub_rect_jpeg(vs, x, y, w, h, bg, fg, colors, palette,
force_jpeg);
ret = send_sub_rect_jpeg(vs, x, y, w, h, bg, fg, colors,
color_count_palette, force_jpeg);
} else {
ret = send_sub_rect_nojpeg(vs, x, y, w, h, bg, fg, colors, palette);
ret = send_sub_rect_nojpeg(vs, x, y, w, h, bg, fg, colors,
color_count_palette);
}
#else
ret = send_sub_rect_nojpeg(vs, x, y, w, h, bg, fg, colors, palette);
ret = send_sub_rect_nojpeg(vs, x, y, w, h, bg, fg, colors,
color_count_palette);
#endif

return ret;
Expand Down

0 comments on commit 66668d1

Please sign in to comment.