dlopen() liblttng-ust.so from constructor to prevent unloading
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Fri, 9 Feb 2018 20:15:23 +0000 (15:15 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 9 Feb 2018 20:41:04 +0000 (15:41 -0500)
commitb2292d8567372f5bbadaeb0cd7b26e6fc4cd1b56
tree12253f4329a8b3e8410c72d662d7bbb897484650
parent35ac38cb4cc188253c600766882b7a833f5a81ee
dlopen() liblttng-ust.so from constructor to prevent unloading

The support of probe provider dlclose() allows for the following
problematic scenario:
- Application is not linked against the liblttng-ust.so
- Application dlopen() a probe provider library that is linked against
  liblttng-ust.so
- Application dlclose() the probe provider

In this scenario, the probe provider has a dependency on
liblttng-ust.so, so when it's loaded by the application, liblttng-ust.so
is loaded too. The probe provider library now has the only reference to
the liblttng-ust.so library.  When the application calls dlclose() on
it, all its references are dropped, thus triggering the unloading of
both the probe provider library and liblttng-ust.so.

This scenario is problematic because lttng ust_listener_threads are in
DETACHED state. We cannot join them and therefore we cannot unload the
library containing the code they run. Only the operating system can free
those resources.

The reason why those threads are in DETACHED state is to quickly
teardown applications on process exit.

A possible solution to investigate: if we can determine whether
liblttng-ust.so is being dlopen (directly or undirectly) or it's linked
against the application, we could set the detached state accordingly.

To prevent that unloading, we pin it in memory by grabbing an extra
reference on the library, with a RTLD_NODELETE flag. This will prevent
the dynamic loader from ever removing the liblttng-ust.so library from
the process' address space.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
configure.ac
liblttng-ust/Makefile.am
liblttng-ust/lttng-ust-comm.c
This page took 0.025546 seconds and 4 git commands to generate.