| 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 | #include <lttng/ust-arch.h> |
| 13 | |
| 14 | static inline __attribute__((always_inline)) |
| 15 | void *zmalloc(size_t len) |
| 16 | { |
| 17 | return calloc(len, 1); |
| 18 | } |
| 19 | |
| 20 | #define max_t(type, x, y) \ |
| 21 | ({ \ |
| 22 | type __max1 = (x); \ |
| 23 | type __max2 = (y); \ |
| 24 | __max1 > __max2 ? __max1: __max2; \ |
| 25 | }) |
| 26 | |
| 27 | #define min_t(type, x, y) \ |
| 28 | ({ \ |
| 29 | type __min1 = (x); \ |
| 30 | type __min2 = (y); \ |
| 31 | __min1 <= __min2 ? __min1: __min2; \ |
| 32 | }) |
| 33 | |
| 34 | #define LTTNG_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
| 35 | |
| 36 | /* |
| 37 | * Use of __builtin_return_address(0) sometimes seems to cause stack |
| 38 | * corruption on 32-bit PowerPC. Disable this feature on that |
| 39 | * architecture for now by always using the NULL value for the ip |
| 40 | * context. |
| 41 | */ |
| 42 | #if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64) |
| 43 | #define LTTNG_UST_CALLER_IP() NULL |
| 44 | #else |
| 45 | #define LTTNG_UST_CALLER_IP() __builtin_return_address(0) |
| 46 | #endif |
| 47 | |
| 48 | #endif /* _LTTNG_UST_HELPER_H */ |