baca88f271184840512ea97745320d8bef65e333
2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2010-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 #ifndef _LTTNG_UST_UTILS_H
8 #define _LTTNG_UST_UTILS_H
12 #include <urcu/compiler.h>
14 /* For lttng_ust_is_integer_type */
15 #if defined (__cplusplus)
16 #include <type_traits>
21 * lttng_ust_stringify - convert a literal value to a C string
23 #define __lttng_ust_stringify1(x) #x
24 #define lttng_ust_stringify(x) __lttng_ust_stringify1(x)
27 * lttng_ust_is_signed_type - check if type is signed
29 * Returns true if the type of @type is signed.
31 #define lttng_ust_is_signed_type(type) ((type) -1 < (type) 1)
35 * lttng_ust_is_integer_type - check if type is an integer
37 * Returns true if the type of @type is an integer.
39 #if defined(__cplusplus)
40 #define lttng_ust_is_integer_type(type) (std::is_integral<type>::value)
42 #define lttng_ust_is_integer_type(type) \
43 (__builtin_types_compatible_p(type, _Bool) || \
44 __builtin_types_compatible_p(type, char) || \
45 __builtin_types_compatible_p(type, signed char) || \
46 __builtin_types_compatible_p(type, unsigned char) || \
47 __builtin_types_compatible_p(type, short) || \
48 __builtin_types_compatible_p(type, unsigned short) || \
49 __builtin_types_compatible_p(type, int) || \
50 __builtin_types_compatible_p(type, unsigned int) || \
51 __builtin_types_compatible_p(type, long) || \
52 __builtin_types_compatible_p(type, unsigned long) || \
53 __builtin_types_compatible_p(type, long long) || \
54 __builtin_types_compatible_p(type, unsigned long long))
58 * lttng_ust_ctf_array_element_type_is_supported -
60 * Adds a compilation assertion that CTF arrays and sequences declared by the
61 * user are of an integral type.
63 #define lttng_ust_ctf_array_element_type_is_supported(type, item) \
64 lttng_static_assert(lttng_ust_is_integer_type(type), \
65 "Non-integer type `" #item "` not supported as element of CTF_ARRAY or CTF_SEQUENCE", \
66 Non_integer_type__##item##__not_supported_as_element_of_CTF_ARRAY_or_CTF_SEQUENCE);
70 * lttng_ust_runtime_bug_on - check condition at runtime
71 * @condition: the condition which should be false.
73 * If the condition is true, a BUG will be triggered at runtime.
75 #define lttng_ust_runtime_bug_on(condition) \
77 if (caa_unlikely(condition)) { \
79 "LTTng BUG in file %s, line %d.\n", \
80 __FILE__, __LINE__); \
87 * lttng_ust_build_bug_on - check condition at build
88 * @condition: the condition which should be false.
90 * If the condition is true, the compiler will generate a build error.
92 #define lttng_ust_build_bug_on(condition) \
93 ((void) sizeof(char[-!!(condition)]))
97 * lttng_ust_build_runtime_bug_on - check condition at build (if constant) or runtime
98 * @condition: the condition which should be false.
100 * If the condition is a constant and true, the compiler will generate a build
101 * error. If the condition is not constant, a BUG will be triggered at runtime
102 * if the condition is ever true. If the condition is constant and false, no
105 #define lttng_ust_build_runtime_bug_on(condition) \
107 if (__builtin_constant_p(condition)) \
108 lttng_ust_build_bug_on(condition); \
110 lttng_ust_runtime_bug_on(condition); \
115 * lttng_ust_offset_align - Calculate the offset needed to align an object on
116 * its natural alignment towards higher addresses.
117 * @align_drift: object offset from an "alignment"-aligned address.
118 * @alignment: natural object alignment. Must be non-zero, power of 2.
120 * Returns the offset that must be added to align towards higher
123 #define lttng_ust_offset_align(align_drift, alignment) \
125 lttng_ust_build_runtime_bug_on((alignment) == 0 \
126 || ((alignment) & ((alignment) - 1))); \
127 (((alignment) - (align_drift)) & ((alignment) - 1)); \
132 * lttng_ust_offset_align_floor - Calculate the offset needed to align an
133 * object on its natural alignment towards lower addresses.
134 * @align_drift: object offset from an "alignment"-aligned address.
135 * @alignment: natural object alignment. Must be non-zero, power of 2.
137 * Returns the offset that must be substracted to align towards lower addresses.
139 #define lttng_ust_offset_align_floor(align_drift, alignment) \
141 lttng_ust_build_runtime_bug_on((alignment) == 0 \
142 || ((alignment) & ((alignment) - 1))); \
143 (((align_drift) - (alignment)) & ((alignment) - 1)); \
146 #endif /* _LTTNG_UST_UTILS_H */
This page took 0.033196 seconds and 4 git commands to generate.