Commit 942bd130 authored by Frediano Ziglio's avatar Frediano Ziglio Committed by Frediano Ziglio
Browse files

Allows to use Valgrind with ucontext coroutines



Changing stack is not usually instrumentation friendly.
Allows to enable the usage of Valgrind memcheck calling some
valgrind macros.
Signed-off-by: Frediano Ziglio's avatarFrediano Ziglio <freddy77@gmail.com>
Acked-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
parent f5121d14
......@@ -61,6 +61,7 @@ headers = [
'sys/types.h',
'netinet/in.h',
'arpa/inet.h',
'valgrind/valgrind.h'
]
foreach header : headers
......@@ -346,6 +347,14 @@ if d.found()
spice_gtk_config_data.set('USE_SMARTCARD', '1')
endif
# valgrind
if get_option('valgrind')
if spice_gtk_config_data.get('HAVE_VALGRIND_VALGRIND_H', '0') != '1'
error('Valgrind requested but headers not found')
endif
spice_gtk_config_data.set('HAVE_VALGRIND', '1')
endif
#
# global C defines
#
......
......@@ -85,3 +85,8 @@ option('recorder',
type : 'boolean',
value : false,
description: 'Enable recorder instrumentation')
option('valgrind',
type : 'boolean',
value : false,
description : 'Enable Valgrind support')
......@@ -44,6 +44,9 @@ struct coroutine
#if WITH_UCONTEXT
struct continuation cc;
#ifdef HAVE_VALGRIND
unsigned int vg_stack;
#endif
#elif WITH_WINFIBER
LPVOID fiber;
int ret;
......
......@@ -30,6 +30,9 @@
#include <stdlib.h>
#include <string.h>
#include <spice/macros.h>
#ifdef HAVE_VALGRIND
#include <valgrind/valgrind.h>
#endif
#include "coroutine.h"
#ifndef MAP_ANONYMOUS
......@@ -45,6 +48,9 @@ static int _coroutine_release(struct continuation *cc)
{
struct coroutine *co = SPICE_CONTAINEROF(cc, struct coroutine, cc);
#ifdef HAVE_VALGRIND
VALGRIND_STACK_DEREGISTER(co->vg_stack);
#endif
munmap(co->cc.stack, co->cc.stack_size);
co->caller = NULL;
......@@ -71,6 +77,9 @@ void coroutine_init(struct coroutine *co)
if (co->cc.stack == MAP_FAILED)
g_error("mmap(%" G_GSIZE_FORMAT ") failed: %s",
co->stack_size, g_strerror(errno));
#ifdef HAVE_VALGRIND
co->vg_stack = VALGRIND_STACK_REGISTER(co->cc.stack, co->cc.stack + co->stack_size);
#endif
co->cc.entry = coroutine_trampoline;
co->cc.release = _coroutine_release;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment