From: Ian Jackson Date: Thu, 17 May 2012 13:45:40 +0000 (+0100) Subject: libxl: events: STATE_AO_GC checks ao is still valid X-Git-Tag: 4.2.0-rc1~326 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=79d00fc950e952a06fa986af6c58341705f06fac;p=xen.git libxl: events: STATE_AO_GC checks ao is still valid This will catch earlier the mistake where an ao is completed while it still has events registered: when the event callback happens for the long-gone ao, we will crash before attempting to execute any of the operation-specific code. Signed-off-by: Ian Jackson Committed-by: Ian Campbell --- diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c index 03d0498020..350e846aa4 100644 --- a/tools/libxl/libxl_event.c +++ b/tools/libxl/libxl_event.c @@ -1352,6 +1352,13 @@ void libxl__ao_abort(libxl__ao *ao) libxl__ao__destroy(CTX, ao); } +libxl__gc *libxl__ao_inprogress_gc(libxl__ao *ao) +{ + assert(ao->magic == LIBXL__AO_MAGIC); + assert(!ao->complete); + return &ao->gc; +} + void libxl__ao_complete(libxl__egc *egc, libxl__ao *ao, int rc) { assert(ao->magic == LIBXL__AO_MAGIC); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index b2fe8bb101..73b991524e 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1575,7 +1575,7 @@ _hidden void libxl__egc_cleanup(libxl__egc *egc); #define STATE_AO_GC(op_ao) \ libxl__ao *const ao = (op_ao); \ - AO_GC + libxl__gc *const gc __attribute__((unused)) = libxl__ao_inprogress_gc(ao) /* All of these MUST be called with the ctx locked. @@ -1585,6 +1585,7 @@ _hidden libxl__ao *libxl__ao_create(libxl_ctx*, uint32_t domid, _hidden int libxl__ao_inprogress(libxl__ao *ao); /* temporarily unlocks */ _hidden void libxl__ao_abort(libxl__ao *ao); _hidden void libxl__ao_complete(libxl__egc *egc, libxl__ao *ao, int rc); +_hidden libxl__gc *libxl__ao_inprogress_gc(libxl__ao *ao); /* Can be called at any time. Use is essential for any aop user. */ _hidden void libxl__ao_progress_gethow(libxl_asyncprogress_how *in_state,