Move to kernel style SPDX license identifiers
[lttng-ust.git] / include / helper.h
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 */
6
7 #ifndef _LTTNG_UST_HELPER_H
8 #define _LTTNG_UST_HELPER_H
9
10 #include <stdlib.h>
11
12 static inline __attribute__((always_inline))
13 void *zmalloc(size_t len)
14 {
15 return calloc(len, 1);
16 }
17
18 #define max_t(type, x, y) \
19 ({ \
20 type __max1 = (x); \
21 type __max2 = (y); \
22 __max1 > __max2 ? __max1: __max2; \
23 })
24
25 #define min_t(type, x, y) \
26 ({ \
27 type __min1 = (x); \
28 type __min2 = (y); \
29 __min1 <= __min2 ? __min1: __min2; \
30 })
31
32 #define LTTNG_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
33
34 /*
35 * Use of __builtin_return_address(0) sometimes seems to cause stack
36 * corruption on 32-bit PowerPC. Disable this feature on that
37 * architecture for now by always using the NULL value for the ip
38 * context.
39 */
40 #if defined(__PPC__) && !defined(__PPC64__)
41 #define LTTNG_UST_CALLER_IP() NULL
42 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
43 #define LTTNG_UST_CALLER_IP() __builtin_return_address(0)
44 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
45
46 /*
47 * LTTNG_HIDDEN: set the hidden attribute for internal functions
48 * On Windows, symbols are local unless explicitly exported,
49 * see https://gcc.gnu.org/wiki/Visibility
50 */
51 #if defined(_WIN32) || defined(__CYGWIN__)
52 #define LTTNG_HIDDEN
53 #else
54 #define LTTNG_HIDDEN __attribute__((visibility("hidden")))
55 #endif
56
57 #endif /* _LTTNG_UST_HELPER_H */
This page took 0.029319 seconds and 4 git commands to generate.