From: Michael Jeanson Date: Fri, 2 Apr 2021 18:45:42 +0000 (-0400) Subject: Move internal headers to 'src/' dir X-Git-Tag: v2.13.0-rc1~146 X-Git-Url: http://git.lttng.org/?a=commitdiff_plain;h=9d315d6d74aac2986b10d708c864d152a0febec7;p=lttng-ust.git Move internal headers to 'src/' dir Move internal headers from the global 'include' directory to their respective private directories under 'src/'. Remove the 'ust-' prefix when appropriate as they are now included with the 'common/' path which makes it easier to distinguish public and internal headers. This is part of an effort to standardize our autotools setup across projects to simplify maintenance. Change-Id: If5510bbe9294ba1f0dcd4b101b363e7ef64e255d Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/.gitignore b/.gitignore index 42171575..37d46f9f 100644 --- a/.gitignore +++ b/.gitignore @@ -123,6 +123,7 @@ cscope.* /doc/examples/Makefile /doc/man/Makefile /include/Makefile +/src/common/Makefile /src/libcounter/Makefile /src/liblttng-ust-comm/Makefile /src/liblttng-ust-ctl/Makefile diff --git a/configure.ac b/configure.ac index 80226c78..00b70f2a 100644 --- a/configure.ac +++ b/configure.ac @@ -518,6 +518,7 @@ AC_CONFIG_FILES([ doc/Makefile doc/man/Makefile include/Makefile + src/common/Makefile src/libcounter/Makefile src/liblttng-ust-comm/Makefile src/liblttng-ust-ctl/Makefile diff --git a/include/Makefile.am b/include/Makefile.am index 854b4785..5ef7c9e5 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -42,34 +42,3 @@ nobase_include_HEADERS = \ nobase_nodist_include_HEADERS = \ lttng/ust-config.h \ lttng/ust-version.h - - -### ### -### Global private headers ### -### ### - -noinst_HEADERS = \ - usterr-signal-safe.h \ - ust-snprintf.h \ - ust-bitmap.h \ - ust-comm.h \ - ust-compat.h \ - ust-elf.h \ - ust-tid.h \ - ust-bitfield.h \ - ust-dlfcn.h \ - ust-dynamic-type.h \ - ust-helper.h \ - ust-share.h - - -# These headers should be moved to the public headers when tested and -# documented. The symbols are still part of the ABI. - -# Used by the Java jni interface. -noinst_HEADERS += \ - ust-context-provider.h - -# Used by liblttng-ust-fd -noinst_HEADERS += \ - ust-fd.h diff --git a/include/ust-bitfield.h b/include/ust-bitfield.h deleted file mode 100644 index 105dae51..00000000 --- a/include/ust-bitfield.h +++ /dev/null @@ -1,509 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (C) 2010-2019 Mathieu Desnoyers - */ - -#ifndef _BABELTRACE_BITFIELD_H -#define _BABELTRACE_BITFIELD_H - -#include /* C99 5.2.4.2 Numerical limits */ -#include /* C99 5.2.4.2 Numerical limits */ -#include /* C99 7.16 bool type */ -#include /* Non-standard BIG_ENDIAN, LITTLE_ENDIAN, BYTE_ORDER */ - -/* - * This header strictly follows the C99 standard, except for use of the - * compiler-specific __typeof__. - */ - -/* - * This bitfield header requires the compiler representation of signed - * integers to be two's complement. - */ -#if (-1 != ~0) -#error "bitfield.h requires the compiler representation of signed integers to be two's complement." -#endif - -#define _bt_is_signed_type(type) ((type) -1 < (type) 1) - -/* - * Produce a build-time error if the condition `cond` is non-zero. - * Evaluates as a size_t expression. - */ -#ifdef __cplusplus -#define _BT_BUILD_ASSERT(cond) ([]{static_assert((cond), "");}, 0) -#else -#define _BT_BUILD_ASSERT(cond) \ - sizeof(struct { int f:(2 * !!(cond) - 1); }) -#endif - -/* - * Cast value `v` to an unsigned integer of the same size as `v`. - */ -#define _bt_cast_value_to_unsigned(v) \ - (sizeof(v) == sizeof(uint8_t) ? (uint8_t) (v) : \ - sizeof(v) == sizeof(uint16_t) ? (uint16_t) (v) : \ - sizeof(v) == sizeof(uint32_t) ? (uint32_t) (v) : \ - sizeof(v) == sizeof(uint64_t) ? (uint64_t) (v) : \ - _BT_BUILD_ASSERT(sizeof(v) <= sizeof(uint64_t))) - -/* - * Cast value `v` to an unsigned integer type of the size of type `type` - * *without* sign-extension. - * - * The unsigned cast ensures that we're not shifting a negative value, - * which is undefined in C. However, this limits the maximum type size - * of `type` to 64-bit. Generate a compile-time error if the size of - * `type` is larger than 64-bit. - */ -#define _bt_cast_value_to_unsigned_type(type, v) \ - (sizeof(type) == sizeof(uint8_t) ? \ - (uint8_t) _bt_cast_value_to_unsigned(v) : \ - sizeof(type) == sizeof(uint16_t) ? \ - (uint16_t) _bt_cast_value_to_unsigned(v) : \ - sizeof(type) == sizeof(uint32_t) ? \ - (uint32_t) _bt_cast_value_to_unsigned(v) : \ - sizeof(type) == sizeof(uint64_t) ? \ - (uint64_t) _bt_cast_value_to_unsigned(v) : \ - _BT_BUILD_ASSERT(sizeof(v) <= sizeof(uint64_t))) - -/* - * _bt_fill_mask evaluates to a "type" integer with all bits set. - */ -#define _bt_fill_mask(type) ((type) ~(type) 0) - -/* - * Left shift a value `v` of `shift` bits. - * - * The type of `v` can be signed or unsigned integer. - * The value of `shift` must be less than the size of `v` (in bits), - * otherwise the behavior is undefined. - * Evaluates to the result of the shift operation. - * - * According to the C99 standard, left shift of a left hand-side signed - * type is undefined if it has a negative value or if the result cannot - * be represented in the result type. This bitfield header discards the - * bits that are left-shifted beyond the result type representation, - * which is the behavior of an unsigned type left shift operation. - * Therefore, always perform left shift on an unsigned type. - * - * This macro should not be used if `shift` can be greater or equal than - * the bitwidth of `v`. See `_bt_safe_lshift`. - */ -#define _bt_lshift(v, shift) \ - ((__typeof__(v)) (_bt_cast_value_to_unsigned(v) << (shift))) - -/* - * Generate a mask of type `type` with the `length` least significant bits - * cleared, and the most significant bits set. - */ -#define _bt_make_mask_complement(type, length) \ - _bt_lshift(_bt_fill_mask(type), length) - -/* - * Generate a mask of type `type` with the `length` least significant bits - * set, and the most significant bits cleared. - */ -#define _bt_make_mask(type, length) \ - ((type) ~_bt_make_mask_complement(type, length)) - -/* - * Right shift a value `v` of `shift` bits. - * - * The type of `v` can be signed or unsigned integer. - * The value of `shift` must be less than the size of `v` (in bits), - * otherwise the behavior is undefined. - * Evaluates to the result of the shift operation. - * - * According to the C99 standard, right shift of a left hand-side signed - * type which has a negative value is implementation defined. This - * bitfield header relies on the right shift implementation carrying the - * sign bit. If the compiler implementation has a different behavior, - * emulate carrying the sign bit. - * - * This macro should not be used if `shift` can be greater or equal than - * the bitwidth of `v`. See `_bt_safe_rshift`. - */ -#if ((-1 >> 1) == -1) -#define _bt_rshift(v, shift) ((v) >> (shift)) -#else -#define _bt_rshift(v, shift) \ - ((__typeof__(v)) ((_bt_cast_value_to_unsigned(v) >> (shift)) | \ - ((v) < 0 ? _bt_make_mask_complement(__typeof__(v), \ - sizeof(v) * CHAR_BIT - (shift)) : 0))) -#endif - -/* - * Right shift a signed or unsigned integer with `shift` value being an - * arbitrary number of bits. `v` is modified by this macro. The shift - * is transformed into a sequence of `_nr_partial_shifts` consecutive - * shift operations, each of a number of bits smaller than the bitwidth - * of `v`, ending with a shift of the number of left over bits. - */ -#define _bt_safe_rshift(v, shift) \ -do { \ - unsigned long _nr_partial_shifts = (shift) / (sizeof(v) * CHAR_BIT - 1); \ - unsigned long _leftover_bits = (shift) % (sizeof(v) * CHAR_BIT - 1); \ - \ - for (; _nr_partial_shifts; _nr_partial_shifts--) \ - (v) = _bt_rshift(v, sizeof(v) * CHAR_BIT - 1); \ - (v) = _bt_rshift(v, _leftover_bits); \ -} while (0) - -/* - * Left shift a signed or unsigned integer with `shift` value being an - * arbitrary number of bits. `v` is modified by this macro. The shift - * is transformed into a sequence of `_nr_partial_shifts` consecutive - * shift operations, each of a number of bits smaller than the bitwidth - * of `v`, ending with a shift of the number of left over bits. - */ -#define _bt_safe_lshift(v, shift) \ -do { \ - unsigned long _nr_partial_shifts = (shift) / (sizeof(v) * CHAR_BIT - 1); \ - unsigned long _leftover_bits = (shift) % (sizeof(v) * CHAR_BIT - 1); \ - \ - for (; _nr_partial_shifts; _nr_partial_shifts--) \ - (v) = _bt_lshift(v, sizeof(v) * CHAR_BIT - 1); \ - (v) = _bt_lshift(v, _leftover_bits); \ -} while (0) - -/* - * bt_bitfield_write - write integer to a bitfield in native endianness - * - * Save integer to the bitfield, which starts at the "start" bit, has "len" - * bits. - * The inside of a bitfield is from high bits to low bits. - * Uses native endianness. - * For unsigned "v", pad MSB with 0 if bitfield is larger than v. - * For signed "v", sign-extend v if bitfield is larger than v. - * - * On little endian, bytes are placed from the less significant to the most - * significant. Also, consecutive bitfields are placed from lower bits to higher - * bits. - * - * On big endian, bytes are places from most significant to less significant. - * Also, consecutive bitfields are placed from higher to lower bits. - */ - -#define _bt_bitfield_write_le(ptr, type, start, length, v) \ -do { \ - __typeof__(v) _v = (v); \ - type *_ptr = (void *) (ptr); \ - unsigned long _start = (start), _length = (length); \ - type _mask, _cmask; \ - unsigned long _ts = sizeof(type) * CHAR_BIT; /* type size */ \ - unsigned long _start_unit, _end_unit, _this_unit; \ - unsigned long _end, _cshift; /* _cshift is "complement shift" */ \ - \ - if (!_length) \ - break; \ - \ - _end = _start + _length; \ - _start_unit = _start / _ts; \ - _end_unit = (_end + (_ts - 1)) / _ts; \ - \ - /* Trim v high bits */ \ - if (_length < sizeof(_v) * CHAR_BIT) \ - _v &= _bt_make_mask(__typeof__(_v), _length); \ - \ - /* We can now append v with a simple "or", shift it piece-wise */ \ - _this_unit = _start_unit; \ - if (_start_unit == _end_unit - 1) { \ - _mask = _bt_make_mask(type, _start % _ts); \ - if (_end % _ts) \ - _mask |= _bt_make_mask_complement(type, _end % _ts); \ - _cmask = _bt_lshift((type) (_v), _start % _ts); \ - _cmask &= ~_mask; \ - _ptr[_this_unit] &= _mask; \ - _ptr[_this_unit] |= _cmask; \ - break; \ - } \ - if (_start % _ts) { \ - _cshift = _start % _ts; \ - _mask = _bt_make_mask(type, _cshift); \ - _cmask = _bt_lshift((type) (_v), _cshift); \ - _cmask &= ~_mask; \ - _ptr[_this_unit] &= _mask; \ - _ptr[_this_unit] |= _cmask; \ - _bt_safe_rshift(_v, _ts - _cshift); \ - _start += _ts - _cshift; \ - _this_unit++; \ - } \ - for (; _this_unit < _end_unit - 1; _this_unit++) { \ - _ptr[_this_unit] = (type) _v; \ - _bt_safe_rshift(_v, _ts); \ - _start += _ts; \ - } \ - if (_end % _ts) { \ - _mask = _bt_make_mask_complement(type, _end % _ts); \ - _cmask = (type) _v; \ - _cmask &= ~_mask; \ - _ptr[_this_unit] &= _mask; \ - _ptr[_this_unit] |= _cmask; \ - } else \ - _ptr[_this_unit] = (type) _v; \ -} while (0) - -#define _bt_bitfield_write_be(ptr, type, start, length, v) \ -do { \ - __typeof__(v) _v = (v); \ - type *_ptr = (void *) (ptr); \ - unsigned long _start = (start), _length = (length); \ - type _mask, _cmask; \ - unsigned long _ts = sizeof(type) * CHAR_BIT; /* type size */ \ - unsigned long _start_unit, _end_unit, _this_unit; \ - unsigned long _end, _cshift; /* _cshift is "complement shift" */ \ - \ - if (!_length) \ - break; \ - \ - _end = _start + _length; \ - _start_unit = _start / _ts; \ - _end_unit = (_end + (_ts - 1)) / _ts; \ - \ - /* Trim v high bits */ \ - if (_length < sizeof(_v) * CHAR_BIT) \ - _v &= _bt_make_mask(__typeof__(_v), _length); \ - \ - /* We can now append v with a simple "or", shift it piece-wise */ \ - _this_unit = _end_unit - 1; \ - if (_start_unit == _end_unit - 1) { \ - _mask = _bt_make_mask(type, (_ts - (_end % _ts)) % _ts); \ - if (_start % _ts) \ - _mask |= _bt_make_mask_complement(type, _ts - (_start % _ts)); \ - _cmask = _bt_lshift((type) (_v), (_ts - (_end % _ts)) % _ts); \ - _cmask &= ~_mask; \ - _ptr[_this_unit] &= _mask; \ - _ptr[_this_unit] |= _cmask; \ - break; \ - } \ - if (_end % _ts) { \ - _cshift = _end % _ts; \ - _mask = _bt_make_mask(type, _ts - _cshift); \ - _cmask = _bt_lshift((type) (_v), _ts - _cshift); \ - _cmask &= ~_mask; \ - _ptr[_this_unit] &= _mask; \ - _ptr[_this_unit] |= _cmask; \ - _bt_safe_rshift(_v, _cshift); \ - _end -= _cshift; \ - _this_unit--; \ - } \ - for (; (long) _this_unit >= (long) _start_unit + 1; _this_unit--) { \ - _ptr[_this_unit] = (type) _v; \ - _bt_safe_rshift(_v, _ts); \ - _end -= _ts; \ - } \ - if (_start % _ts) { \ - _mask = _bt_make_mask_complement(type, _ts - (_start % _ts)); \ - _cmask = (type) _v; \ - _cmask &= ~_mask; \ - _ptr[_this_unit] &= _mask; \ - _ptr[_this_unit] |= _cmask; \ - } else \ - _ptr[_this_unit] = (type) _v; \ -} while (0) - -/* - * bt_bitfield_write - write integer to a bitfield in native endianness - * bt_bitfield_write_le - write integer to a bitfield in little endian - * bt_bitfield_write_be - write integer to a bitfield in big endian - */ - -#if (BYTE_ORDER == LITTLE_ENDIAN) - -#define bt_bitfield_write(ptr, type, start, length, v) \ - _bt_bitfield_write_le(ptr, type, start, length, v) - -#define bt_bitfield_write_le(ptr, type, start, length, v) \ - _bt_bitfield_write_le(ptr, type, start, length, v) - -#define bt_bitfield_write_be(ptr, type, start, length, v) \ - _bt_bitfield_write_be(ptr, unsigned char, start, length, v) - -#elif (BYTE_ORDER == BIG_ENDIAN) - -#define bt_bitfield_write(ptr, type, start, length, v) \ - _bt_bitfield_write_be(ptr, type, start, length, v) - -#define bt_bitfield_write_le(ptr, type, start, length, v) \ - _bt_bitfield_write_le(ptr, unsigned char, start, length, v) - -#define bt_bitfield_write_be(ptr, type, start, length, v) \ - _bt_bitfield_write_be(ptr, type, start, length, v) - -#else /* (BYTE_ORDER == PDP_ENDIAN) */ - -#error "Byte order not supported" - -#endif - -#define _bt_bitfield_read_le(ptr, type, start, length, vptr) \ -do { \ - __typeof__(*(vptr)) *_vptr = (vptr); \ - __typeof__(*_vptr) _v; \ - type *_ptr = (type *) (ptr); \ - unsigned long _start = (start), _length = (length); \ - type _mask, _cmask; \ - unsigned long _ts = sizeof(type) * CHAR_BIT; /* type size */ \ - unsigned long _start_unit, _end_unit, _this_unit; \ - unsigned long _end, _cshift; /* _cshift is "complement shift" */ \ - \ - if (!_length) { \ - *_vptr = 0; \ - break; \ - } \ - \ - _end = _start + _length; \ - _start_unit = _start / _ts; \ - _end_unit = (_end + (_ts - 1)) / _ts; \ - \ - _this_unit = _end_unit - 1; \ - if (_bt_is_signed_type(__typeof__(_v)) \ - && (_ptr[_this_unit] & _bt_lshift((type) 1, (_end % _ts ? _end % _ts : _ts) - 1))) \ - _v = ~(__typeof__(_v)) 0; \ - else \ - _v = 0; \ - if (_start_unit == _end_unit - 1) { \ - _cmask = _ptr[_this_unit]; \ - _cmask = _bt_rshift(_cmask, _start % _ts); \ - if ((_end - _start) % _ts) { \ - _mask = _bt_make_mask(type, _end - _start); \ - _cmask &= _mask; \ - } \ - _bt_safe_lshift(_v, _end - _start); \ - _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \ - *_vptr = _v; \ - break; \ - } \ - if (_end % _ts) { \ - _cshift = _end % _ts; \ - _mask = _bt_make_mask(type, _cshift); \ - _cmask = _ptr[_this_unit]; \ - _cmask &= _mask; \ - _bt_safe_lshift(_v, _cshift); \ - _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \ - _end -= _cshift; \ - _this_unit--; \ - } \ - for (; (long) _this_unit >= (long) _start_unit + 1; _this_unit--) { \ - _bt_safe_lshift(_v, _ts); \ - _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _ptr[_this_unit]); \ - _end -= _ts; \ - } \ - if (_start % _ts) { \ - _mask = _bt_make_mask(type, _ts - (_start % _ts)); \ - _cmask = _ptr[_this_unit]; \ - _cmask = _bt_rshift(_cmask, _start % _ts); \ - _cmask &= _mask; \ - _bt_safe_lshift(_v, _ts - (_start % _ts)); \ - _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \ - } else { \ - _bt_safe_lshift(_v, _ts); \ - _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _ptr[_this_unit]); \ - } \ - *_vptr = _v; \ -} while (0) - -#define _bt_bitfield_read_be(ptr, type, start, length, vptr) \ -do { \ - __typeof__(*(vptr)) *_vptr = (vptr); \ - __typeof__(*_vptr) _v; \ - type *_ptr = (void *) (ptr); \ - unsigned long _start = (start), _length = (length); \ - type _mask, _cmask; \ - unsigned long _ts = sizeof(type) * CHAR_BIT; /* type size */ \ - unsigned long _start_unit, _end_unit, _this_unit; \ - unsigned long _end, _cshift; /* _cshift is "complement shift" */ \ - \ - if (!_length) { \ - *_vptr = 0; \ - break; \ - } \ - \ - _end = _start + _length; \ - _start_unit = _start / _ts; \ - _end_unit = (_end + (_ts - 1)) / _ts; \ - \ - _this_unit = _start_unit; \ - if (_bt_is_signed_type(__typeof__(_v)) \ - && (_ptr[_this_unit] & _bt_lshift((type) 1, _ts - (_start % _ts) - 1))) \ - _v = ~(__typeof__(_v)) 0; \ - else \ - _v = 0; \ - if (_start_unit == _end_unit - 1) { \ - _cmask = _ptr[_this_unit]; \ - _cmask = _bt_rshift(_cmask, (_ts - (_end % _ts)) % _ts); \ - if ((_end - _start) % _ts) { \ - _mask = _bt_make_mask(type, _end - _start); \ - _cmask &= _mask; \ - } \ - _bt_safe_lshift(_v, _end - _start); \ - _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \ - *_vptr = _v; \ - break; \ - } \ - if (_start % _ts) { \ - _cshift = _start % _ts; \ - _mask = _bt_make_mask(type, _ts - _cshift); \ - _cmask = _ptr[_this_unit]; \ - _cmask &= _mask; \ - _bt_safe_lshift(_v, _ts - _cshift); \ - _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \ - _start += _ts - _cshift; \ - _this_unit++; \ - } \ - for (; _this_unit < _end_unit - 1; _this_unit++) { \ - _bt_safe_lshift(_v, _ts); \ - _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _ptr[_this_unit]); \ - _start += _ts; \ - } \ - if (_end % _ts) { \ - _mask = _bt_make_mask(type, _end % _ts); \ - _cmask = _ptr[_this_unit]; \ - _cmask = _bt_rshift(_cmask, _ts - (_end % _ts)); \ - _cmask &= _mask; \ - _bt_safe_lshift(_v, _end % _ts); \ - _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \ - } else { \ - _bt_safe_lshift(_v, _ts); \ - _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _ptr[_this_unit]); \ - } \ - *_vptr = _v; \ -} while (0) - -/* - * bt_bitfield_read - read integer from a bitfield in native endianness - * bt_bitfield_read_le - read integer from a bitfield in little endian - * bt_bitfield_read_be - read integer from a bitfield in big endian - */ - -#if (BYTE_ORDER == LITTLE_ENDIAN) - -#define bt_bitfield_read(ptr, type, start, length, vptr) \ - _bt_bitfield_read_le(ptr, type, start, length, vptr) - -#define bt_bitfield_read_le(ptr, type, start, length, vptr) \ - _bt_bitfield_read_le(ptr, type, start, length, vptr) - -#define bt_bitfield_read_be(ptr, type, start, length, vptr) \ - _bt_bitfield_read_be(ptr, unsigned char, start, length, vptr) - -#elif (BYTE_ORDER == BIG_ENDIAN) - -#define bt_bitfield_read(ptr, type, start, length, vptr) \ - _bt_bitfield_read_be(ptr, type, start, length, vptr) - -#define bt_bitfield_read_le(ptr, type, start, length, vptr) \ - _bt_bitfield_read_le(ptr, unsigned char, start, length, vptr) - -#define bt_bitfield_read_be(ptr, type, start, length, vptr) \ - _bt_bitfield_read_be(ptr, type, start, length, vptr) - -#else /* (BYTE_ORDER == PDP_ENDIAN) */ - -#error "Byte order not supported" - -#endif - -#endif /* _BABELTRACE_BITFIELD_H */ diff --git a/include/ust-bitmap.h b/include/ust-bitmap.h deleted file mode 100644 index 29cc22e0..00000000 --- a/include/ust-bitmap.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (C) 2020 Mathieu Desnoyers - * - * LTTng Bitmap API - */ - -#ifndef _LTTNG_BITMAP_H -#define _LTTNG_BITMAP_H - -#include -#include -#include -#include - -static inline void lttng_bitmap_index(unsigned int index, unsigned int *word, - unsigned int *bit) -{ - *word = index / CAA_BITS_PER_LONG; - *bit = index % CAA_BITS_PER_LONG; -} - -static inline void lttng_bitmap_set_bit(unsigned int index, unsigned long *p) -{ - unsigned int word, bit; - unsigned long val; - - lttng_bitmap_index(index, &word, &bit); - val = 1U << bit; - uatomic_or(p + word, val); -} - -static inline void lttng_bitmap_clear_bit(unsigned int index, unsigned long *p) -{ - unsigned int word, bit; - unsigned long val; - - lttng_bitmap_index(index, &word, &bit); - val = ~(1U << bit); - uatomic_and(p + word, val); -} - -static inline bool lttng_bitmap_test_bit(unsigned int index, unsigned long *p) -{ - unsigned int word, bit; - - lttng_bitmap_index(index, &word, &bit); - return (CMM_LOAD_SHARED(p[word]) >> bit) & 0x1; -} - -#endif /* _LTTNG_BITMAP_H */ diff --git a/include/ust-comm.h b/include/ust-comm.h deleted file mode 100644 index 775b6bef..00000000 --- a/include/ust-comm.h +++ /dev/null @@ -1,327 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (C) 2011 David Goulet - * Copyright (C) 2011 Julien Desfossez - * Copyright (C) 2011 Mathieu Desnoyers - */ - -/* - * This header is meant for liblttng and libust internal use ONLY. - * These declarations should NOT be considered stable API. - */ - -#ifndef _LTTNG_UST_COMM_H -#define _LTTNG_UST_COMM_H - -#include -#include -#include -#include -#include -#include -#include - -/* - * Default timeout the application waits for the sessiond to send its - * "register done" command. Can be overridden with the environment - * variable "LTTNG_UST_REGISTER_TIMEOUT". Note that if the sessiond is not - * found, the application proceeds directly without any delay. - */ -#define LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS 3000 - -#define LTTNG_DEFAULT_RUNDIR LTTNG_SYSTEM_RUNDIR -#define LTTNG_DEFAULT_HOME_RUNDIR ".lttng" - -/* Queue size of listen(2) */ -#define LTTNG_UST_COMM_MAX_LISTEN 10 -#define LTTNG_UST_COMM_REG_MSG_PADDING 64 - -struct lttng_ust_event_field; -struct lttng_ust_ctx_field; -struct lttng_ust_enum_entry; -struct lttng_integer_type; -struct lttng_ust_session; - -struct ustctl_reg_msg { - uint32_t magic; - uint32_t major; - uint32_t minor; - uint32_t pid; - uint32_t ppid; - uint32_t uid; - uint32_t gid; - uint32_t bits_per_long; - uint32_t uint8_t_alignment; - uint32_t uint16_t_alignment; - uint32_t uint32_t_alignment; - uint32_t uint64_t_alignment; - uint32_t long_alignment; - uint32_t socket_type; /* enum ustctl_socket_type */ - char name[LTTNG_UST_ABI_PROCNAME_LEN]; /* process name */ - char padding[LTTNG_UST_COMM_REG_MSG_PADDING]; -} __attribute__((packed)); - -/* - * Data structure for the commands sent from sessiond to UST. - */ -#define USTCOMM_MSG_PADDING1 32 -#define USTCOMM_MSG_PADDING2 32 -struct ustcomm_ust_msg { - uint32_t handle; - uint32_t cmd; - char padding[USTCOMM_MSG_PADDING1]; - union { - struct lttng_ust_abi_channel channel; - struct lttng_ust_abi_stream stream; - struct lttng_ust_abi_event event; - struct lttng_ust_abi_context context; - struct lttng_ust_abi_tracer_version version; - struct lttng_ust_abi_tracepoint_iter tracepoint; - struct { - uint32_t data_size; /* following filter data */ - uint32_t reloc_offset; - uint64_t seqnum; - } __attribute__((packed)) filter; - struct { - uint32_t count; /* how many names follow */ - } __attribute__((packed)) exclusion; - struct { - uint32_t data_size; /* following capture data */ - uint32_t reloc_offset; - uint64_t seqnum; - } __attribute__((packed)) capture; - struct lttng_ust_abi_counter counter; - struct lttng_ust_abi_counter_global counter_global; - struct lttng_ust_abi_counter_cpu counter_cpu; - /* - * For lttng_ust_abi_EVENT_NOTIFIER_CREATE, a struct - * lttng_ust_abi_event_notifier implicitly follows struct - * ustcomm_ust_msg. - */ - struct { - /* Length of struct lttng_ust_abi_event_notifier */ - uint32_t len; - } event_notifier; - char padding[USTCOMM_MSG_PADDING2]; - } u; -} __attribute__((packed)); - -/* - * Data structure for the response from UST to the session daemon. - * cmd_type is sent back in the reply for validation. - */ -#define USTCOMM_REPLY_PADDING1 32 -#define USTCOMM_REPLY_PADDING2 32 -struct ustcomm_ust_reply { - uint32_t handle; - uint32_t cmd; - int32_t ret_code; /* enum ustcomm_return_code */ - uint32_t ret_val; /* return value */ - char padding[USTCOMM_REPLY_PADDING1]; - union { - struct { - uint64_t memory_map_size; - } __attribute__((packed)) channel; - struct { - uint64_t memory_map_size; - } __attribute__((packed)) stream; - struct lttng_ust_abi_tracer_version version; - struct lttng_ust_abi_tracepoint_iter tracepoint; - char padding[USTCOMM_REPLY_PADDING2]; - } u; -} __attribute__((packed)); - -struct ustcomm_notify_hdr { - uint32_t notify_cmd; -} __attribute__((packed)); - -#define USTCOMM_NOTIFY_EVENT_MSG_PADDING 32 -struct ustcomm_notify_event_msg { - uint32_t session_objd; - uint32_t channel_objd; - char event_name[LTTNG_UST_ABI_SYM_NAME_LEN]; - int32_t loglevel; - uint32_t signature_len; - uint32_t fields_len; - uint32_t model_emf_uri_len; - char padding[USTCOMM_NOTIFY_EVENT_MSG_PADDING]; - /* followed by signature, fields, and model_emf_uri */ -} __attribute__((packed)); - -#define USTCOMM_NOTIFY_EVENT_REPLY_PADDING 32 -struct ustcomm_notify_event_reply { - int32_t ret_code; /* 0: ok, negative: error code */ - uint32_t event_id; - char padding[USTCOMM_NOTIFY_EVENT_REPLY_PADDING]; -} __attribute__((packed)); - -#define USTCOMM_NOTIFY_ENUM_MSG_PADDING 32 -struct ustcomm_notify_enum_msg { - uint32_t session_objd; - char enum_name[LTTNG_UST_ABI_SYM_NAME_LEN]; - uint32_t entries_len; - char padding[USTCOMM_NOTIFY_ENUM_MSG_PADDING]; - /* followed by enum entries */ -} __attribute__((packed)); - -#define USTCOMM_NOTIFY_EVENT_REPLY_PADDING 32 -struct ustcomm_notify_enum_reply { - int32_t ret_code; /* 0: ok, negative: error code */ - uint64_t enum_id; - char padding[USTCOMM_NOTIFY_EVENT_REPLY_PADDING]; -} __attribute__((packed)); - -#define USTCOMM_NOTIFY_CHANNEL_MSG_PADDING 32 -struct ustcomm_notify_channel_msg { - uint32_t session_objd; - uint32_t channel_objd; - uint32_t ctx_fields_len; - char padding[USTCOMM_NOTIFY_CHANNEL_MSG_PADDING]; - /* followed by context fields */ -} __attribute__((packed)); - -#define USTCOMM_NOTIFY_CHANNEL_REPLY_PADDING 32 -struct ustcomm_notify_channel_reply { - int32_t ret_code; /* 0: ok, negative: error code */ - uint32_t chan_id; - uint32_t header_type; /* enum ustctl_channel_header */ - char padding[USTCOMM_NOTIFY_CHANNEL_REPLY_PADDING]; -} __attribute__((packed)); - -/* - * LTTNG_UST_TRACEPOINT_FIELD_LIST reply is followed by a - * struct lttng_ust_field_iter field. - */ - -int ustcomm_create_unix_sock(const char *pathname) - __attribute__((visibility("hidden"))); - -int ustcomm_connect_unix_sock(const char *pathname, - long timeout) - __attribute__((visibility("hidden"))); - -int ustcomm_accept_unix_sock(int sock) - __attribute__((visibility("hidden"))); - -int ustcomm_listen_unix_sock(int sock) - __attribute__((visibility("hidden"))); - -int ustcomm_close_unix_sock(int sock) - __attribute__((visibility("hidden"))); - -ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len) - __attribute__((visibility("hidden"))); - -ssize_t ustcomm_send_unix_sock(int sock, const void *buf, size_t len) - __attribute__((visibility("hidden"))); - -ssize_t ustcomm_send_fds_unix_sock(int sock, int *fds, size_t nb_fd) - __attribute__((visibility("hidden"))); - -ssize_t ustcomm_recv_fds_unix_sock(int sock, int *fds, size_t nb_fd) - __attribute__((visibility("hidden"))); - -const char *ustcomm_get_readable_code(int code) - __attribute__((visibility("hidden"))); - -int ustcomm_send_app_msg(int sock, struct ustcomm_ust_msg *lum) - __attribute__((visibility("hidden"))); - -int ustcomm_recv_app_reply(int sock, struct ustcomm_ust_reply *lur, - uint32_t expected_handle, uint32_t expected_cmd) - __attribute__((visibility("hidden"))); - -int ustcomm_send_app_cmd(int sock, - struct ustcomm_ust_msg *lum, - struct ustcomm_ust_reply *lur) - __attribute__((visibility("hidden"))); - -int ustcomm_recv_fd(int sock) - __attribute__((visibility("hidden"))); - -ssize_t ustcomm_recv_channel_from_sessiond(int sock, - void **chan_data, uint64_t len, int *wakeup_fd) - __attribute__((visibility("hidden"))); - -int ustcomm_recv_stream_from_sessiond(int sock, - uint64_t *memory_map_size, - int *shm_fd, int *wakeup_fd) - __attribute__((visibility("hidden"))); - -ssize_t ustcomm_recv_event_notifier_notif_fd_from_sessiond(int sock, - int *event_notifier_notif_fd) - __attribute__((visibility("hidden"))); - -ssize_t ustcomm_recv_counter_from_sessiond(int sock, - void **counter_data, uint64_t len) - __attribute__((visibility("hidden"))); - -int ustcomm_recv_counter_shm_from_sessiond(int sock, - int *shm_fd) - __attribute__((visibility("hidden"))); - -/* - * Returns 0 on success, negative error value on error. - * Returns -EPIPE or -ECONNRESET if other end has hung up. - */ -int ustcomm_send_reg_msg(int sock, - enum ustctl_socket_type type, - uint32_t bits_per_long, - uint32_t uint8_t_alignment, - uint32_t uint16_t_alignment, - uint32_t uint32_t_alignment, - uint32_t uint64_t_alignment, - uint32_t long_alignment) - __attribute__((visibility("hidden"))); - -/* - * Returns 0 on success, negative error value on error. - * Returns -EPIPE or -ECONNRESET if other end has hung up. - */ -int ustcomm_register_event(int sock, - struct lttng_ust_session *session, - int session_objd, /* session descriptor */ - int channel_objd, /* channel descriptor */ - const char *event_name, /* event name (input) */ - int loglevel, - const char *signature, /* event signature (input) */ - size_t nr_fields, /* fields */ - const struct lttng_ust_event_field **fields, - const char *model_emf_uri, - uint32_t *id) /* event id (output) */ - __attribute__((visibility("hidden"))); - -/* - * Returns 0 on success, negative error value on error. - * Returns -EPIPE or -ECONNRESET if other end has hung up. - */ -int ustcomm_register_enum(int sock, - int session_objd, /* session descriptor */ - const char *enum_name, /* enum name (input) */ - size_t nr_entries, /* entries */ - const struct lttng_ust_enum_entry **entries, - uint64_t *id) /* enum id (output) */ - __attribute__((visibility("hidden"))); - -/* - * Returns 0 on success, negative error value on error. - * Returns -EPIPE or -ECONNRESET if other end has hung up. - */ -int ustcomm_register_channel(int sock, - struct lttng_ust_session *session, - int session_objd, /* session descriptor */ - int channel_objd, /* channel descriptor */ - size_t nr_ctx_fields, - struct lttng_ust_ctx_field *ctx_fields, - uint32_t *chan_id, /* channel id (output) */ - int *header_type) /* header type (output) */ - __attribute__((visibility("hidden"))); - -int ustcomm_setsockopt_rcv_timeout(int sock, unsigned int msec) - __attribute__((visibility("hidden"))); - -int ustcomm_setsockopt_snd_timeout(int sock, unsigned int msec) - __attribute__((visibility("hidden"))); - -#endif /* _LTTNG_UST_COMM_H */ diff --git a/include/ust-compat.h b/include/ust-compat.h deleted file mode 100644 index c148e1be..00000000 --- a/include/ust-compat.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (C) 2010-2011 Mathieu Desnoyers - */ - -#ifndef _LTTNG_UST_COMPAT_H -#define _LTTNG_UST_COMPAT_H - -#include -#include - -#ifdef __FreeBSD__ -#include -#endif - -#ifdef _SC_PAGE_SIZE -#define LTTNG_UST_PAGE_SIZE sysconf(_SC_PAGE_SIZE) -#elif defined(PAGE_SIZE) -#define LTTNG_UST_PAGE_SIZE PAGE_SIZE -#else -#error "Please add page size detection for your OS." -#endif - -#define LTTNG_UST_PAGE_MASK (~(LTTNG_UST_PAGE_SIZE - 1)) - -#define __LTTNG_UST_ALIGN_MASK(v, mask) (((v) + (mask)) & ~(mask)) -#define LTTNG_UST_ALIGN(v, align) __LTTNG_UST_ALIGN_MASK(v, (__typeof__(v)) (align) - 1) -#define LTTNG_UST_PAGE_ALIGN(addr) LTTNG_UST_ALIGN(addr, LTTNG_UST_PAGE_SIZE) - -#endif diff --git a/include/ust-context-provider.h b/include/ust-context-provider.h deleted file mode 100644 index 85beac90..00000000 --- a/include/ust-context-provider.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (C) 2016 Mathieu Desnoyers - * - * The context provider feature is part of the ABI and used by the Java jni - * interface. This header should be moved to the public header directory once - * some test code and documentation is written. - */ - -#ifndef _LTTNG_UST_CONTEXT_PROVIDER_H -#define _LTTNG_UST_CONTEXT_PROVIDER_H - -#include -#include - -#include "ust-dynamic-type.h" - -struct lttng_ust_registered_context_provider; - -/* - * Context value - * - * IMPORTANT: this structure is part of the ABI between the probe and - * UST. Additional selectors may be added in the future, mapping to new - * union fields, which means the overall size of this structure may - * increase. This means this structure should never be nested within a - * public structure interface, nor embedded in an array. - */ - -struct lttng_ust_ctx_value { - enum lttng_ust_dynamic_type sel; /* Type selector */ - union { - int64_t s64; - uint64_t u64; - const char *str; - double d; - } u; -}; - -/* - * Context provider - * - * IMPORTANT: this structure is part of the ABI between the probe and - * UST. Fields need to be only added at the end, never reordered, never - * removed. - * - * The field @struct_size should be used to determine the size of the - * structure. It should be queried before using additional fields added - * at the end of the structure. - */ - -struct lttng_ust_context_provider { - uint32_t struct_size; - - const char *name; - size_t (*get_size)(void *priv, size_t offset); - void (*record)(void *priv, struct lttng_ust_lib_ring_buffer_ctx *ctx, - struct lttng_ust_channel_buffer *chan); - void (*get_value)(void *priv, struct lttng_ust_ctx_value *value); - void *priv; - - /* End of base ABI. Fields below should be used after checking struct_size. */ -}; - -/* - * Returns an opaque pointer on success, which must be passed to - * lttng_ust_context_provider_unregister for unregistration. Returns - * NULL on error. - */ -struct lttng_ust_registered_context_provider *lttng_ust_context_provider_register(struct lttng_ust_context_provider *provider); - -void lttng_ust_context_provider_unregister(struct lttng_ust_registered_context_provider *reg_provider); - -#endif /* _LTTNG_UST_CONTEXT_PROVIDER_H */ diff --git a/include/ust-dlfcn.h b/include/ust-dlfcn.h deleted file mode 100644 index 0681f8f6..00000000 --- a/include/ust-dlfcn.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (C) 2014 Mathieu Desnoyers - * - * dlfcn.h compatibility layer. - */ - -#ifndef _LTTNG_UST_DLFCN_H -#define _LTTNG_UST_DLFCN_H - -#ifdef _DLFCN_H -#error "Please include ust-dlfcn.h before dlfcn.h." -#endif /* _DLFCN_H */ - -#ifdef __GLIBC__ -/* - * glibc declares dlsym() and dlerror() with __attribute__((leaf)) (see - * THROW annotation). Unfortunately, this is not in sync with reality, - * as those functions call the memory allocator. Work-around this glibc - * bug by declaring our own symbols. - * - * There has been a similar issue for dlopen() and dlclose(), as - * constructors and destructors are called from these functions, so they - * are clearly non-leaf. Work-around the issue for those too for older - * glibc where these have not been fixed. - */ -#define dlopen glibc_dlopen_proto_lies_about_leafness -#define dlclose glibc_dlclose_proto_lies_about_leafness -#define dlsym glibc_dlsym_proto_lies_about_leafness -#define dlerror glibc_dlerror_proto_lies_about_leafness -#define dlmopen glibc_dlmopen_proto_lies_about_leafness -#define dlvsym glibc_dlvsym_proto_lies_about_leafness -#include -#undef dlvsym -#undef dlmopen -#undef dlerror -#undef dlsym -#undef dlclose -#undef dlopen - -extern void *dlopen(__const char *__file, int __mode); -extern int dlclose(void *__handle) __nonnull ((1)); -extern void *dlsym(void *__restrict __handle, - __const char *__restrict __name) __nonnull ((2)); -extern char *dlerror(void); -#ifdef __USE_GNU -extern void *dlmopen(Lmid_t __nsid, const char *__file, int __mode); -extern void *dlvsym(void *__restrict __handle, - __const char *__restrict __name, - __const char *__restrict __version); -#endif -#else -#include -#endif /* __GLIBC__ */ - -#endif /* _LTTNG_UST_DLFCN_H */ diff --git a/include/ust-dynamic-type.h b/include/ust-dynamic-type.h deleted file mode 100644 index e63fc4c4..00000000 --- a/include/ust-dynamic-type.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (C) 2016 Mathieu Desnoyers - */ - -#ifndef _LTTNG_UST_DYNAMIC_TYPE_H -#define _LTTNG_UST_DYNAMIC_TYPE_H - -#include - -enum lttng_ust_dynamic_type { - LTTNG_UST_DYNAMIC_TYPE_NONE, - LTTNG_UST_DYNAMIC_TYPE_S8, - LTTNG_UST_DYNAMIC_TYPE_S16, - LTTNG_UST_DYNAMIC_TYPE_S32, - LTTNG_UST_DYNAMIC_TYPE_S64, - LTTNG_UST_DYNAMIC_TYPE_U8, - LTTNG_UST_DYNAMIC_TYPE_U16, - LTTNG_UST_DYNAMIC_TYPE_U32, - LTTNG_UST_DYNAMIC_TYPE_U64, - LTTNG_UST_DYNAMIC_TYPE_FLOAT, - LTTNG_UST_DYNAMIC_TYPE_DOUBLE, - LTTNG_UST_DYNAMIC_TYPE_STRING, - _NR_LTTNG_UST_DYNAMIC_TYPES, -}; - -int lttng_ust_dynamic_type_choices(size_t *nr_choices, - const struct lttng_ust_event_field ***choices) - __attribute__((visibility("hidden"))); - -const struct lttng_ust_event_field *lttng_ust_dynamic_type_field(int64_t value) - __attribute__((visibility("hidden"))); - -const struct lttng_ust_event_field *lttng_ust_dynamic_type_tag_field(void) - __attribute__((visibility("hidden"))); - -#endif /* _LTTNG_UST_DYNAMIC_TYPE_H */ diff --git a/include/ust-elf.h b/include/ust-elf.h deleted file mode 100644 index 29a9426f..00000000 --- a/include/ust-elf.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * - * Copyright (C) 2015 Antoine Busque - */ - -#ifndef _LTTNG_UST_ELF_H -#define _LTTNG_UST_ELF_H - -#include -#include -#include - -struct lttng_ust_elf_ehdr { - uint16_t e_type; - uint16_t e_machine; - uint32_t e_version; - uint64_t e_entry; - uint64_t e_phoff; - uint64_t e_shoff; - uint32_t e_flags; - uint16_t e_ehsize; - uint16_t e_phentsize; - uint16_t e_phnum; - uint16_t e_shentsize; - uint16_t e_shnum; - uint16_t e_shstrndx; -}; - -struct lttng_ust_elf_phdr { - uint32_t p_type; - uint64_t p_offset; - uint64_t p_filesz; - uint64_t p_memsz; - uint64_t p_align; - uint64_t p_vaddr; -}; - -struct lttng_ust_elf_shdr { - uint32_t sh_name; - uint32_t sh_type; - uint64_t sh_flags; - uint64_t sh_addr; - uint64_t sh_offset; - uint64_t sh_size; - uint32_t sh_link; - uint32_t sh_info; - uint64_t sh_addralign; - uint64_t sh_entsize; -}; - -struct lttng_ust_elf_nhdr { - uint32_t n_namesz; - uint32_t n_descsz; - uint32_t n_type; -}; - -struct lttng_ust_elf { - /* Offset in bytes to start of section names string table. */ - off_t section_names_offset; - /* Size in bytes of section names string table. */ - size_t section_names_size; - char *path; - int fd; - struct lttng_ust_elf_ehdr *ehdr; - uint8_t bitness; - uint8_t endianness; -}; - -struct lttng_ust_elf *lttng_ust_elf_create(const char *path); -void lttng_ust_elf_destroy(struct lttng_ust_elf *elf); -uint8_t lttng_ust_elf_is_pic(struct lttng_ust_elf *elf); -int lttng_ust_elf_get_memsz(struct lttng_ust_elf *elf, uint64_t *memsz); -int lttng_ust_elf_get_build_id(struct lttng_ust_elf *elf, uint8_t **build_id, - size_t *length, int *found); -int lttng_ust_elf_get_debug_link(struct lttng_ust_elf *elf, char **filename, - uint32_t *crc, int *found); - -#endif /* _LTTNG_UST_ELF_H */ diff --git a/include/ust-fd.h b/include/ust-fd.h deleted file mode 100644 index ddebaa91..00000000 --- a/include/ust-fd.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (C) 2016 Mathieu Desnoyers - */ - -#ifndef _LTTNG_UST_FD_H -#define _LTTNG_UST_FD_H - -/* - * The fd tracker feature is part of the ABI and used by liblttng-ust-fd. - * However, some test code and documentation needs to be written before it is - * exposed to users with a public header. - */ - -#include - -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); -void lttng_ust_unlock_fd_tracker(void); - -int lttng_ust_safe_close_fd(int fd, int (*close_cb)(int)); -int lttng_ust_safe_fclose_stream(FILE *stream, int (*fclose_cb)(FILE *stream)); -int lttng_ust_safe_closefrom_fd(int lowfd, int (*close_cb)(int)); - -#endif /* _LTTNG_UST_FD_H */ diff --git a/include/ust-helper.h b/include/ust-helper.h deleted file mode 100644 index f1695516..00000000 --- a/include/ust-helper.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (C) 2011 Mathieu Desnoyers - */ - -#ifndef _LTTNG_UST_HELPER_H -#define _LTTNG_UST_HELPER_H - -#include - -#include - -static inline -void *zmalloc(size_t len) - __attribute__((always_inline)); -static inline -void *zmalloc(size_t len) -{ - return calloc(len, 1); -} - -#define max_t(type, x, y) \ - ({ \ - type __max1 = (x); \ - type __max2 = (y); \ - __max1 > __max2 ? __max1: __max2; \ - }) - -#define min_t(type, x, y) \ - ({ \ - type __min1 = (x); \ - type __min2 = (y); \ - __min1 <= __min2 ? __min1: __min2; \ - }) - -#define LTTNG_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) - -/* - * Use of __builtin_return_address(0) sometimes seems to cause stack - * corruption on 32-bit PowerPC. Disable this feature on that - * architecture for now by always using the NULL value for the ip - * context. - */ -#if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64) -#define LTTNG_UST_CALLER_IP() NULL -#else -#define LTTNG_UST_CALLER_IP() __builtin_return_address(0) -#endif - -#endif /* _LTTNG_UST_HELPER_H */ diff --git a/include/ust-share.h b/include/ust-share.h deleted file mode 100644 index e0ee0958..00000000 --- a/include/ust-share.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (C) 2011 Mathieu Desnoyers - */ - -#ifndef _LTTNG_SHARE_H -#define _LTTNG_SHARE_H - -#include -#include - -ssize_t ust_patient_write(int fd, const void *buf, size_t count) - __attribute__((visibility("hidden"))); - -ssize_t ust_patient_writev(int fd, struct iovec *iov, int iovcnt) - __attribute__((visibility("hidden"))); - -ssize_t ust_patient_send(int fd, const void *buf, size_t count, int flags) - __attribute__((visibility("hidden"))); - -#endif /* _LTTNG_SHARE_H */ diff --git a/include/ust-snprintf.h b/include/ust-snprintf.h deleted file mode 100644 index 3f663894..00000000 --- a/include/ust-snprintf.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * - * Copyright (C) 2009 Pierre-Marc Fournier - */ - -#ifndef UST_SNPRINTF -#define UST_SNPRINTF - -#include -#include - -int ust_safe_vsnprintf(char *str, size_t n, const char *fmt, va_list ap) - __attribute__((visibility("hidden"))); - -int ust_safe_snprintf(char *str, size_t n, const char *fmt, ...) - __attribute__((visibility("hidden"))) - __attribute__((format(printf, 3, 4))); - -#endif /* UST_SNPRINTF */ diff --git a/include/ust-tid.h b/include/ust-tid.h deleted file mode 100644 index eae1db9d..00000000 --- a/include/ust-tid.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (C) 2012 Mathieu Desnoyers - * - * gettid compatibility layer. - */ - -#ifndef _LTTNG_UST_TID_H -#define _LTTNG_UST_TID_H - -#ifdef __linux__ -#include -#endif - -#if defined(__NR_gettid) - -#include -static inline pid_t lttng_gettid(void) -{ - return syscall(__NR_gettid); -} - -#else - -#include -#include - -/* Fall-back on getpid for tid if not available. */ -static inline pid_t lttng_gettid(void) -{ - return getpid(); -} - -#endif - -#endif /* _LTTNG_UST_TID_H */ diff --git a/include/usterr-signal-safe.h b/include/usterr-signal-safe.h deleted file mode 100644 index 6123c0b3..00000000 --- a/include/usterr-signal-safe.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (C) 2009 Pierre-Marc Fournier - * Copyright (C) 2011 Mathieu Desnoyers - */ - -#ifndef _USTERR_SIGNAL_SAFE_H -#define _USTERR_SIGNAL_SAFE_H - -#include -#include -#include -#include -#include -#include -#include -#include "ust-tid.h" -#include "ust-snprintf.h" - -enum ust_err_loglevel { - UST_ERR_LOGLEVEL_UNKNOWN = 0, - UST_ERR_LOGLEVEL_NORMAL, - UST_ERR_LOGLEVEL_DEBUG, -}; - -extern volatile enum ust_err_loglevel ust_err_loglevel - __attribute__((visibility("hidden"))); - -void ust_err_init(void) - __attribute__((visibility("hidden"))); - -#ifdef LTTNG_UST_DEBUG -static inline bool ust_err_debug_enabled(void) -{ - return true; -} -#else /* #ifdef LTTNG_UST_DEBUG */ -static inline bool ust_err_debug_enabled(void) -{ - return ust_err_loglevel == UST_ERR_LOGLEVEL_DEBUG; -} -#endif /* #else #ifdef LTTNG_UST_DEBUG */ - -/* - * The default component for error messages. - */ -#ifndef UST_COMPONENT -#define UST_COMPONENT libust -#endif - -/* To stringify the expansion of a define */ -#define UST_XSTR(d) UST_STR(d) -#define UST_STR(s) #s - -#define UST_ERR_MAX_LEN 512 - -/* - * We sometimes print in the tracing path, and tracing can occur in - * signal handlers, so we must use a print method which is signal safe. - */ -/* Can't use dynamic allocation. Limit ourselves to UST_ERR_MAX_LEN chars. */ -/* Add end of string in case of buffer overflow. */ -#define sigsafe_print_err(fmt, args...) \ -do { \ - if (ust_err_debug_enabled()) { \ - char ____buf[UST_ERR_MAX_LEN]; \ - int ____saved_errno; \ - \ - ____saved_errno = errno; /* signal-safety */ \ - ust_safe_snprintf(____buf, sizeof(____buf), fmt, ## args); \ - ____buf[sizeof(____buf) - 1] = 0; \ - ust_patient_write(STDERR_FILENO, ____buf, strlen(____buf)); \ - errno = ____saved_errno; /* signal-safety */ \ - fflush(stderr); \ - } \ -} while (0) - -#define UST_STR_COMPONENT UST_XSTR(UST_COMPONENT) - -#define ERRMSG(fmt, args...) \ - do { \ - sigsafe_print_err(UST_STR_COMPONENT "[%ld/%ld]: " fmt " (in %s() at " __FILE__ ":" UST_XSTR(__LINE__) ")\n", \ - (long) getpid(), \ - (long) lttng_gettid(), \ - ## args, __func__); \ - } while(0) - - -#define DBG(fmt, args...) ERRMSG(fmt, ## args) -#define DBG_raw(fmt, args...) sigsafe_print_err(fmt, ## args) -#define WARN(fmt, args...) ERRMSG("Warning: " fmt, ## args) -#define ERR(fmt, args...) ERRMSG("Error: " fmt, ## args) -#define BUG(fmt, args...) ERRMSG("BUG: " fmt, ## args) - -#if !defined(__GLIBC__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE)) -/* - * Version using XSI strerror_r. - */ -#define PERROR(call, args...) \ - do { \ - if (ust_err_debug_enabled()) { \ - char perror_buf[200] = "Error in strerror_r()"; \ - strerror_r(errno, perror_buf, \ - sizeof(perror_buf)); \ - ERRMSG("Error: " call ": %s", ## args, \ - perror_buf); \ - } \ - } while(0) -#else -/* - * Version using GNU strerror_r, for linux with appropriate defines. - */ -#define PERROR(call, args...) \ - do { \ - if (ust_err_debug_enabled()) { \ - char *perror_buf; \ - char perror_tmp[200]; \ - perror_buf = strerror_r(errno, perror_tmp, \ - sizeof(perror_tmp)); \ - ERRMSG("Error: " call ": %s", ## args, \ - perror_buf); \ - } \ - } while(0) -#endif - -#define BUG_ON(condition) \ - do { \ - if (caa_unlikely(condition)) \ - ERR("condition not respected (BUG) on line %s:%d", __FILE__, __LINE__); \ - } while(0) -#define WARN_ON(condition) \ - do { \ - if (caa_unlikely(condition)) \ - WARN("condition not respected on line %s:%d", __FILE__, __LINE__); \ - } while(0) -#define WARN_ON_ONCE(condition) WARN_ON(condition) - -#endif /* _USTERR_SIGNAL_SAFE_H */ diff --git a/src/Makefile.am b/src/Makefile.am index 87fcdb8f..d9253053 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-2.1-only SUBDIRS = \ + common \ snprintf \ libringbuffer \ liblttng-ust-comm \ diff --git a/src/common/.placeholder b/src/common/.placeholder deleted file mode 100644 index 959eb256..00000000 --- a/src/common/.placeholder +++ /dev/null @@ -1 +0,0 @@ -# Git doesn't support empty folders diff --git a/src/common/Makefile.am b/src/common/Makefile.am new file mode 100644 index 00000000..276c06a5 --- /dev/null +++ b/src/common/Makefile.am @@ -0,0 +1,32 @@ +# SPDX-License-Identifier: LGPL-2.1-only + +### ### +### Global private headers ### +### ### + +noinst_HEADERS = \ + align.h \ + bitfield.h \ + bitmap.h \ + dynamic-type.h \ + elf.h \ + logging.h \ + macros.h \ + patient.h \ + safe-snprintf.h \ + ustcomm.h + +noinst_HEADERS += \ + compat/dlfcn.h \ + compat/tid.h + +# These headers should be moved to the public headers when tested and +# documented. The symbols are still part of the ABI. + +# Used by the Java jni interface. +noinst_HEADERS += \ + ust-context-provider.h + +# Used by liblttng-ust-fd +noinst_HEADERS += \ + ust-fd.h diff --git a/src/common/align.h b/src/common/align.h new file mode 100644 index 00000000..ef04fe4a --- /dev/null +++ b/src/common/align.h @@ -0,0 +1,31 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright (C) 2010-2011 Mathieu Desnoyers + */ + +#ifndef _UST_COMMON_ALIGN_H +#define _UST_COMMON_ALIGN_H + +#include +#include + +#ifdef __FreeBSD__ +#include +#endif + +#ifdef _SC_PAGE_SIZE +#define LTTNG_UST_PAGE_SIZE sysconf(_SC_PAGE_SIZE) +#elif defined(PAGE_SIZE) +#define LTTNG_UST_PAGE_SIZE PAGE_SIZE +#else +#error "Please add page size detection for your OS." +#endif + +#define LTTNG_UST_PAGE_MASK (~(LTTNG_UST_PAGE_SIZE - 1)) + +#define __LTTNG_UST_ALIGN_MASK(v, mask) (((v) + (mask)) & ~(mask)) +#define LTTNG_UST_ALIGN(v, align) __LTTNG_UST_ALIGN_MASK(v, (__typeof__(v)) (align) - 1) +#define LTTNG_UST_PAGE_ALIGN(addr) LTTNG_UST_ALIGN(addr, LTTNG_UST_PAGE_SIZE) + +#endif /* _UST_COMMON_ALIGN_H */ diff --git a/src/common/bitfield.h b/src/common/bitfield.h new file mode 100644 index 00000000..7cb5b32d --- /dev/null +++ b/src/common/bitfield.h @@ -0,0 +1,509 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright (C) 2010-2019 Mathieu Desnoyers + */ + +#ifndef _UST_COMMON_BITFIELD_H +#define _UST_COMMON_BITFIELD_H + +#include /* C99 5.2.4.2 Numerical limits */ +#include /* C99 5.2.4.2 Numerical limits */ +#include /* C99 7.16 bool type */ +#include /* Non-standard BIG_ENDIAN, LITTLE_ENDIAN, BYTE_ORDER */ + +/* + * This header strictly follows the C99 standard, except for use of the + * compiler-specific __typeof__. + */ + +/* + * This bitfield header requires the compiler representation of signed + * integers to be two's complement. + */ +#if (-1 != ~0) +#error "bitfield.h requires the compiler representation of signed integers to be two's complement." +#endif + +#define _bt_is_signed_type(type) ((type) -1 < (type) 1) + +/* + * Produce a build-time error if the condition `cond` is non-zero. + * Evaluates as a size_t expression. + */ +#ifdef __cplusplus +#define _BT_BUILD_ASSERT(cond) ([]{static_assert((cond), "");}, 0) +#else +#define _BT_BUILD_ASSERT(cond) \ + sizeof(struct { int f:(2 * !!(cond) - 1); }) +#endif + +/* + * Cast value `v` to an unsigned integer of the same size as `v`. + */ +#define _bt_cast_value_to_unsigned(v) \ + (sizeof(v) == sizeof(uint8_t) ? (uint8_t) (v) : \ + sizeof(v) == sizeof(uint16_t) ? (uint16_t) (v) : \ + sizeof(v) == sizeof(uint32_t) ? (uint32_t) (v) : \ + sizeof(v) == sizeof(uint64_t) ? (uint64_t) (v) : \ + _BT_BUILD_ASSERT(sizeof(v) <= sizeof(uint64_t))) + +/* + * Cast value `v` to an unsigned integer type of the size of type `type` + * *without* sign-extension. + * + * The unsigned cast ensures that we're not shifting a negative value, + * which is undefined in C. However, this limits the maximum type size + * of `type` to 64-bit. Generate a compile-time error if the size of + * `type` is larger than 64-bit. + */ +#define _bt_cast_value_to_unsigned_type(type, v) \ + (sizeof(type) == sizeof(uint8_t) ? \ + (uint8_t) _bt_cast_value_to_unsigned(v) : \ + sizeof(type) == sizeof(uint16_t) ? \ + (uint16_t) _bt_cast_value_to_unsigned(v) : \ + sizeof(type) == sizeof(uint32_t) ? \ + (uint32_t) _bt_cast_value_to_unsigned(v) : \ + sizeof(type) == sizeof(uint64_t) ? \ + (uint64_t) _bt_cast_value_to_unsigned(v) : \ + _BT_BUILD_ASSERT(sizeof(v) <= sizeof(uint64_t))) + +/* + * _bt_fill_mask evaluates to a "type" integer with all bits set. + */ +#define _bt_fill_mask(type) ((type) ~(type) 0) + +/* + * Left shift a value `v` of `shift` bits. + * + * The type of `v` can be signed or unsigned integer. + * The value of `shift` must be less than the size of `v` (in bits), + * otherwise the behavior is undefined. + * Evaluates to the result of the shift operation. + * + * According to the C99 standard, left shift of a left hand-side signed + * type is undefined if it has a negative value or if the result cannot + * be represented in the result type. This bitfield header discards the + * bits that are left-shifted beyond the result type representation, + * which is the behavior of an unsigned type left shift operation. + * Therefore, always perform left shift on an unsigned type. + * + * This macro should not be used if `shift` can be greater or equal than + * the bitwidth of `v`. See `_bt_safe_lshift`. + */ +#define _bt_lshift(v, shift) \ + ((__typeof__(v)) (_bt_cast_value_to_unsigned(v) << (shift))) + +/* + * Generate a mask of type `type` with the `length` least significant bits + * cleared, and the most significant bits set. + */ +#define _bt_make_mask_complement(type, length) \ + _bt_lshift(_bt_fill_mask(type), length) + +/* + * Generate a mask of type `type` with the `length` least significant bits + * set, and the most significant bits cleared. + */ +#define _bt_make_mask(type, length) \ + ((type) ~_bt_make_mask_complement(type, length)) + +/* + * Right shift a value `v` of `shift` bits. + * + * The type of `v` can be signed or unsigned integer. + * The value of `shift` must be less than the size of `v` (in bits), + * otherwise the behavior is undefined. + * Evaluates to the result of the shift operation. + * + * According to the C99 standard, right shift of a left hand-side signed + * type which has a negative value is implementation defined. This + * bitfield header relies on the right shift implementation carrying the + * sign bit. If the compiler implementation has a different behavior, + * emulate carrying the sign bit. + * + * This macro should not be used if `shift` can be greater or equal than + * the bitwidth of `v`. See `_bt_safe_rshift`. + */ +#if ((-1 >> 1) == -1) +#define _bt_rshift(v, shift) ((v) >> (shift)) +#else +#define _bt_rshift(v, shift) \ + ((__typeof__(v)) ((_bt_cast_value_to_unsigned(v) >> (shift)) | \ + ((v) < 0 ? _bt_make_mask_complement(__typeof__(v), \ + sizeof(v) * CHAR_BIT - (shift)) : 0))) +#endif + +/* + * Right shift a signed or unsigned integer with `shift` value being an + * arbitrary number of bits. `v` is modified by this macro. The shift + * is transformed into a sequence of `_nr_partial_shifts` consecutive + * shift operations, each of a number of bits smaller than the bitwidth + * of `v`, ending with a shift of the number of left over bits. + */ +#define _bt_safe_rshift(v, shift) \ +do { \ + unsigned long _nr_partial_shifts = (shift) / (sizeof(v) * CHAR_BIT - 1); \ + unsigned long _leftover_bits = (shift) % (sizeof(v) * CHAR_BIT - 1); \ + \ + for (; _nr_partial_shifts; _nr_partial_shifts--) \ + (v) = _bt_rshift(v, sizeof(v) * CHAR_BIT - 1); \ + (v) = _bt_rshift(v, _leftover_bits); \ +} while (0) + +/* + * Left shift a signed or unsigned integer with `shift` value being an + * arbitrary number of bits. `v` is modified by this macro. The shift + * is transformed into a sequence of `_nr_partial_shifts` consecutive + * shift operations, each of a number of bits smaller than the bitwidth + * of `v`, ending with a shift of the number of left over bits. + */ +#define _bt_safe_lshift(v, shift) \ +do { \ + unsigned long _nr_partial_shifts = (shift) / (sizeof(v) * CHAR_BIT - 1); \ + unsigned long _leftover_bits = (shift) % (sizeof(v) * CHAR_BIT - 1); \ + \ + for (; _nr_partial_shifts; _nr_partial_shifts--) \ + (v) = _bt_lshift(v, sizeof(v) * CHAR_BIT - 1); \ + (v) = _bt_lshift(v, _leftover_bits); \ +} while (0) + +/* + * bt_bitfield_write - write integer to a bitfield in native endianness + * + * Save integer to the bitfield, which starts at the "start" bit, has "len" + * bits. + * The inside of a bitfield is from high bits to low bits. + * Uses native endianness. + * For unsigned "v", pad MSB with 0 if bitfield is larger than v. + * For signed "v", sign-extend v if bitfield is larger than v. + * + * On little endian, bytes are placed from the less significant to the most + * significant. Also, consecutive bitfields are placed from lower bits to higher + * bits. + * + * On big endian, bytes are places from most significant to less significant. + * Also, consecutive bitfields are placed from higher to lower bits. + */ + +#define _bt_bitfield_write_le(ptr, type, start, length, v) \ +do { \ + __typeof__(v) _v = (v); \ + type *_ptr = (void *) (ptr); \ + unsigned long _start = (start), _length = (length); \ + type _mask, _cmask; \ + unsigned long _ts = sizeof(type) * CHAR_BIT; /* type size */ \ + unsigned long _start_unit, _end_unit, _this_unit; \ + unsigned long _end, _cshift; /* _cshift is "complement shift" */ \ + \ + if (!_length) \ + break; \ + \ + _end = _start + _length; \ + _start_unit = _start / _ts; \ + _end_unit = (_end + (_ts - 1)) / _ts; \ + \ + /* Trim v high bits */ \ + if (_length < sizeof(_v) * CHAR_BIT) \ + _v &= _bt_make_mask(__typeof__(_v), _length); \ + \ + /* We can now append v with a simple "or", shift it piece-wise */ \ + _this_unit = _start_unit; \ + if (_start_unit == _end_unit - 1) { \ + _mask = _bt_make_mask(type, _start % _ts); \ + if (_end % _ts) \ + _mask |= _bt_make_mask_complement(type, _end % _ts); \ + _cmask = _bt_lshift((type) (_v), _start % _ts); \ + _cmask &= ~_mask; \ + _ptr[_this_unit] &= _mask; \ + _ptr[_this_unit] |= _cmask; \ + break; \ + } \ + if (_start % _ts) { \ + _cshift = _start % _ts; \ + _mask = _bt_make_mask(type, _cshift); \ + _cmask = _bt_lshift((type) (_v), _cshift); \ + _cmask &= ~_mask; \ + _ptr[_this_unit] &= _mask; \ + _ptr[_this_unit] |= _cmask; \ + _bt_safe_rshift(_v, _ts - _cshift); \ + _start += _ts - _cshift; \ + _this_unit++; \ + } \ + for (; _this_unit < _end_unit - 1; _this_unit++) { \ + _ptr[_this_unit] = (type) _v; \ + _bt_safe_rshift(_v, _ts); \ + _start += _ts; \ + } \ + if (_end % _ts) { \ + _mask = _bt_make_mask_complement(type, _end % _ts); \ + _cmask = (type) _v; \ + _cmask &= ~_mask; \ + _ptr[_this_unit] &= _mask; \ + _ptr[_this_unit] |= _cmask; \ + } else \ + _ptr[_this_unit] = (type) _v; \ +} while (0) + +#define _bt_bitfield_write_be(ptr, type, start, length, v) \ +do { \ + __typeof__(v) _v = (v); \ + type *_ptr = (void *) (ptr); \ + unsigned long _start = (start), _length = (length); \ + type _mask, _cmask; \ + unsigned long _ts = sizeof(type) * CHAR_BIT; /* type size */ \ + unsigned long _start_unit, _end_unit, _this_unit; \ + unsigned long _end, _cshift; /* _cshift is "complement shift" */ \ + \ + if (!_length) \ + break; \ + \ + _end = _start + _length; \ + _start_unit = _start / _ts; \ + _end_unit = (_end + (_ts - 1)) / _ts; \ + \ + /* Trim v high bits */ \ + if (_length < sizeof(_v) * CHAR_BIT) \ + _v &= _bt_make_mask(__typeof__(_v), _length); \ + \ + /* We can now append v with a simple "or", shift it piece-wise */ \ + _this_unit = _end_unit - 1; \ + if (_start_unit == _end_unit - 1) { \ + _mask = _bt_make_mask(type, (_ts - (_end % _ts)) % _ts); \ + if (_start % _ts) \ + _mask |= _bt_make_mask_complement(type, _ts - (_start % _ts)); \ + _cmask = _bt_lshift((type) (_v), (_ts - (_end % _ts)) % _ts); \ + _cmask &= ~_mask; \ + _ptr[_this_unit] &= _mask; \ + _ptr[_this_unit] |= _cmask; \ + break; \ + } \ + if (_end % _ts) { \ + _cshift = _end % _ts; \ + _mask = _bt_make_mask(type, _ts - _cshift); \ + _cmask = _bt_lshift((type) (_v), _ts - _cshift); \ + _cmask &= ~_mask; \ + _ptr[_this_unit] &= _mask; \ + _ptr[_this_unit] |= _cmask; \ + _bt_safe_rshift(_v, _cshift); \ + _end -= _cshift; \ + _this_unit--; \ + } \ + for (; (long) _this_unit >= (long) _start_unit + 1; _this_unit--) { \ + _ptr[_this_unit] = (type) _v; \ + _bt_safe_rshift(_v, _ts); \ + _end -= _ts; \ + } \ + if (_start % _ts) { \ + _mask = _bt_make_mask_complement(type, _ts - (_start % _ts)); \ + _cmask = (type) _v; \ + _cmask &= ~_mask; \ + _ptr[_this_unit] &= _mask; \ + _ptr[_this_unit] |= _cmask; \ + } else \ + _ptr[_this_unit] = (type) _v; \ +} while (0) + +/* + * bt_bitfield_write - write integer to a bitfield in native endianness + * bt_bitfield_write_le - write integer to a bitfield in little endian + * bt_bitfield_write_be - write integer to a bitfield in big endian + */ + +#if (BYTE_ORDER == LITTLE_ENDIAN) + +#define bt_bitfield_write(ptr, type, start, length, v) \ + _bt_bitfield_write_le(ptr, type, start, length, v) + +#define bt_bitfield_write_le(ptr, type, start, length, v) \ + _bt_bitfield_write_le(ptr, type, start, length, v) + +#define bt_bitfield_write_be(ptr, type, start, length, v) \ + _bt_bitfield_write_be(ptr, unsigned char, start, length, v) + +#elif (BYTE_ORDER == BIG_ENDIAN) + +#define bt_bitfield_write(ptr, type, start, length, v) \ + _bt_bitfield_write_be(ptr, type, start, length, v) + +#define bt_bitfield_write_le(ptr, type, start, length, v) \ + _bt_bitfield_write_le(ptr, unsigned char, start, length, v) + +#define bt_bitfield_write_be(ptr, type, start, length, v) \ + _bt_bitfield_write_be(ptr, type, start, length, v) + +#else /* (BYTE_ORDER == PDP_ENDIAN) */ + +#error "Byte order not supported" + +#endif + +#define _bt_bitfield_read_le(ptr, type, start, length, vptr) \ +do { \ + __typeof__(*(vptr)) *_vptr = (vptr); \ + __typeof__(*_vptr) _v; \ + type *_ptr = (type *) (ptr); \ + unsigned long _start = (start), _length = (length); \ + type _mask, _cmask; \ + unsigned long _ts = sizeof(type) * CHAR_BIT; /* type size */ \ + unsigned long _start_unit, _end_unit, _this_unit; \ + unsigned long _end, _cshift; /* _cshift is "complement shift" */ \ + \ + if (!_length) { \ + *_vptr = 0; \ + break; \ + } \ + \ + _end = _start + _length; \ + _start_unit = _start / _ts; \ + _end_unit = (_end + (_ts - 1)) / _ts; \ + \ + _this_unit = _end_unit - 1; \ + if (_bt_is_signed_type(__typeof__(_v)) \ + && (_ptr[_this_unit] & _bt_lshift((type) 1, (_end % _ts ? _end % _ts : _ts) - 1))) \ + _v = ~(__typeof__(_v)) 0; \ + else \ + _v = 0; \ + if (_start_unit == _end_unit - 1) { \ + _cmask = _ptr[_this_unit]; \ + _cmask = _bt_rshift(_cmask, _start % _ts); \ + if ((_end - _start) % _ts) { \ + _mask = _bt_make_mask(type, _end - _start); \ + _cmask &= _mask; \ + } \ + _bt_safe_lshift(_v, _end - _start); \ + _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \ + *_vptr = _v; \ + break; \ + } \ + if (_end % _ts) { \ + _cshift = _end % _ts; \ + _mask = _bt_make_mask(type, _cshift); \ + _cmask = _ptr[_this_unit]; \ + _cmask &= _mask; \ + _bt_safe_lshift(_v, _cshift); \ + _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \ + _end -= _cshift; \ + _this_unit--; \ + } \ + for (; (long) _this_unit >= (long) _start_unit + 1; _this_unit--) { \ + _bt_safe_lshift(_v, _ts); \ + _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _ptr[_this_unit]); \ + _end -= _ts; \ + } \ + if (_start % _ts) { \ + _mask = _bt_make_mask(type, _ts - (_start % _ts)); \ + _cmask = _ptr[_this_unit]; \ + _cmask = _bt_rshift(_cmask, _start % _ts); \ + _cmask &= _mask; \ + _bt_safe_lshift(_v, _ts - (_start % _ts)); \ + _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \ + } else { \ + _bt_safe_lshift(_v, _ts); \ + _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _ptr[_this_unit]); \ + } \ + *_vptr = _v; \ +} while (0) + +#define _bt_bitfield_read_be(ptr, type, start, length, vptr) \ +do { \ + __typeof__(*(vptr)) *_vptr = (vptr); \ + __typeof__(*_vptr) _v; \ + type *_ptr = (void *) (ptr); \ + unsigned long _start = (start), _length = (length); \ + type _mask, _cmask; \ + unsigned long _ts = sizeof(type) * CHAR_BIT; /* type size */ \ + unsigned long _start_unit, _end_unit, _this_unit; \ + unsigned long _end, _cshift; /* _cshift is "complement shift" */ \ + \ + if (!_length) { \ + *_vptr = 0; \ + break; \ + } \ + \ + _end = _start + _length; \ + _start_unit = _start / _ts; \ + _end_unit = (_end + (_ts - 1)) / _ts; \ + \ + _this_unit = _start_unit; \ + if (_bt_is_signed_type(__typeof__(_v)) \ + && (_ptr[_this_unit] & _bt_lshift((type) 1, _ts - (_start % _ts) - 1))) \ + _v = ~(__typeof__(_v)) 0; \ + else \ + _v = 0; \ + if (_start_unit == _end_unit - 1) { \ + _cmask = _ptr[_this_unit]; \ + _cmask = _bt_rshift(_cmask, (_ts - (_end % _ts)) % _ts); \ + if ((_end - _start) % _ts) { \ + _mask = _bt_make_mask(type, _end - _start); \ + _cmask &= _mask; \ + } \ + _bt_safe_lshift(_v, _end - _start); \ + _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \ + *_vptr = _v; \ + break; \ + } \ + if (_start % _ts) { \ + _cshift = _start % _ts; \ + _mask = _bt_make_mask(type, _ts - _cshift); \ + _cmask = _ptr[_this_unit]; \ + _cmask &= _mask; \ + _bt_safe_lshift(_v, _ts - _cshift); \ + _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \ + _start += _ts - _cshift; \ + _this_unit++; \ + } \ + for (; _this_unit < _end_unit - 1; _this_unit++) { \ + _bt_safe_lshift(_v, _ts); \ + _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _ptr[_this_unit]); \ + _start += _ts; \ + } \ + if (_end % _ts) { \ + _mask = _bt_make_mask(type, _end % _ts); \ + _cmask = _ptr[_this_unit]; \ + _cmask = _bt_rshift(_cmask, _ts - (_end % _ts)); \ + _cmask &= _mask; \ + _bt_safe_lshift(_v, _end % _ts); \ + _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \ + } else { \ + _bt_safe_lshift(_v, _ts); \ + _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _ptr[_this_unit]); \ + } \ + *_vptr = _v; \ +} while (0) + +/* + * bt_bitfield_read - read integer from a bitfield in native endianness + * bt_bitfield_read_le - read integer from a bitfield in little endian + * bt_bitfield_read_be - read integer from a bitfield in big endian + */ + +#if (BYTE_ORDER == LITTLE_ENDIAN) + +#define bt_bitfield_read(ptr, type, start, length, vptr) \ + _bt_bitfield_read_le(ptr, type, start, length, vptr) + +#define bt_bitfield_read_le(ptr, type, start, length, vptr) \ + _bt_bitfield_read_le(ptr, type, start, length, vptr) + +#define bt_bitfield_read_be(ptr, type, start, length, vptr) \ + _bt_bitfield_read_be(ptr, unsigned char, start, length, vptr) + +#elif (BYTE_ORDER == BIG_ENDIAN) + +#define bt_bitfield_read(ptr, type, start, length, vptr) \ + _bt_bitfield_read_be(ptr, type, start, length, vptr) + +#define bt_bitfield_read_le(ptr, type, start, length, vptr) \ + _bt_bitfield_read_le(ptr, unsigned char, start, length, vptr) + +#define bt_bitfield_read_be(ptr, type, start, length, vptr) \ + _bt_bitfield_read_be(ptr, type, start, length, vptr) + +#else /* (BYTE_ORDER == PDP_ENDIAN) */ + +#error "Byte order not supported" + +#endif + +#endif /* _BABELTRACE_BITFIELD_H */ diff --git a/src/common/bitmap.h b/src/common/bitmap.h new file mode 100644 index 00000000..838a6a14 --- /dev/null +++ b/src/common/bitmap.h @@ -0,0 +1,52 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright (C) 2020 Mathieu Desnoyers + * + * LTTng Bitmap API + */ + +#ifndef _UST_COMMON_BITMAP_H +#define _UST_COMMON_BITMAP_H + +#include +#include +#include +#include + +static inline void lttng_bitmap_index(unsigned int index, unsigned int *word, + unsigned int *bit) +{ + *word = index / CAA_BITS_PER_LONG; + *bit = index % CAA_BITS_PER_LONG; +} + +static inline void lttng_bitmap_set_bit(unsigned int index, unsigned long *p) +{ + unsigned int word, bit; + unsigned long val; + + lttng_bitmap_index(index, &word, &bit); + val = 1U << bit; + uatomic_or(p + word, val); +} + +static inline void lttng_bitmap_clear_bit(unsigned int index, unsigned long *p) +{ + unsigned int word, bit; + unsigned long val; + + lttng_bitmap_index(index, &word, &bit); + val = ~(1U << bit); + uatomic_and(p + word, val); +} + +static inline bool lttng_bitmap_test_bit(unsigned int index, unsigned long *p) +{ + unsigned int word, bit; + + lttng_bitmap_index(index, &word, &bit); + return (CMM_LOAD_SHARED(p[word]) >> bit) & 0x1; +} + +#endif /* _UST_COMMON_BITMAP_H */ diff --git a/src/common/compat/dlfcn.h b/src/common/compat/dlfcn.h new file mode 100644 index 00000000..c5861cae --- /dev/null +++ b/src/common/compat/dlfcn.h @@ -0,0 +1,57 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright (C) 2014 Mathieu Desnoyers + * + * dlfcn.h compatibility layer. + */ + +#ifndef _UST_COMMON_COMPAT_DLFCN_H +#define _UST_COMMON_COMPAT_DLFCN_H + +#ifdef _DLFCN_H +#error "Please include compat/dlfcn.h before dlfcn.h." +#endif /* _DLFCN_H */ + +#ifdef __GLIBC__ +/* + * glibc declares dlsym() and dlerror() with __attribute__((leaf)) (see + * THROW annotation). Unfortunately, this is not in sync with reality, + * as those functions call the memory allocator. Work-around this glibc + * bug by declaring our own symbols. + * + * There has been a similar issue for dlopen() and dlclose(), as + * constructors and destructors are called from these functions, so they + * are clearly non-leaf. Work-around the issue for those too for older + * glibc where these have not been fixed. + */ +#define dlopen glibc_dlopen_proto_lies_about_leafness +#define dlclose glibc_dlclose_proto_lies_about_leafness +#define dlsym glibc_dlsym_proto_lies_about_leafness +#define dlerror glibc_dlerror_proto_lies_about_leafness +#define dlmopen glibc_dlmopen_proto_lies_about_leafness +#define dlvsym glibc_dlvsym_proto_lies_about_leafness +#include +#undef dlvsym +#undef dlmopen +#undef dlerror +#undef dlsym +#undef dlclose +#undef dlopen + +extern void *dlopen(__const char *__file, int __mode); +extern int dlclose(void *__handle) __nonnull ((1)); +extern void *dlsym(void *__restrict __handle, + __const char *__restrict __name) __nonnull ((2)); +extern char *dlerror(void); +#ifdef __USE_GNU +extern void *dlmopen(Lmid_t __nsid, const char *__file, int __mode); +extern void *dlvsym(void *__restrict __handle, + __const char *__restrict __name, + __const char *__restrict __version); +#endif +#else +#include +#endif /* __GLIBC__ */ + +#endif /* _UST_COMMON_COMPAT_DLFCN_H */ diff --git a/src/common/compat/tid.h b/src/common/compat/tid.h new file mode 100644 index 00000000..aecae9b1 --- /dev/null +++ b/src/common/compat/tid.h @@ -0,0 +1,37 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright (C) 2012 Mathieu Desnoyers + * + * gettid compatibility layer. + */ + +#ifndef _UST_COMMON_COMPAT_GETTID_H +#define _UST_COMMON_COMPAT_GETTID_H + +#ifdef __linux__ +#include +#endif + +#if defined(__NR_gettid) + +#include +static inline pid_t lttng_gettid(void) +{ + return syscall(__NR_gettid); +} + +#else + +#include +#include + +/* Fall-back on getpid for tid if not available. */ +static inline pid_t lttng_gettid(void) +{ + return getpid(); +} + +#endif + +#endif /* _UST_COMMON_COMPAT_GETTID_H */ diff --git a/src/common/dynamic-type.h b/src/common/dynamic-type.h new file mode 100644 index 00000000..84f55f9a --- /dev/null +++ b/src/common/dynamic-type.h @@ -0,0 +1,38 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright (C) 2016 Mathieu Desnoyers + */ + +#ifndef _UST_COMMON_DYNAMIC_TYPE_H +#define _UST_COMMON_DYNAMIC_TYPE_H + +#include + +enum lttng_ust_dynamic_type { + LTTNG_UST_DYNAMIC_TYPE_NONE, + LTTNG_UST_DYNAMIC_TYPE_S8, + LTTNG_UST_DYNAMIC_TYPE_S16, + LTTNG_UST_DYNAMIC_TYPE_S32, + LTTNG_UST_DYNAMIC_TYPE_S64, + LTTNG_UST_DYNAMIC_TYPE_U8, + LTTNG_UST_DYNAMIC_TYPE_U16, + LTTNG_UST_DYNAMIC_TYPE_U32, + LTTNG_UST_DYNAMIC_TYPE_U64, + LTTNG_UST_DYNAMIC_TYPE_FLOAT, + LTTNG_UST_DYNAMIC_TYPE_DOUBLE, + LTTNG_UST_DYNAMIC_TYPE_STRING, + _NR_LTTNG_UST_DYNAMIC_TYPES, +}; + +int lttng_ust_dynamic_type_choices(size_t *nr_choices, + const struct lttng_ust_event_field ***choices) + __attribute__((visibility("hidden"))); + +const struct lttng_ust_event_field *lttng_ust_dynamic_type_field(int64_t value) + __attribute__((visibility("hidden"))); + +const struct lttng_ust_event_field *lttng_ust_dynamic_type_tag_field(void) + __attribute__((visibility("hidden"))); + +#endif /* _UST_COMMON_DYNAMIC_TYPE_H */ diff --git a/src/common/elf.h b/src/common/elf.h new file mode 100644 index 00000000..ea0351de --- /dev/null +++ b/src/common/elf.h @@ -0,0 +1,79 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * Copyright (C) 2015 Antoine Busque + */ + +#ifndef _UST_COMMON_ELF_H +#define _UST_COMMON_ELF_H + +#include +#include +#include + +struct lttng_ust_elf_ehdr { + uint16_t e_type; + uint16_t e_machine; + uint32_t e_version; + uint64_t e_entry; + uint64_t e_phoff; + uint64_t e_shoff; + uint32_t e_flags; + uint16_t e_ehsize; + uint16_t e_phentsize; + uint16_t e_phnum; + uint16_t e_shentsize; + uint16_t e_shnum; + uint16_t e_shstrndx; +}; + +struct lttng_ust_elf_phdr { + uint32_t p_type; + uint64_t p_offset; + uint64_t p_filesz; + uint64_t p_memsz; + uint64_t p_align; + uint64_t p_vaddr; +}; + +struct lttng_ust_elf_shdr { + uint32_t sh_name; + uint32_t sh_type; + uint64_t sh_flags; + uint64_t sh_addr; + uint64_t sh_offset; + uint64_t sh_size; + uint32_t sh_link; + uint32_t sh_info; + uint64_t sh_addralign; + uint64_t sh_entsize; +}; + +struct lttng_ust_elf_nhdr { + uint32_t n_namesz; + uint32_t n_descsz; + uint32_t n_type; +}; + +struct lttng_ust_elf { + /* Offset in bytes to start of section names string table. */ + off_t section_names_offset; + /* Size in bytes of section names string table. */ + size_t section_names_size; + char *path; + int fd; + struct lttng_ust_elf_ehdr *ehdr; + uint8_t bitness; + uint8_t endianness; +}; + +struct lttng_ust_elf *lttng_ust_elf_create(const char *path); +void lttng_ust_elf_destroy(struct lttng_ust_elf *elf); +uint8_t lttng_ust_elf_is_pic(struct lttng_ust_elf *elf); +int lttng_ust_elf_get_memsz(struct lttng_ust_elf *elf, uint64_t *memsz); +int lttng_ust_elf_get_build_id(struct lttng_ust_elf *elf, uint8_t **build_id, + size_t *length, int *found); +int lttng_ust_elf_get_debug_link(struct lttng_ust_elf *elf, char **filename, + uint32_t *crc, int *found); + +#endif /* _UST_COMMON_ELF_H */ diff --git a/src/common/logging.h b/src/common/logging.h new file mode 100644 index 00000000..4001c885 --- /dev/null +++ b/src/common/logging.h @@ -0,0 +1,139 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2009 Pierre-Marc Fournier + * Copyright (C) 2011 Mathieu Desnoyers + */ + +#ifndef _USTERR_SIGNAL_SAFE_H +#define _USTERR_SIGNAL_SAFE_H + +#include +#include +#include +#include +#include +#include +#include "common/patient.h" +#include "common/compat/tid.h" +#include "common/safe-snprintf.h" + +enum ust_err_loglevel { + UST_ERR_LOGLEVEL_UNKNOWN = 0, + UST_ERR_LOGLEVEL_NORMAL, + UST_ERR_LOGLEVEL_DEBUG, +}; + +extern volatile enum ust_err_loglevel ust_err_loglevel + __attribute__((visibility("hidden"))); + +void ust_err_init(void) + __attribute__((visibility("hidden"))); + +#ifdef LTTNG_UST_DEBUG +static inline bool ust_err_debug_enabled(void) +{ + return true; +} +#else /* #ifdef LTTNG_UST_DEBUG */ +static inline bool ust_err_debug_enabled(void) +{ + return ust_err_loglevel == UST_ERR_LOGLEVEL_DEBUG; +} +#endif /* #else #ifdef LTTNG_UST_DEBUG */ + +/* + * The default component for error messages. + */ +#ifndef UST_COMPONENT +#define UST_COMPONENT libust +#endif + +/* To stringify the expansion of a define */ +#define UST_XSTR(d) UST_STR(d) +#define UST_STR(s) #s + +#define UST_ERR_MAX_LEN 512 + +/* + * We sometimes print in the tracing path, and tracing can occur in + * signal handlers, so we must use a print method which is signal safe. + */ +/* Can't use dynamic allocation. Limit ourselves to UST_ERR_MAX_LEN chars. */ +/* Add end of string in case of buffer overflow. */ +#define sigsafe_print_err(fmt, args...) \ +do { \ + if (ust_err_debug_enabled()) { \ + char ____buf[UST_ERR_MAX_LEN]; \ + int ____saved_errno; \ + \ + ____saved_errno = errno; /* signal-safety */ \ + ust_safe_snprintf(____buf, sizeof(____buf), fmt, ## args); \ + ____buf[sizeof(____buf) - 1] = 0; \ + ust_patient_write(STDERR_FILENO, ____buf, strlen(____buf)); \ + errno = ____saved_errno; /* signal-safety */ \ + fflush(stderr); \ + } \ +} while (0) + +#define UST_STR_COMPONENT UST_XSTR(UST_COMPONENT) + +#define ERRMSG(fmt, args...) \ + do { \ + sigsafe_print_err(UST_STR_COMPONENT "[%ld/%ld]: " fmt " (in %s() at " __FILE__ ":" UST_XSTR(__LINE__) ")\n", \ + (long) getpid(), \ + (long) lttng_gettid(), \ + ## args, __func__); \ + } while(0) + + +#define DBG(fmt, args...) ERRMSG(fmt, ## args) +#define DBG_raw(fmt, args...) sigsafe_print_err(fmt, ## args) +#define WARN(fmt, args...) ERRMSG("Warning: " fmt, ## args) +#define ERR(fmt, args...) ERRMSG("Error: " fmt, ## args) +#define BUG(fmt, args...) ERRMSG("BUG: " fmt, ## args) + +#if !defined(__GLIBC__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE)) +/* + * Version using XSI strerror_r. + */ +#define PERROR(call, args...) \ + do { \ + if (ust_err_debug_enabled()) { \ + char perror_buf[200] = "Error in strerror_r()"; \ + strerror_r(errno, perror_buf, \ + sizeof(perror_buf)); \ + ERRMSG("Error: " call ": %s", ## args, \ + perror_buf); \ + } \ + } while(0) +#else +/* + * Version using GNU strerror_r, for linux with appropriate defines. + */ +#define PERROR(call, args...) \ + do { \ + if (ust_err_debug_enabled()) { \ + char *perror_buf; \ + char perror_tmp[200]; \ + perror_buf = strerror_r(errno, perror_tmp, \ + sizeof(perror_tmp)); \ + ERRMSG("Error: " call ": %s", ## args, \ + perror_buf); \ + } \ + } while(0) +#endif + +#define BUG_ON(condition) \ + do { \ + if (caa_unlikely(condition)) \ + ERR("condition not respected (BUG) on line %s:%d", __FILE__, __LINE__); \ + } while(0) +#define WARN_ON(condition) \ + do { \ + if (caa_unlikely(condition)) \ + WARN("condition not respected on line %s:%d", __FILE__, __LINE__); \ + } while(0) +#define WARN_ON_ONCE(condition) WARN_ON(condition) + +#endif /* _USTERR_SIGNAL_SAFE_H */ diff --git a/src/common/macros.h b/src/common/macros.h new file mode 100644 index 00000000..308a1dfc --- /dev/null +++ b/src/common/macros.h @@ -0,0 +1,54 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2011 Mathieu Desnoyers + */ + +#ifndef _UST_COMMON_MACROS_H +#define _UST_COMMON_MACROS_H + +#include + +#include + +/* + * Memory allocation zeroed + */ +static inline +void *zmalloc(size_t len) + __attribute__((always_inline)); +static inline +void *zmalloc(size_t len) +{ + return calloc(len, 1); +} + +#define max_t(type, x, y) \ + ({ \ + type __max1 = (x); \ + type __max2 = (y); \ + __max1 > __max2 ? __max1: __max2; \ + }) + +#define min_t(type, x, y) \ + ({ \ + type __min1 = (x); \ + type __min2 = (y); \ + __min1 <= __min2 ? __min1: __min2; \ + }) + +#define LTTNG_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +/* + * Use of __builtin_return_address(0) sometimes seems to cause stack + * corruption on 32-bit PowerPC. Disable this feature on that + * architecture for now by always using the NULL value for the ip + * context. + */ +#if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64) +#define LTTNG_UST_CALLER_IP() NULL +#else +#define LTTNG_UST_CALLER_IP() __builtin_return_address(0) +#endif + +#endif /* _UST_COMMON_MACROS_H */ diff --git a/src/common/patient.h b/src/common/patient.h new file mode 100644 index 00000000..98b07b12 --- /dev/null +++ b/src/common/patient.h @@ -0,0 +1,22 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright (C) 2011 Mathieu Desnoyers + */ + +#ifndef _UST_COMMON_PATIENT_H +#define _UST_COMMON_PATIENT_H + +#include +#include + +ssize_t ust_patient_write(int fd, const void *buf, size_t count) + __attribute__((visibility("hidden"))); + +ssize_t ust_patient_writev(int fd, struct iovec *iov, int iovcnt) + __attribute__((visibility("hidden"))); + +ssize_t ust_patient_send(int fd, const void *buf, size_t count, int flags) + __attribute__((visibility("hidden"))); + +#endif /* _UST_COMMON_PATIENT_H */ diff --git a/src/common/safe-snprintf.h b/src/common/safe-snprintf.h new file mode 100644 index 00000000..3cc4f67e --- /dev/null +++ b/src/common/safe-snprintf.h @@ -0,0 +1,20 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * Copyright (C) 2009 Pierre-Marc Fournier + */ + +#ifndef _UST_COMMON_SAFE_SNPRINTF_H +#define _UST_COMMON_SAFE_SNPRINTF_H + +#include +#include + +int ust_safe_vsnprintf(char *str, size_t n, const char *fmt, va_list ap) + __attribute__((visibility("hidden"))); + +int ust_safe_snprintf(char *str, size_t n, const char *fmt, ...) + __attribute__((visibility("hidden"))) + __attribute__((format(printf, 3, 4))); + +#endif /* _UST_COMMON_SAFE_SNPRINTF_H */ diff --git a/src/common/ust-context-provider.h b/src/common/ust-context-provider.h new file mode 100644 index 00000000..57dda8f3 --- /dev/null +++ b/src/common/ust-context-provider.h @@ -0,0 +1,75 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright (C) 2016 Mathieu Desnoyers + * + * The context provider feature is part of the ABI and used by the Java jni + * interface. This header should be moved to the public header directory once + * some test code and documentation is written. + */ + +#ifndef _LTTNG_UST_CONTEXT_PROVIDER_H +#define _LTTNG_UST_CONTEXT_PROVIDER_H + +#include +#include + +#include "common/dynamic-type.h" + +struct lttng_ust_registered_context_provider; + +/* + * Context value + * + * IMPORTANT: this structure is part of the ABI between the probe and + * UST. Additional selectors may be added in the future, mapping to new + * union fields, which means the overall size of this structure may + * increase. This means this structure should never be nested within a + * public structure interface, nor embedded in an array. + */ + +struct lttng_ust_ctx_value { + enum lttng_ust_dynamic_type sel; /* Type selector */ + union { + int64_t s64; + uint64_t u64; + const char *str; + double d; + } u; +}; + +/* + * Context provider + * + * IMPORTANT: this structure is part of the ABI between the probe and + * UST. Fields need to be only added at the end, never reordered, never + * removed. + * + * The field @struct_size should be used to determine the size of the + * structure. It should be queried before using additional fields added + * at the end of the structure. + */ + +struct lttng_ust_context_provider { + uint32_t struct_size; + + const char *name; + size_t (*get_size)(void *priv, size_t offset); + void (*record)(void *priv, struct lttng_ust_lib_ring_buffer_ctx *ctx, + struct lttng_ust_channel_buffer *chan); + void (*get_value)(void *priv, struct lttng_ust_ctx_value *value); + void *priv; + + /* End of base ABI. Fields below should be used after checking struct_size. */ +}; + +/* + * Returns an opaque pointer on success, which must be passed to + * lttng_ust_context_provider_unregister for unregistration. Returns + * NULL on error. + */ +struct lttng_ust_registered_context_provider *lttng_ust_context_provider_register(struct lttng_ust_context_provider *provider); + +void lttng_ust_context_provider_unregister(struct lttng_ust_registered_context_provider *reg_provider); + +#endif /* _LTTNG_UST_CONTEXT_PROVIDER_H */ diff --git a/src/common/ust-fd.h b/src/common/ust-fd.h new file mode 100644 index 00000000..ddebaa91 --- /dev/null +++ b/src/common/ust-fd.h @@ -0,0 +1,28 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2016 Mathieu Desnoyers + */ + +#ifndef _LTTNG_UST_FD_H +#define _LTTNG_UST_FD_H + +/* + * The fd tracker feature is part of the ABI and used by liblttng-ust-fd. + * However, some test code and documentation needs to be written before it is + * exposed to users with a public header. + */ + +#include + +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); +void lttng_ust_unlock_fd_tracker(void); + +int lttng_ust_safe_close_fd(int fd, int (*close_cb)(int)); +int lttng_ust_safe_fclose_stream(FILE *stream, int (*fclose_cb)(FILE *stream)); +int lttng_ust_safe_closefrom_fd(int lowfd, int (*close_cb)(int)); + +#endif /* _LTTNG_UST_FD_H */ diff --git a/src/common/ustcomm.h b/src/common/ustcomm.h new file mode 100644 index 00000000..81ce885d --- /dev/null +++ b/src/common/ustcomm.h @@ -0,0 +1,327 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2011 David Goulet + * Copyright (C) 2011 Julien Desfossez + * Copyright (C) 2011 Mathieu Desnoyers + */ + +/* + * This header is meant for liblttng and libust internal use ONLY. + * These declarations should NOT be considered stable API. + */ + +#ifndef _UST_COMMON_USTCOMM_H +#define _UST_COMMON_USTCOMM_H + +#include +#include +#include +#include +#include +#include +#include + +/* + * Default timeout the application waits for the sessiond to send its + * "register done" command. Can be overridden with the environment + * variable "LTTNG_UST_REGISTER_TIMEOUT". Note that if the sessiond is not + * found, the application proceeds directly without any delay. + */ +#define LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS 3000 + +#define LTTNG_DEFAULT_RUNDIR LTTNG_SYSTEM_RUNDIR +#define LTTNG_DEFAULT_HOME_RUNDIR ".lttng" + +/* Queue size of listen(2) */ +#define LTTNG_UST_COMM_MAX_LISTEN 10 +#define LTTNG_UST_COMM_REG_MSG_PADDING 64 + +struct lttng_ust_event_field; +struct lttng_ust_ctx_field; +struct lttng_ust_enum_entry; +struct lttng_integer_type; +struct lttng_ust_session; + +struct ustctl_reg_msg { + uint32_t magic; + uint32_t major; + uint32_t minor; + uint32_t pid; + uint32_t ppid; + uint32_t uid; + uint32_t gid; + uint32_t bits_per_long; + uint32_t uint8_t_alignment; + uint32_t uint16_t_alignment; + uint32_t uint32_t_alignment; + uint32_t uint64_t_alignment; + uint32_t long_alignment; + uint32_t socket_type; /* enum ustctl_socket_type */ + char name[LTTNG_UST_ABI_PROCNAME_LEN]; /* process name */ + char padding[LTTNG_UST_COMM_REG_MSG_PADDING]; +} __attribute__((packed)); + +/* + * Data structure for the commands sent from sessiond to UST. + */ +#define USTCOMM_MSG_PADDING1 32 +#define USTCOMM_MSG_PADDING2 32 +struct ustcomm_ust_msg { + uint32_t handle; + uint32_t cmd; + char padding[USTCOMM_MSG_PADDING1]; + union { + struct lttng_ust_abi_channel channel; + struct lttng_ust_abi_stream stream; + struct lttng_ust_abi_event event; + struct lttng_ust_abi_context context; + struct lttng_ust_abi_tracer_version version; + struct lttng_ust_abi_tracepoint_iter tracepoint; + struct { + uint32_t data_size; /* following filter data */ + uint32_t reloc_offset; + uint64_t seqnum; + } __attribute__((packed)) filter; + struct { + uint32_t count; /* how many names follow */ + } __attribute__((packed)) exclusion; + struct { + uint32_t data_size; /* following capture data */ + uint32_t reloc_offset; + uint64_t seqnum; + } __attribute__((packed)) capture; + struct lttng_ust_abi_counter counter; + struct lttng_ust_abi_counter_global counter_global; + struct lttng_ust_abi_counter_cpu counter_cpu; + /* + * For lttng_ust_abi_EVENT_NOTIFIER_CREATE, a struct + * lttng_ust_abi_event_notifier implicitly follows struct + * ustcomm_ust_msg. + */ + struct { + /* Length of struct lttng_ust_abi_event_notifier */ + uint32_t len; + } event_notifier; + char padding[USTCOMM_MSG_PADDING2]; + } u; +} __attribute__((packed)); + +/* + * Data structure for the response from UST to the session daemon. + * cmd_type is sent back in the reply for validation. + */ +#define USTCOMM_REPLY_PADDING1 32 +#define USTCOMM_REPLY_PADDING2 32 +struct ustcomm_ust_reply { + uint32_t handle; + uint32_t cmd; + int32_t ret_code; /* enum ustcomm_return_code */ + uint32_t ret_val; /* return value */ + char padding[USTCOMM_REPLY_PADDING1]; + union { + struct { + uint64_t memory_map_size; + } __attribute__((packed)) channel; + struct { + uint64_t memory_map_size; + } __attribute__((packed)) stream; + struct lttng_ust_abi_tracer_version version; + struct lttng_ust_abi_tracepoint_iter tracepoint; + char padding[USTCOMM_REPLY_PADDING2]; + } u; +} __attribute__((packed)); + +struct ustcomm_notify_hdr { + uint32_t notify_cmd; +} __attribute__((packed)); + +#define USTCOMM_NOTIFY_EVENT_MSG_PADDING 32 +struct ustcomm_notify_event_msg { + uint32_t session_objd; + uint32_t channel_objd; + char event_name[LTTNG_UST_ABI_SYM_NAME_LEN]; + int32_t loglevel; + uint32_t signature_len; + uint32_t fields_len; + uint32_t model_emf_uri_len; + char padding[USTCOMM_NOTIFY_EVENT_MSG_PADDING]; + /* followed by signature, fields, and model_emf_uri */ +} __attribute__((packed)); + +#define USTCOMM_NOTIFY_EVENT_REPLY_PADDING 32 +struct ustcomm_notify_event_reply { + int32_t ret_code; /* 0: ok, negative: error code */ + uint32_t event_id; + char padding[USTCOMM_NOTIFY_EVENT_REPLY_PADDING]; +} __attribute__((packed)); + +#define USTCOMM_NOTIFY_ENUM_MSG_PADDING 32 +struct ustcomm_notify_enum_msg { + uint32_t session_objd; + char enum_name[LTTNG_UST_ABI_SYM_NAME_LEN]; + uint32_t entries_len; + char padding[USTCOMM_NOTIFY_ENUM_MSG_PADDING]; + /* followed by enum entries */ +} __attribute__((packed)); + +#define USTCOMM_NOTIFY_EVENT_REPLY_PADDING 32 +struct ustcomm_notify_enum_reply { + int32_t ret_code; /* 0: ok, negative: error code */ + uint64_t enum_id; + char padding[USTCOMM_NOTIFY_EVENT_REPLY_PADDING]; +} __attribute__((packed)); + +#define USTCOMM_NOTIFY_CHANNEL_MSG_PADDING 32 +struct ustcomm_notify_channel_msg { + uint32_t session_objd; + uint32_t channel_objd; + uint32_t ctx_fields_len; + char padding[USTCOMM_NOTIFY_CHANNEL_MSG_PADDING]; + /* followed by context fields */ +} __attribute__((packed)); + +#define USTCOMM_NOTIFY_CHANNEL_REPLY_PADDING 32 +struct ustcomm_notify_channel_reply { + int32_t ret_code; /* 0: ok, negative: error code */ + uint32_t chan_id; + uint32_t header_type; /* enum ustctl_channel_header */ + char padding[USTCOMM_NOTIFY_CHANNEL_REPLY_PADDING]; +} __attribute__((packed)); + +/* + * LTTNG_UST_TRACEPOINT_FIELD_LIST reply is followed by a + * struct lttng_ust_field_iter field. + */ + +int ustcomm_create_unix_sock(const char *pathname) + __attribute__((visibility("hidden"))); + +int ustcomm_connect_unix_sock(const char *pathname, + long timeout) + __attribute__((visibility("hidden"))); + +int ustcomm_accept_unix_sock(int sock) + __attribute__((visibility("hidden"))); + +int ustcomm_listen_unix_sock(int sock) + __attribute__((visibility("hidden"))); + +int ustcomm_close_unix_sock(int sock) + __attribute__((visibility("hidden"))); + +ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len) + __attribute__((visibility("hidden"))); + +ssize_t ustcomm_send_unix_sock(int sock, const void *buf, size_t len) + __attribute__((visibility("hidden"))); + +ssize_t ustcomm_send_fds_unix_sock(int sock, int *fds, size_t nb_fd) + __attribute__((visibility("hidden"))); + +ssize_t ustcomm_recv_fds_unix_sock(int sock, int *fds, size_t nb_fd) + __attribute__((visibility("hidden"))); + +const char *ustcomm_get_readable_code(int code) + __attribute__((visibility("hidden"))); + +int ustcomm_send_app_msg(int sock, struct ustcomm_ust_msg *lum) + __attribute__((visibility("hidden"))); + +int ustcomm_recv_app_reply(int sock, struct ustcomm_ust_reply *lur, + uint32_t expected_handle, uint32_t expected_cmd) + __attribute__((visibility("hidden"))); + +int ustcomm_send_app_cmd(int sock, + struct ustcomm_ust_msg *lum, + struct ustcomm_ust_reply *lur) + __attribute__((visibility("hidden"))); + +int ustcomm_recv_fd(int sock) + __attribute__((visibility("hidden"))); + +ssize_t ustcomm_recv_channel_from_sessiond(int sock, + void **chan_data, uint64_t len, int *wakeup_fd) + __attribute__((visibility("hidden"))); + +int ustcomm_recv_stream_from_sessiond(int sock, + uint64_t *memory_map_size, + int *shm_fd, int *wakeup_fd) + __attribute__((visibility("hidden"))); + +ssize_t ustcomm_recv_event_notifier_notif_fd_from_sessiond(int sock, + int *event_notifier_notif_fd) + __attribute__((visibility("hidden"))); + +ssize_t ustcomm_recv_counter_from_sessiond(int sock, + void **counter_data, uint64_t len) + __attribute__((visibility("hidden"))); + +int ustcomm_recv_counter_shm_from_sessiond(int sock, + int *shm_fd) + __attribute__((visibility("hidden"))); + +/* + * Returns 0 on success, negative error value on error. + * Returns -EPIPE or -ECONNRESET if other end has hung up. + */ +int ustcomm_send_reg_msg(int sock, + enum ustctl_socket_type type, + uint32_t bits_per_long, + uint32_t uint8_t_alignment, + uint32_t uint16_t_alignment, + uint32_t uint32_t_alignment, + uint32_t uint64_t_alignment, + uint32_t long_alignment) + __attribute__((visibility("hidden"))); + +/* + * Returns 0 on success, negative error value on error. + * Returns -EPIPE or -ECONNRESET if other end has hung up. + */ +int ustcomm_register_event(int sock, + struct lttng_ust_session *session, + int session_objd, /* session descriptor */ + int channel_objd, /* channel descriptor */ + const char *event_name, /* event name (input) */ + int loglevel, + const char *signature, /* event signature (input) */ + size_t nr_fields, /* fields */ + const struct lttng_ust_event_field **fields, + const char *model_emf_uri, + uint32_t *id) /* event id (output) */ + __attribute__((visibility("hidden"))); + +/* + * Returns 0 on success, negative error value on error. + * Returns -EPIPE or -ECONNRESET if other end has hung up. + */ +int ustcomm_register_enum(int sock, + int session_objd, /* session descriptor */ + const char *enum_name, /* enum name (input) */ + size_t nr_entries, /* entries */ + const struct lttng_ust_enum_entry **entries, + uint64_t *id) /* enum id (output) */ + __attribute__((visibility("hidden"))); + +/* + * Returns 0 on success, negative error value on error. + * Returns -EPIPE or -ECONNRESET if other end has hung up. + */ +int ustcomm_register_channel(int sock, + struct lttng_ust_session *session, + int session_objd, /* session descriptor */ + int channel_objd, /* channel descriptor */ + size_t nr_ctx_fields, + struct lttng_ust_ctx_field *ctx_fields, + uint32_t *chan_id, /* channel id (output) */ + int *header_type) /* header type (output) */ + __attribute__((visibility("hidden"))); + +int ustcomm_setsockopt_rcv_timeout(int sock, unsigned int msec) + __attribute__((visibility("hidden"))); + +int ustcomm_setsockopt_snd_timeout(int sock, unsigned int msec) + __attribute__((visibility("hidden"))); + +#endif /* _UST_COMMON_USTCOMM_H */ diff --git a/src/libcounter/counter-api.h b/src/libcounter/counter-api.h index 540bd11f..f140325d 100644 --- a/src/libcounter/counter-api.h +++ b/src/libcounter/counter-api.h @@ -15,7 +15,7 @@ #include "counter-internal.h" #include #include -#include "ust-bitmap.h" +#include "common/bitmap.h" #include "../libringbuffer/getcpu.h" /* diff --git a/src/libcounter/counter.c b/src/libcounter/counter.c index a825ac95..0393bed3 100644 --- a/src/libcounter/counter.c +++ b/src/libcounter/counter.c @@ -11,12 +11,13 @@ #include #include #include -#include + +#include "common/macros.h" +#include "common/align.h" +#include "common/bitmap.h" + #include "smp.h" #include "shm.h" -#include "ust-compat.h" - -#include "ust-bitmap.h" static size_t lttng_counter_get_dimension_nr_elements(struct lib_counter_dimension *dimension) { diff --git a/src/libcounter/shm.c b/src/libcounter/shm.c index b8a07e13..c1d6718a 100644 --- a/src/libcounter/shm.c +++ b/src/libcounter/shm.c @@ -27,8 +27,8 @@ #include -#include -#include +#include "common/macros.h" +#include "common/ust-fd.h" #include "../libringbuffer/mmap.h" /* diff --git a/src/libcounter/shm.h b/src/libcounter/shm.h index 8ec251d7..689edb0a 100644 --- a/src/libcounter/shm.h +++ b/src/libcounter/shm.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include "common/logging.h" #include #include "shm_types.h" diff --git a/src/liblttng-ust-comm/lttng-ust-comm.c b/src/liblttng-ust-comm/lttng-ust-comm.c index d5d193d7..2d445cba 100644 --- a/src/liblttng-ust-comm/lttng-ust-comm.c +++ b/src/liblttng-ust-comm/lttng-ust-comm.c @@ -20,12 +20,12 @@ #include #include -#include -#include -#include +#include "common/ustcomm.h" +#include "common/ust-fd.h" +#include "common/macros.h" #include -#include -#include +#include "common/dynamic-type.h" +#include "common/logging.h" #include "../liblttng-ust/ust-events-internal.h" #include "../liblttng-ust/compat.h" diff --git a/src/liblttng-ust-comm/lttng-ust-fd-tracker.c b/src/liblttng-ust-comm/lttng-ust-fd-tracker.c index 18456e08..3879a90d 100644 --- a/src/liblttng-ust-comm/lttng-ust-fd-tracker.c +++ b/src/liblttng-ust-comm/lttng-ust-fd-tracker.c @@ -25,10 +25,10 @@ #include #include -#include -#include +#include "common/ust-fd.h" +#include "common/macros.h" #include -#include +#include "common/logging.h" #include "../liblttng-ust/compat.h" #include "../liblttng-ust/lttng-tracer-core.h" diff --git a/src/liblttng-ust-ctl/ustctl.c b/src/liblttng-ust-ctl/ustctl.c index a12e9dd3..a4e9d0e9 100644 --- a/src/liblttng-ust-ctl/ustctl.c +++ b/src/liblttng-ust-ctl/ustctl.c @@ -17,10 +17,10 @@ #include #include -#include -#include -#include -#include "ust-compat.h" +#include "common/logging.h" +#include "common/ustcomm.h" +#include "common/macros.h" +#include "common/align.h" #include "../libringbuffer/backend.h" #include "../libringbuffer/frontend.h" diff --git a/src/liblttng-ust-dl/lttng-ust-dl.c b/src/liblttng-ust-dl/lttng-ust-dl.c index 1394ce19..6444e3fb 100644 --- a/src/liblttng-ust-dl/lttng-ust-dl.c +++ b/src/liblttng-ust-dl/lttng-ust-dl.c @@ -7,17 +7,20 @@ */ #define _LGPL_SOURCE + +/* Has to be included first to override dlfcn.h */ +#include + #include #include #include #include #include -#include -#include +#include "common/elf.h" #include -#include -#include "usterr-signal-safe.h" +#include "common/macros.h" +#include "common/logging.h" #include "../liblttng-ust/ust-events-internal.h" diff --git a/src/liblttng-ust-fd/lttng-ust-fd.c b/src/liblttng-ust-fd/lttng-ust-fd.c index 14a23d9f..5efc0acd 100644 --- a/src/liblttng-ust-fd/lttng-ust-fd.c +++ b/src/liblttng-ust-fd/lttng-ust-fd.c @@ -9,10 +9,10 @@ #include #include #include -#include +#include "common/ust-fd.h" #include -#include +#include "common/macros.h" static int (*__lttng_ust_fd_plibc_close)(int fd); static int (*__lttng_ust_fd_plibc_fclose)(FILE *stream); diff --git a/src/liblttng-ust-fork/ustfork.c b/src/liblttng-ust-fork/ustfork.c index b10f24d2..3eb62d2a 100644 --- a/src/liblttng-ust-fork/ustfork.c +++ b/src/liblttng-ust-fork/ustfork.c @@ -5,7 +5,9 @@ * Copyright (C) 2011-2012 Mathieu Desnoyers */ -#include +/* Has to be included first to override dlfcn.h */ +#include + #include #include #include diff --git a/src/liblttng-ust-java-agent/jni/common/lttng_ust_context.c b/src/liblttng-ust-java-agent/jni/common/lttng_ust_context.c index 7ba4403a..8570b211 100644 --- a/src/liblttng-ust-java-agent/jni/common/lttng_ust_context.c +++ b/src/liblttng-ust-java-agent/jni/common/lttng_ust_context.c @@ -12,9 +12,9 @@ #include #include #include -#include +#include -#include "ust-helper.h" +#include "common/macros.h" #include "lttng_ust_context.h" enum lttng_ust_jni_type { diff --git a/src/liblttng-ust-libc-wrapper/lttng-ust-malloc.c b/src/liblttng-ust-libc-wrapper/lttng-ust-malloc.c index e1ff8e80..a93c7c1a 100644 --- a/src/liblttng-ust-libc-wrapper/lttng-ust-malloc.c +++ b/src/liblttng-ust-libc-wrapper/lttng-ust-malloc.c @@ -10,7 +10,10 @@ * circular dependency loop between this malloc wrapper, liburcu and * libc. */ -#include + +/* Has to be included first to override dlfcn.h */ +#include + #include #include #include @@ -24,8 +27,8 @@ #include -#include -#include "ust-compat.h" +#include "common/macros.h" +#include "common/align.h" #define TRACEPOINT_DEFINE #define TRACEPOINT_CREATE_PROBES diff --git a/src/liblttng-ust-libc-wrapper/lttng-ust-pthread.c b/src/liblttng-ust-libc-wrapper/lttng-ust-pthread.c index 06bf791b..c6633fe8 100644 --- a/src/liblttng-ust-libc-wrapper/lttng-ust-pthread.c +++ b/src/liblttng-ust-libc-wrapper/lttng-ust-pthread.c @@ -9,8 +9,11 @@ * circular dependency loop between this malloc wrapper, liburcu and * libc. */ -#include -#include + +/* Has to be included first to override dlfcn.h */ +#include + +#include "common/macros.h" #include #define TRACEPOINT_DEFINE diff --git a/src/liblttng-ust/context-internal.h b/src/liblttng-ust/context-internal.h index 209ffd43..87e3bbf5 100644 --- a/src/liblttng-ust/context-internal.h +++ b/src/liblttng-ust/context-internal.h @@ -9,7 +9,7 @@ #include #include "ust-events-internal.h" -#include "ust-context-provider.h" +#include "common/ust-context-provider.h" int lttng_context_init_all(struct lttng_ust_ctx **ctx) __attribute__((visibility("hidden"))); diff --git a/src/liblttng-ust/event-notifier-notification.c b/src/liblttng-ust/event-notifier-notification.c index b3e2c94f..aab66ab2 100644 --- a/src/liblttng-ust/event-notifier-notification.c +++ b/src/liblttng-ust/event-notifier-notification.c @@ -11,14 +11,14 @@ #include #include -#include +#include "common/logging.h" #include #include "lttng-tracer-core.h" #include "ust-events-internal.h" #include "../libmsgpack/msgpack.h" #include "lttng-bytecode.h" -#include "ust-share.h" +#include "common/patient.h" /* * We want this write to be atomic AND non-blocking, meaning that we diff --git a/src/liblttng-ust/getenv.c b/src/liblttng-ust/getenv.c index ea8edbcd..0a7bffd8 100644 --- a/src/liblttng-ust/getenv.c +++ b/src/liblttng-ust/getenv.c @@ -9,8 +9,8 @@ #include #include #include -#include -#include +#include "common/logging.h" +#include "common/macros.h" #include "getenv.h" enum lttng_env_secure { diff --git a/src/liblttng-ust/lttng-bytecode-specialize.c b/src/liblttng-ust/lttng-bytecode-specialize.c index 31bc3d05..3d7b5c2a 100644 --- a/src/liblttng-ust/lttng-bytecode-specialize.c +++ b/src/liblttng-ust/lttng-bytecode-specialize.c @@ -16,7 +16,7 @@ #include "context-internal.h" #include "lttng-bytecode.h" #include "ust-events-internal.h" -#include "ust-helper.h" +#include "common/macros.h" static int lttng_fls(int val) { diff --git a/src/liblttng-ust/lttng-bytecode-validator.c b/src/liblttng-ust/lttng-bytecode-validator.c index 267c5c19..91c4cace 100644 --- a/src/liblttng-ust/lttng-bytecode-validator.c +++ b/src/liblttng-ust/lttng-bytecode-validator.c @@ -17,7 +17,7 @@ #include "lttng-hash-helper.h" #include "string-utils.h" #include "ust-events-internal.h" -#include "ust-helper.h" +#include "common/macros.h" /* * Number of merge points for hash table size. Hash table initialized to diff --git a/src/liblttng-ust/lttng-bytecode.c b/src/liblttng-ust/lttng-bytecode.c index ea5827a4..68108192 100644 --- a/src/liblttng-ust/lttng-bytecode.c +++ b/src/liblttng-ust/lttng-bytecode.c @@ -15,7 +15,7 @@ #include "context-internal.h" #include "lttng-bytecode.h" #include "ust-events-internal.h" -#include "ust-helper.h" +#include "common/macros.h" static const char *opnames[] = { [ BYTECODE_OP_UNKNOWN ] = "UNKNOWN", diff --git a/src/liblttng-ust/lttng-bytecode.h b/src/liblttng-ust/lttng-bytecode.h index ffbaf187..a72369e1 100644 --- a/src/liblttng-ust/lttng-bytecode.h +++ b/src/liblttng-ust/lttng-bytecode.h @@ -12,16 +12,16 @@ #include #include #include -#include +#include "common/macros.h" #include -#include +#include "common/ust-context-provider.h" #include #include #include #include #include #include -#include +#include "common/logging.h" #include "bytecode.h" #include "ust-events-internal.h" diff --git a/src/liblttng-ust/lttng-clock.c b/src/liblttng-ust/lttng-clock.c index 27ecccd9..edda7ae9 100644 --- a/src/liblttng-ust/lttng-clock.c +++ b/src/liblttng-ust/lttng-clock.c @@ -10,11 +10,13 @@ #include #include #include -#include + #include #include #include +#include "common/logging.h" + #include "clock.h" #include "getenv.h" diff --git a/src/liblttng-ust/lttng-context-cgroup-ns.c b/src/liblttng-ust/lttng-context-cgroup-ns.c index fece0808..305ed8cd 100644 --- a/src/liblttng-ust/lttng-context-cgroup-ns.c +++ b/src/liblttng-ust/lttng-context-cgroup-ns.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include "common/compat/tid.h" #include #include diff --git a/src/liblttng-ust/lttng-context-ipc-ns.c b/src/liblttng-ust/lttng-context-ipc-ns.c index 2ec62416..c5867fb4 100644 --- a/src/liblttng-ust/lttng-context-ipc-ns.c +++ b/src/liblttng-ust/lttng-context-ipc-ns.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include "common/compat/tid.h" #include #include diff --git a/src/liblttng-ust/lttng-context-net-ns.c b/src/liblttng-ust/lttng-context-net-ns.c index 76707cba..e7c8f9f9 100644 --- a/src/liblttng-ust/lttng-context-net-ns.c +++ b/src/liblttng-ust/lttng-context-net-ns.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include "common/compat/tid.h" #include #include "context-internal.h" diff --git a/src/liblttng-ust/lttng-context-perf-counters.c b/src/liblttng-ust/lttng-context-perf-counters.c index 6f620911..39b51f3b 100644 --- a/src/liblttng-ust/lttng-context-perf-counters.c +++ b/src/liblttng-ust/lttng-context-perf-counters.c @@ -25,9 +25,9 @@ #include #include #include -#include +#include "common/macros.h" #include -#include +#include "common/logging.h" #include #include #include "perf_event.h" diff --git a/src/liblttng-ust/lttng-context-provider.c b/src/liblttng-ust/lttng-context-provider.c index c70da208..caeb387b 100644 --- a/src/liblttng-ust/lttng-context-provider.c +++ b/src/liblttng-ust/lttng-context-provider.c @@ -12,13 +12,13 @@ #include #include -#include +#include #include "context-internal.h" #include "lttng-tracer-core.h" #include "jhash.h" #include "context-provider-internal.h" -#include +#include "common/macros.h" struct lttng_ust_registered_context_provider { const struct lttng_ust_context_provider *provider; diff --git a/src/liblttng-ust/lttng-context-time-ns.c b/src/liblttng-ust/lttng-context-time-ns.c index cb907c4a..75e3e365 100644 --- a/src/liblttng-ust/lttng-context-time-ns.c +++ b/src/liblttng-ust/lttng-context-time-ns.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include "common/compat/tid.h" #include #include "lttng-tracer-core.h" #include "ns.h" diff --git a/src/liblttng-ust/lttng-context-uts-ns.c b/src/liblttng-ust/lttng-context-uts-ns.c index 5ba06f6e..b28fe874 100644 --- a/src/liblttng-ust/lttng-context-uts-ns.c +++ b/src/liblttng-ust/lttng-context-uts-ns.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include "common/compat/tid.h" #include #include "context-internal.h" diff --git a/src/liblttng-ust/lttng-context-vtid.c b/src/liblttng-ust/lttng-context-vtid.c index 3530d266..ce8dcd2c 100644 --- a/src/liblttng-ust/lttng-context-vtid.c +++ b/src/liblttng-ust/lttng-context-vtid.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include "common/compat/tid.h" #include #include "context-internal.h" diff --git a/src/liblttng-ust/lttng-context.c b/src/liblttng-ust/lttng-context.c index 7043c157..aeafa9fc 100644 --- a/src/liblttng-ust/lttng-context.c +++ b/src/liblttng-ust/lttng-context.c @@ -9,11 +9,11 @@ #define _LGPL_SOURCE #include #include -#include +#include #include #include -#include -#include +#include "common/logging.h" +#include "common/macros.h" #include #include #include diff --git a/src/liblttng-ust/lttng-events.c b/src/liblttng-ust/lttng-events.c index b61a2293..ed11b3b5 100644 --- a/src/liblttng-ust/lttng-events.c +++ b/src/liblttng-ust/lttng-events.c @@ -32,13 +32,13 @@ #include #include -#include -#include +#include "common/logging.h" +#include "common/macros.h" #include -#include -#include -#include -#include +#include "common/ustcomm.h" +#include "common/ust-fd.h" +#include "common/dynamic-type.h" +#include "common/ust-context-provider.h" #include "error.h" #include "compat.h" #include "lttng-ust-uuid.h" diff --git a/src/liblttng-ust/lttng-getcpu.c b/src/liblttng-ust/lttng-getcpu.c index 762f8152..d4d91da6 100644 --- a/src/liblttng-ust/lttng-getcpu.c +++ b/src/liblttng-ust/lttng-getcpu.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include "common/logging.h" #include #include #include diff --git a/src/liblttng-ust/lttng-probes.c b/src/liblttng-ust/lttng-probes.c index 03fbe36b..553770ea 100644 --- a/src/liblttng-ust/lttng-probes.c +++ b/src/liblttng-ust/lttng-probes.c @@ -15,7 +15,7 @@ #include #include "tracepoint-internal.h" #include -#include +#include "common/macros.h" #include #include "lttng-tracer-core.h" diff --git a/src/liblttng-ust/lttng-ring-buffer-client-template.h b/src/liblttng-ust/lttng-ring-buffer-client-template.h index a63786bc..d7f77698 100644 --- a/src/liblttng-ust/lttng-ring-buffer-client-template.h +++ b/src/liblttng-ust/lttng-ring-buffer-client-template.h @@ -12,8 +12,8 @@ #include #include -#include "ust-bitfield.h" -#include "ust-compat.h" +#include "common/bitfield.h" +#include "common/align.h" #include "clock.h" #include "context-internal.h" #include "lttng-tracer.h" diff --git a/src/liblttng-ust/lttng-ring-buffer-metadata-client-template.h b/src/liblttng-ust/lttng-ring-buffer-metadata-client-template.h index fe080dca..2406567e 100644 --- a/src/liblttng-ust/lttng-ring-buffer-metadata-client-template.h +++ b/src/liblttng-ust/lttng-ring-buffer-metadata-client-template.h @@ -11,8 +11,8 @@ #include #include -#include "ust-bitfield.h" -#include "ust-compat.h" +#include "common/bitfield.h" +#include "common/align.h" #include "lttng-tracer.h" #include "../libringbuffer/frontend_types.h" #include diff --git a/src/liblttng-ust/lttng-tracer-core.h b/src/liblttng-ust/lttng-tracer-core.h index 7714dbf4..e127a660 100644 --- a/src/liblttng-ust/lttng-tracer-core.h +++ b/src/liblttng-ust/lttng-tracer-core.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include "common/logging.h" /* * The longuest possible namespace proc path is with the cgroup ns diff --git a/src/liblttng-ust/lttng-ust-abi.c b/src/liblttng-ust/lttng-ust-abi.c index 61105ace..e443e4bc 100644 --- a/src/liblttng-ust/lttng-ust-abi.c +++ b/src/liblttng-ust/lttng-ust-abi.c @@ -35,8 +35,9 @@ #include #include #include -#include -#include + +#include "common/ust-fd.h" +#include "common/logging.h" #include "../libringbuffer/frontend_types.h" #include "../libringbuffer/frontend.h" @@ -47,7 +48,7 @@ #include "string-utils.h" #include "ust-events-internal.h" #include "context-internal.h" -#include "ust-helper.h" +#include "common/macros.h" #define OBJ_NAME_LEN 16 diff --git a/src/liblttng-ust/lttng-ust-comm.c b/src/liblttng-ust/lttng-ust-comm.c index c0a7311f..137107cd 100644 --- a/src/liblttng-ust/lttng-ust-comm.c +++ b/src/liblttng-ust/lttng-ust-comm.c @@ -39,10 +39,10 @@ #include #include #include -#include -#include -#include -#include +#include "common/ustcomm.h" +#include "common/ust-fd.h" +#include "common/logging.h" +#include "common/macros.h" #include "tracepoint-internal.h" #include "lttng-tracer-core.h" #include "compat.h" @@ -53,7 +53,7 @@ #include "getenv.h" #include "ust-events-internal.h" #include "context-internal.h" -#include "ust-compat.h" +#include "common/align.h" #include "lttng-counter-client.h" #include "lttng-rb-clients.h" diff --git a/src/liblttng-ust/lttng-ust-dynamic-type.c b/src/liblttng-ust/lttng-ust-dynamic-type.c index 30128699..d98e45ba 100644 --- a/src/liblttng-ust/lttng-ust-dynamic-type.c +++ b/src/liblttng-ust/lttng-ust-dynamic-type.c @@ -12,8 +12,8 @@ #include #include -#include -#include +#include "common/macros.h" +#include "common/dynamic-type.h" #define ctf_enum_value(_string, _value) \ __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \ diff --git a/src/liblttng-ust/lttng-ust-elf.c b/src/liblttng-ust/lttng-ust-elf.c index 3e0b8890..59805365 100644 --- a/src/liblttng-ust/lttng-ust-elf.c +++ b/src/liblttng-ust/lttng-ust-elf.c @@ -15,12 +15,12 @@ #include -#include -#include +#include "common/elf.h" +#include "common/ust-fd.h" #include "lttng-tracer-core.h" #include "lttng-ust-elf.h" -#include "ust-helper.h" +#include "common/macros.h" #define BUF_LEN 4096 diff --git a/src/liblttng-ust/lttng-ust-statedump.c b/src/liblttng-ust/lttng-ust-statedump.c index eaee338a..cd8bc7c8 100644 --- a/src/liblttng-ust/lttng-ust-statedump.c +++ b/src/liblttng-ust/lttng-ust-statedump.c @@ -16,8 +16,8 @@ #include #include -#include -#include +#include "common/elf.h" +#include "common/macros.h" #include "lttng-tracer-core.h" #include "lttng-ust-statedump.h" #include "jhash.h" diff --git a/src/liblttng-ust/tracef.c b/src/liblttng-ust/tracef.c index 4c7e805d..3c4ce490 100644 --- a/src/liblttng-ust/tracef.c +++ b/src/liblttng-ust/tracef.c @@ -6,7 +6,7 @@ #define _LGPL_SOURCE #include -#include +#include "common/macros.h" #define TRACEPOINT_CREATE_PROBES #define TRACEPOINT_DEFINE diff --git a/src/liblttng-ust/tracelog.c b/src/liblttng-ust/tracelog.c index d69301d8..735d04a9 100644 --- a/src/liblttng-ust/tracelog.c +++ b/src/liblttng-ust/tracelog.c @@ -6,7 +6,7 @@ #define _LGPL_SOURCE #include -#include +#include "common/macros.h" #define TRACEPOINT_CREATE_PROBES #define TRACEPOINT_DEFINE diff --git a/src/liblttng-ust/tracepoint.c b/src/liblttng-ust/tracepoint.c index 00fcc740..e5a970ad 100644 --- a/src/liblttng-ust/tracepoint.c +++ b/src/liblttng-ust/tracepoint.c @@ -23,8 +23,8 @@ #include #include /* for LTTNG_UST_ABI_SYM_NAME_LEN */ -#include -#include +#include "common/logging.h" +#include "common/macros.h" #include "tracepoint-internal.h" #include "lttng-tracer-core.h" diff --git a/src/liblttng-ust/ust-core.c b/src/liblttng-ust/ust-core.c index 2633832b..d4829904 100644 --- a/src/liblttng-ust/ust-core.c +++ b/src/liblttng-ust/ust-core.c @@ -11,7 +11,7 @@ #include "context-internal.h" #include "ust-events-internal.h" -#include +#include "common/logging.h" #include "lttng-tracer-core.h" #include "lttng-rb-clients.h" #include "lttng-counter-client.h" diff --git a/src/liblttng-ust/ust-events-internal.h b/src/liblttng-ust/ust-events-internal.h index d84d32ee..21d40e17 100644 --- a/src/liblttng-ust/ust-events-internal.h +++ b/src/liblttng-ust/ust-events-internal.h @@ -15,8 +15,8 @@ #include -#include -#include "ust-context-provider.h" +#include "common/macros.h" +#include "common/ust-context-provider.h" struct lttng_ust_abi_obj; struct lttng_event_notifier_group; diff --git a/src/libringbuffer/frontend_types.h b/src/libringbuffer/frontend_types.h index 4e7d2e8f..467ece73 100644 --- a/src/libringbuffer/frontend_types.h +++ b/src/libringbuffer/frontend_types.h @@ -20,7 +20,7 @@ #include #include "ringbuffer-config.h" -#include +#include "common/logging.h" #include "backend_types.h" #include "shm_internal.h" #include "shm_types.h" diff --git a/src/libringbuffer/ring_buffer_backend.c b/src/libringbuffer/ring_buffer_backend.c index 6ba0d8b1..b0a7c513 100644 --- a/src/libringbuffer/ring_buffer_backend.c +++ b/src/libringbuffer/ring_buffer_backend.c @@ -20,7 +20,7 @@ #include "frontend.h" #include "smp.h" #include "shm.h" -#include "ust-compat.h" +#include "common/align.h" /** * lib_ring_buffer_backend_allocate - allocate a channel buffer diff --git a/src/libringbuffer/ring_buffer_frontend.c b/src/libringbuffer/ring_buffer_frontend.c index 1b9ec40d..296368f3 100644 --- a/src/libringbuffer/ring_buffer_frontend.c +++ b/src/libringbuffer/ring_buffer_frontend.c @@ -50,7 +50,7 @@ #include #include #include -#include +#include "common/macros.h" #include #include diff --git a/src/libringbuffer/shm.c b/src/libringbuffer/shm.c index e4f818fc..a5de019c 100644 --- a/src/libringbuffer/shm.c +++ b/src/libringbuffer/shm.c @@ -27,8 +27,8 @@ #include -#include -#include +#include "common/macros.h" +#include "common/ust-fd.h" #include "mmap.h" /* diff --git a/src/libringbuffer/shm.h b/src/libringbuffer/shm.h index c3ce4ef8..6e4f7f7b 100644 --- a/src/libringbuffer/shm.h +++ b/src/libringbuffer/shm.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include "common/logging.h" #include #include "shm_types.h" diff --git a/src/snprintf/core.c b/src/snprintf/core.c index 8c4eddec..9841c68d 100644 --- a/src/snprintf/core.c +++ b/src/snprintf/core.c @@ -4,7 +4,7 @@ * Copyright (C) 2011 Mathieu Desnoyers */ -#include +#include "common/logging.h" volatile enum ust_err_loglevel ust_err_loglevel; diff --git a/src/snprintf/patient_write.c b/src/snprintf/patient_write.c index 5a7fed43..517a16ad 100644 --- a/src/snprintf/patient_write.c +++ b/src/snprintf/patient_write.c @@ -19,7 +19,7 @@ #include -#include +#include "common/patient.h" /* * This write is patient because it restarts if it was incomplete. diff --git a/src/snprintf/snprintf.c b/src/snprintf/snprintf.c index 7e37a5e5..c297cb70 100644 --- a/src/snprintf/snprintf.c +++ b/src/snprintf/snprintf.c @@ -15,7 +15,7 @@ #include #include #include "local.h" -#include "ust-snprintf.h" +#include "common/safe-snprintf.h" #define DUMMY_LEN 1 diff --git a/tests/compile/test-app-ctx/hello.c b/tests/compile/test-app-ctx/hello.c index 9cc8f1a8..26cca016 100644 --- a/tests/compile/test-app-ctx/hello.c +++ b/tests/compile/test-app-ctx/hello.c @@ -31,7 +31,7 @@ struct mmsghdr; #include #include /* Internal header. */ -#include +#include static __thread unsigned int test_count; diff --git a/tests/unit/libringbuffer/shm.c b/tests/unit/libringbuffer/shm.c index d543991a..c0092170 100644 --- a/tests/unit/libringbuffer/shm.c +++ b/tests/unit/libringbuffer/shm.c @@ -13,7 +13,7 @@ #include #include "../../../src/libringbuffer/shm.h" -#include "ust-compat.h" +#include "common/align.h" #include "tap.h" diff --git a/tests/unit/snprintf/snprintf.c b/tests/unit/snprintf/snprintf.c index 00fd02a0..79f31357 100644 --- a/tests/unit/snprintf/snprintf.c +++ b/tests/unit/snprintf/snprintf.c @@ -6,7 +6,7 @@ #include #include -#include "ust-snprintf.h" +#include "common/safe-snprintf.h" #include "tap.h" diff --git a/tests/unit/ust-elf/ust-elf.c b/tests/unit/ust-elf/ust-elf.c index 0073a999..7e924a90 100644 --- a/tests/unit/ust-elf/ust-elf.c +++ b/tests/unit/ust-elf/ust-elf.c @@ -11,7 +11,7 @@ #include #include -#include +#include "common/elf.h" #include "tap.h" #define NUM_ARCH 4