Fix: pass private data to context callbacks
[lttng-ust.git] / liblttng-ust / lttng-ust-comm.c
index 428108646b765d00b9e5df272ec7e97de0bcc1ed..c0a7311fa66e7797c62c8a207a429e28ad190dcf 100644 (file)
 #include <urcu/compiler.h>
 #include <lttng/urcu/urcu-ust.h>
 
+#include <lttng/ust-utils.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-abi.h>
-#include <lttng/ust.h>
+#include <lttng/ust-fork.h>
 #include <lttng/ust-error.h>
 #include <lttng/ust-ctl.h>
 #include <lttng/ust-libc-wrapper.h>
+#include <lttng/ust-thread.h>
+#include <lttng/ust-tracer.h>
 #include <urcu/tls-compat.h>
 #include <ust-comm.h>
 #include <ust-fd.h>
@@ -51,9 +54,8 @@
 #include "ust-events-internal.h"
 #include "context-internal.h"
 #include "ust-compat.h"
-
-/* Concatenate lttng ust shared library name with its major version number. */
-#define LTTNG_UST_LIB_SO_NAME "liblttng-ust.so." __ust_stringify(CONFIG_LTTNG_UST_LIBRARY_VERSION_MAJOR)
+#include "lttng-counter-client.h"
+#include "lttng-rb-clients.h"
 
 /*
  * Has lttng ust comm constructor been called ?
@@ -351,29 +353,6 @@ static const char *cmd_name_mapping[] = {
 static const char *str_timeout;
 static int got_timeout_env;
 
-extern void lttng_ring_buffer_client_overwrite_init(void);
-extern void lttng_ring_buffer_client_overwrite_rt_init(void);
-extern void lttng_ring_buffer_client_discard_init(void);
-extern void lttng_ring_buffer_client_discard_rt_init(void);
-extern void lttng_ring_buffer_metadata_client_init(void);
-extern void lttng_ring_buffer_client_overwrite_exit(void);
-extern void lttng_ring_buffer_client_overwrite_rt_exit(void);
-extern void lttng_ring_buffer_client_discard_exit(void);
-extern void lttng_ring_buffer_client_discard_rt_exit(void);
-extern void lttng_ring_buffer_metadata_client_exit(void);
-
-__attribute__((visibility("hidden")))
-extern void lttng_counter_client_percpu_32_modular_init(void);
-
-__attribute__((visibility("hidden")))
-extern void lttng_counter_client_percpu_32_modular_exit(void);
-
-__attribute__((visibility("hidden")))
-extern void lttng_counter_client_percpu_64_modular_init(void);
-
-__attribute__((visibility("hidden")))
-extern void lttng_counter_client_percpu_64_modular_exit(void);
-
 static char *get_map_shm(struct sock_info *sock_info);
 
 ssize_t lttng_ust_read(int fd, void *buf, size_t len)
@@ -449,6 +428,31 @@ void lttng_ust_fixup_tls(void)
        lttng_fixup_net_ns_tls();
        lttng_fixup_time_ns_tls();
        lttng_fixup_uts_ns_tls();
+       lttng_ust_fixup_ring_buffer_client_discard_tls();
+       lttng_ust_fixup_ring_buffer_client_discard_rt_tls();
+       lttng_ust_fixup_ring_buffer_client_overwrite_tls();
+       lttng_ust_fixup_ring_buffer_client_overwrite_rt_tls();
+}
+
+/*
+ * LTTng-UST uses Global Dynamic model TLS variables rather than IE
+ * model because many versions of glibc don't preallocate a pool large
+ * enough for TLS variables IE model defined in other shared libraries,
+ * and causes issues when using LTTng-UST for Java tracing.
+ *
+ * Because of this use of Global Dynamic TLS variables, users wishing to
+ * trace from signal handlers need to explicitly trigger the lazy
+ * allocation of those variables for each thread before using them.
+ * This can be triggered by calling lttng_ust_init_thread().
+ */
+void lttng_ust_init_thread(void)
+{
+       /*
+        * Because those TLS variables are global dynamic, we need to
+        * ensure those are initialized before a signal handler nesting over
+        * this thread attempts to use them.
+        */
+       lttng_ust_fixup_tls();
 }
 
 int lttng_get_notify_socket(void *owner)
@@ -638,11 +642,11 @@ int register_to_sessiond(int socket, enum ustctl_socket_type type)
        return ustcomm_send_reg_msg(socket,
                type,
                CAA_BITS_PER_LONG,
-               lttng_alignof(uint8_t) * CHAR_BIT,
-               lttng_alignof(uint16_t) * CHAR_BIT,
-               lttng_alignof(uint32_t) * CHAR_BIT,
-               lttng_alignof(uint64_t) * CHAR_BIT,
-               lttng_alignof(unsigned long) * CHAR_BIT);
+               lttng_ust_rb_alignof(uint8_t) * CHAR_BIT,
+               lttng_ust_rb_alignof(uint16_t) * CHAR_BIT,
+               lttng_ust_rb_alignof(uint32_t) * CHAR_BIT,
+               lttng_ust_rb_alignof(uint64_t) * CHAR_BIT,
+               lttng_ust_rb_alignof(unsigned long) * CHAR_BIT);
 }
 
 static
@@ -2064,7 +2068,11 @@ void lttng_ust_libc_wrapper_malloc_init(void)
  * sessiond monitoring thread: monitor presence of global and per-user
  * sessiond by polling the application common named pipe.
  */
-void __attribute__((constructor)) lttng_ust_init(void)
+static
+void lttng_ust_init(void)
+       __attribute__((constructor));
+static
+void lttng_ust_init(void)
 {
        struct timespec constructor_timeout;
        sigset_t sig_all_blocked, orig_parent_mask;
@@ -2092,7 +2100,7 @@ void __attribute__((constructor)) lttng_ust_init(void)
         * liblttng-ust.so to increment the dynamic loader's internal refcount for
         * this library so it never becomes zero, thus never gets unloaded from the
         * address space of the process. Since we are already running in the
-        * constructor of the LTTNG_UST_LIB_SO_NAME library, calling dlopen will
+        * constructor of the LTTNG_UST_LIB_SONAME library, calling dlopen will
         * simply increment the refcount and no additionnal work is needed by the
         * dynamic loader as the shared library is already loaded in the address
         * space. As a safe guard, we use the RTLD_NODELETE flag to prevent
@@ -2100,9 +2108,9 @@ void __attribute__((constructor)) lttng_ust_init(void)
         * never happen). Do the return value check but discard the handle at the
         * end of the function as it's not needed.
         */
-       handle = dlopen(LTTNG_UST_LIB_SO_NAME, RTLD_LAZY | RTLD_NODELETE);
+       handle = dlopen(LTTNG_UST_LIB_SONAME, RTLD_LAZY | RTLD_NODELETE);
        if (!handle) {
-               ERR("dlopen of liblttng-ust shared library (%s).", LTTNG_UST_LIB_SO_NAME);
+               ERR("dlopen of liblttng-ust shared library (%s).", LTTNG_UST_LIB_SONAME);
        }
 
        /*
@@ -2118,13 +2126,8 @@ void __attribute__((constructor)) lttng_ust_init(void)
        lttng_ust_clock_init();
        lttng_ust_getcpu_init();
        lttng_ust_statedump_init();
-       lttng_ring_buffer_metadata_client_init();
-       lttng_ring_buffer_client_overwrite_init();
-       lttng_ring_buffer_client_overwrite_rt_init();
-       lttng_ring_buffer_client_discard_init();
-       lttng_ring_buffer_client_discard_rt_init();
-       lttng_counter_client_percpu_32_modular_init();
-       lttng_counter_client_percpu_64_modular_init();
+       lttng_ust_ring_buffer_clients_init();
+       lttng_ust_counter_clients_init();
        lttng_perf_counter_init();
        /*
         * Invoke ust malloc wrapper init before starting other threads.
@@ -2265,13 +2268,8 @@ void lttng_ust_cleanup(int exiting)
        lttng_ust_abi_exit();
        lttng_ust_abi_events_exit();
        lttng_perf_counter_exit();
-       lttng_ring_buffer_client_discard_rt_exit();
-       lttng_ring_buffer_client_discard_exit();
-       lttng_ring_buffer_client_overwrite_rt_exit();
-       lttng_ring_buffer_client_overwrite_exit();
-       lttng_ring_buffer_metadata_client_exit();
-       lttng_counter_client_percpu_32_modular_exit();
-       lttng_counter_client_percpu_64_modular_exit();
+       lttng_ust_ring_buffer_clients_exit();
+       lttng_ust_counter_clients_exit();
        lttng_ust_statedump_destroy();
        lttng_ust_tp_exit();
        if (!exiting) {
@@ -2282,7 +2280,11 @@ void lttng_ust_cleanup(int exiting)
        }
 }
 
-void __attribute__((destructor)) lttng_ust_exit(void)
+static
+void lttng_ust_exit(void)
+       __attribute__((destructor));
+static
+void lttng_ust_exit(void)
 {
        int ret;
 
@@ -2370,7 +2372,7 @@ void ust_context_vgids_reset(void)
  * in the middle of an tracepoint or ust tracing state modification.
  * Holding this mutex protects these structures across fork and clone.
  */
-void ust_before_fork(sigset_t *save_sigset)
+void lttng_ust_before_fork(sigset_t *save_sigset)
 {
        /*
         * Disable signals. This is to avoid that the child intervenes
@@ -2419,7 +2421,7 @@ static void ust_after_fork_common(sigset_t *restore_sigset)
        }
 }
 
-void ust_after_fork_parent(sigset_t *restore_sigset)
+void lttng_ust_after_fork_parent(sigset_t *restore_sigset)
 {
        if (URCU_TLS(lttng_ust_nest_count))
                return;
@@ -2438,7 +2440,7 @@ void ust_after_fork_parent(sigset_t *restore_sigset)
  * This is meant for forks() that have tracing in the child between the
  * fork and following exec call (if there is any).
  */
-void ust_after_fork_child(sigset_t *restore_sigset)
+void lttng_ust_after_fork_child(sigset_t *restore_sigset)
 {
        if (URCU_TLS(lttng_ust_nest_count))
                return;
@@ -2457,56 +2459,56 @@ void ust_after_fork_child(sigset_t *restore_sigset)
        lttng_ust_init();
 }
 
-void ust_after_setns(void)
+void lttng_ust_after_setns(void)
 {
        ust_context_ns_reset();
        ust_context_vuids_reset();
        ust_context_vgids_reset();
 }
 
-void ust_after_unshare(void)
+void lttng_ust_after_unshare(void)
 {
        ust_context_ns_reset();
        ust_context_vuids_reset();
        ust_context_vgids_reset();
 }
 
-void ust_after_setuid(void)
+void lttng_ust_after_setuid(void)
 {
        ust_context_vuids_reset();
 }
 
-void ust_after_seteuid(void)
+void lttng_ust_after_seteuid(void)
 {
        ust_context_vuids_reset();
 }
 
-void ust_after_setreuid(void)
+void lttng_ust_after_setreuid(void)
 {
        ust_context_vuids_reset();
 }
 
-void ust_after_setresuid(void)
+void lttng_ust_after_setresuid(void)
 {
        ust_context_vuids_reset();
 }
 
-void ust_after_setgid(void)
+void lttng_ust_after_setgid(void)
 {
        ust_context_vgids_reset();
 }
 
-void ust_after_setegid(void)
+void lttng_ust_after_setegid(void)
 {
        ust_context_vgids_reset();
 }
 
-void ust_after_setregid(void)
+void lttng_ust_after_setregid(void)
 {
        ust_context_vgids_reset();
 }
 
-void ust_after_setresgid(void)
+void lttng_ust_after_setresgid(void)
 {
        ust_context_vgids_reset();
 }
This page took 0.026213 seconds and 4 git commands to generate.