lttng/ust-tracepoint-event-nowrite.h \
lttng/ust-arch.h \
lttng/ust-events.h \
+ lttng/ust-common.h \
lttng/ust-ctl.h \
lttng/ust-abi.h \
lttng/ust-tracer.h \
--- /dev/null
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * Public symbols of liblttng-ust-common.so
+ */
+
+#ifndef _LTTNG_UST_COMMON_H
+#define _LTTNG_UST_COMMON_H
+
+/*
+ * The liblttng-ust-common constructor is public so it can be called in the
+ * constructors of client libraries since there is no reliable way to guarantee
+ * the execution order of constructors across shared library.
+ */
+void lttng_ust_common_ctor(void)
+ __attribute__((constructor));
+
+#endif
* function in liblttng-ust that is overridden by the one in
* liblttng-ust-wrapper-libc when it's preloaded.
*/
-void lttng_ust_libc_wrapper_malloc_init(void)
+void lttng_ust_libc_wrapper_malloc_ctor(void)
__attribute__((constructor));
#endif
#include <stdio.h>
-void lttng_ust_init_fd_tracker(void);
int lttng_ust_add_fd_to_tracker(int fd);
void lttng_ust_delete_fd_from_tracker(int fd);
void lttng_ust_lock_fd_tracker(void);
liblttng_ust_common_la_SOURCES = \
fd-tracker.c \
+ fd-tracker.h \
ust-common.c \
lttng-ust-urcu.c \
lttng-ust-urcu-pointer.c
#include <lttng/ust-error.h>
#include "common/logging.h"
+#include "lib/lttng-ust-common/fd-tracker.h"
+
/* Operations on the fd set. */
#define IS_FD_VALID(fd) ((fd) >= 0 && (fd) < lttng_ust_max_fd)
#define GET_FD_SET_FOR_FD(fd, fd_sets) (&((fd_sets)[(fd) / FD_SETSIZE]))
* process. This will be called during the constructor execution
* and will also be called in the child after fork via lttng_ust_init.
*/
-void lttng_ust_init_fd_tracker(void)
+void lttng_ust_fd_tracker_init(void)
{
struct rlimit rlim;
int i;
* Ensure the tracker is initialized when called from
* constructors.
*/
- lttng_ust_init_fd_tracker();
+ lttng_ust_fd_tracker_init();
assert(URCU_TLS(ust_fd_mutex_nest));
if (IS_FD_STD(fd)) {
* Ensure the tracker is initialized when called from
* constructors.
*/
- lttng_ust_init_fd_tracker();
+ lttng_ust_fd_tracker_init();
assert(URCU_TLS(ust_fd_mutex_nest));
/* Not a valid fd. */
* Ensure the tracker is initialized when called from
* constructors.
*/
- lttng_ust_init_fd_tracker();
+ lttng_ust_fd_tracker_init();
/*
* If called from lttng-ust, we directly call close without
* Ensure the tracker is initialized when called from
* constructors.
*/
- lttng_ust_init_fd_tracker();
+ lttng_ust_fd_tracker_init();
/*
* If called from lttng-ust, we directly call fclose without
* Ensure the tracker is initialized when called from
* constructors.
*/
- lttng_ust_init_fd_tracker();
+ lttng_ust_fd_tracker_init();
if (lowfd < 0) {
/*
--- /dev/null
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com>
+ */
+
+#ifndef _LTTNG_UST_COMMON_FD_TRACKER_H
+#define _LTTNG_UST_COMMON_FD_TRACKER_H
+
+void lttng_ust_fd_tracker_init(void)
+ __attribute__((visibility("hidden")));
+
+#endif
* Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com>
*/
+#include <lttng/ust-common.h>
+
#include "common/logging.h"
#include "common/ust-fd.h"
+#include "common/getenv.h"
+
+#include "lib/lttng-ust-common/fd-tracker.h"
-static
-void lttng_ust_common_init(void)
- __attribute__((constructor));
-static
-void lttng_ust_common_init(void)
+/*
+ * The liblttng-ust-common constructor, initialize the internal shared state.
+ * Libraries linking on liblttng-ust-common should also call this early in
+ * their constructor since there is no reliable way to guarantee the execution
+ * order of constructors across shared library.
+ */
+void lttng_ust_common_ctor(void)
{
/*
- * Initialize the fd-tracker, other libraries using it should also call
- * this in their constructor in case it gets executed before this one.
+ * Initialize the shared state of the fd tracker.
*/
- lttng_ust_init_fd_tracker();
+ lttng_ust_fd_tracker_init();
}
#include <lttng/ust-ctl.h>
#include <lttng/ust-abi.h>
#include <lttng/ust-endian.h>
+#include <lttng/ust-common.h>
#include "common/logging.h"
#include "common/ustcomm.h"
}
static
-void ustctl_init(void)
+void lttng_ust_ctl_ctor(void)
__attribute__((constructor));
static
-void ustctl_init(void)
+void lttng_ust_ctl_ctor(void)
{
+ /*
+ * Call the liblttng-ust-common constructor to ensure it runs first.
+ */
+ lttng_ust_common_ctor();
+
lttng_ust_clock_init();
lttng_ust_ring_buffer_clients_init();
lttng_ust_counter_clients_init();
liblttng_ust_fd_la_LIBADD = \
$(top_builddir)/src/lib/lttng-ust/liblttng-ust.la \
+ $(top_builddir)/src/lib/lttng-ust-common/liblttng-ust-common.la \
+ $(top_builddir)/src/common/libcommon.la \
$(DL_LIBS)
liblttng_ust_fd_la_LDFLAGS = -version-info $(LTTNG_UST_LIBRARY_VERSION)
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
-#include "common/ust-fd.h"
#include <dlfcn.h>
+#include <lttng/ust-common.h>
+
#include "common/macros.h"
+#include "common/ust-fd.h"
static int (*__lttng_ust_fd_plibc_close)(int fd);
static int (*__lttng_ust_fd_plibc_fclose)(FILE *stream);
+static
+void _lttng_ust_fd_ctor(void)
+ __attribute__((constructor));
+static
+void _lttng_ust_fd_ctor(void)
+{
+ lttng_ust_common_ctor();
+}
+
static
int _lttng_ust_fd_libc_close(int fd)
{
asm volatile ("" : : "m" (URCU_TLS(malloc_nesting)));
}
-void lttng_ust_libc_wrapper_malloc_init(void)
+void lttng_ust_libc_wrapper_malloc_ctor(void)
{
/* Initialization already done */
if (cur_alloc.calloc) {
#include <lttng/tracepoint.h>
#include <lttng/ust-abi.h> /* for LTTNG_UST_ABI_SYM_NAME_LEN */
+#include <lttng/ust-common.h>
#include "common/logging.h"
#include "common/macros.h"
if (uatomic_xchg(&initialized, 1) == 1)
return;
lttng_ust_logging_init();
+ lttng_ust_common_ctor();
check_weak_hidden();
}
#include <lttng/ust-libc-wrapper.h>
#include <lttng/ust-thread.h>
#include <lttng/ust-tracer.h>
+#include <lttng/ust-common.h>
#include <urcu/tls-compat.h>
#include "common/compat/futex.h"
#include "common/ustcomm.h"
* Weak symbol to call when the ust malloc wrapper is not loaded.
*/
__attribute__((weak))
-void lttng_ust_libc_wrapper_malloc_init(void)
+void lttng_ust_libc_wrapper_malloc_ctor(void)
{
}
* sessiond by polling the application common named pipe.
*/
static
-void lttng_ust_init(void)
+void lttng_ust_ctor(void)
__attribute__((constructor));
static
-void lttng_ust_init(void)
+void lttng_ust_ctor(void)
{
struct timespec constructor_timeout;
sigset_t sig_all_blocked, orig_parent_mask;
lttng_ust_logging_init();
lttng_ust_getenv_init();
+ /* Call the liblttng-ust-common constructor. */
+ lttng_ust_common_ctor();
+
lttng_ust_tp_init();
- lttng_ust_init_fd_tracker();
lttng_ust_clock_init();
lttng_ust_getcpu_plugin_init();
lttng_ust_statedump_init();
/*
* Invoke ust malloc wrapper init before starting other threads.
*/
- lttng_ust_libc_wrapper_malloc_init();
+ lttng_ust_libc_wrapper_malloc_ctor();
timeout_mode = get_constructor_timeout(&constructor_timeout);
* After fork, in the child, we need to cleanup all the leftover state,
* except the worker thread which already magically disappeared thanks
* to the weird Linux fork semantics. After tyding up, we call
- * lttng_ust_init() again to start over as a new PID.
+ * lttng_ust_ctor() again to start over as a new PID.
*
* This is meant for forks() that have tracing in the child between the
* fork and following exec call (if there is any).
lttng_ust_cleanup(0);
/* Release mutexes and reenable signals */
ust_after_fork_common(restore_sigset);
- lttng_ust_init();
+ lttng_ust_ctor();
}
void lttng_ust_after_setns(void)