baddr statedump: hold ust lock around allocations
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 31 Aug 2015 20:50:03 +0000 (16:50 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 31 Aug 2015 20:50:03 +0000 (16:50 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust/lttng-ust-statedump.c

index 0c0a7bddaa5329004e2ced770a0dfc1e7a018577..93a035b35a0ead7032e2ae121d8168f5c624c6da 100644 (file)
@@ -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;
 }
 
 /*
This page took 0.025862 seconds and 4 git commands to generate.