From: Mathieu Desnoyers Date: Mon, 31 Aug 2015 20:50:03 +0000 (-0400) Subject: baddr statedump: hold ust lock around allocations X-Git-Url: http://git.efficios.com/?p=deliverable%2Flttng-ust.git;a=commitdiff_plain;h=d34e6761379227cfd49abb6eab184e1e254ee0b2 baddr statedump: hold ust lock around allocations Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust/lttng-ust-statedump.c b/liblttng-ust/lttng-ust-statedump.c index 0c0a7bdd..93a035b3 100644 --- a/liblttng-ust/lttng-ust-statedump.c +++ b/liblttng-ust/lttng-ust-statedump.c @@ -66,14 +66,6 @@ int trace_statedump_event(tracepoint_cb tp_cb, void *owner, void *priv) struct cds_list_head *sessionsp; struct lttng_session *session; - /* - * UST lock nests within dynamic loader lock. - */ - if (ust_lock()) { - ust_unlock(); - return 1; - } - sessionsp = _lttng_get_sessions(); cds_list_for_each_entry(session, sessionsp, node) { if (session->owner != owner) @@ -82,7 +74,6 @@ int trace_statedump_event(tracepoint_cb tp_cb, void *owner, void *priv) continue; tp_cb(session, priv); } - ust_unlock(); return 0; } @@ -217,9 +208,20 @@ int trace_statedump_end(void *owner) static int extract_soinfo_events(struct dl_phdr_info *info, size_t size, void *_data) { - int j; + int j, ret = 0; struct dl_iterate_data *data = _data; + /* + * UST lock nests within dynamic loader lock. + * + * Hold this lock across handling of the entire module to + * protect memory allocation at early process start, due to + * interactions with libc-wrapper lttng malloc instrumentation. + */ + if (ust_lock()) { + goto end; + } + for (j = 0; j < info->dlpi_phnum; j++) { struct soinfo_data so_data; char resolved_path[PATH_MAX]; @@ -276,10 +278,12 @@ int extract_soinfo_events(struct dl_phdr_info *info, size_t size, void *_data) so_data.owner = data->owner; so_data.base_addr_ptr = base_addr_ptr; so_data.resolved_path = resolved_path; - return trace_baddr(&so_data); + ret = trace_baddr(&so_data); + break; } - - return 0; +end: + ust_unlock(); + return ret; } /*