Move to kernel style SPDX license identifiers
[lttng-ust.git] / include / helper.h
CommitLineData
35897f8b 1/*
c0c0989a 2 * SPDX-License-Identifier: LGPL-2.1-only
35897f8b 3 *
c0c0989a 4 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
35897f8b
MD
5 */
6
c0c0989a
MJ
7#ifndef _LTTNG_UST_HELPER_H
8#define _LTTNG_UST_HELPER_H
9
35897f8b
MD
10#include <stdlib.h>
11
415dfaf7 12static inline __attribute__((always_inline))
35897f8b
MD
13void *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
fd67a004
MD
32#define LTTNG_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
33
171fcc6f
MD
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
94be38e8
JR
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
35897f8b 57#endif /* _LTTNG_UST_HELPER_H */
This page took 0.028691 seconds and 4 git commands to generate.