Commit | Line | Data |
---|---|---|
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 | ||
9d315d6d MJ |
7 | #ifndef _UST_COMMON_MACROS_H |
8 | #define _UST_COMMON_MACROS_H | |
c0c0989a | 9 | |
35897f8b MD |
10 | #include <stdlib.h> |
11 | ||
2eba8e39 MJ |
12 | #include <lttng/ust-arch.h> |
13 | ||
9d315d6d MJ |
14 | /* |
15 | * Memory allocation zeroed | |
16 | */ | |
5f6daaef MJ |
17 | static inline |
18 | void *zmalloc(size_t len) | |
19 | __attribute__((always_inline)); | |
20 | static inline | |
35897f8b MD |
21 | void *zmalloc(size_t len) |
22 | { | |
23 | return calloc(len, 1); | |
24 | } | |
25 | ||
26 | #define max_t(type, x, y) \ | |
27 | ({ \ | |
28 | type __max1 = (x); \ | |
29 | type __max2 = (y); \ | |
30 | __max1 > __max2 ? __max1: __max2; \ | |
31 | }) | |
32 | ||
33 | #define min_t(type, x, y) \ | |
34 | ({ \ | |
35 | type __min1 = (x); \ | |
36 | type __min2 = (y); \ | |
37 | __min1 <= __min2 ? __min1: __min2; \ | |
38 | }) | |
39 | ||
fd67a004 MD |
40 | #define LTTNG_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
41 | ||
171fcc6f MD |
42 | /* |
43 | * Use of __builtin_return_address(0) sometimes seems to cause stack | |
44 | * corruption on 32-bit PowerPC. Disable this feature on that | |
45 | * architecture for now by always using the NULL value for the ip | |
46 | * context. | |
47 | */ | |
2eba8e39 | 48 | #if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64) |
171fcc6f | 49 | #define LTTNG_UST_CALLER_IP() NULL |
2eba8e39 | 50 | #else |
171fcc6f | 51 | #define LTTNG_UST_CALLER_IP() __builtin_return_address(0) |
2eba8e39 | 52 | #endif |
171fcc6f | 53 | |
9d315d6d | 54 | #endif /* _UST_COMMON_MACROS_H */ |