| 1 | #ifndef _LTTNG_UST_HELPER_H |
| 2 | #define _LTTNG_UST_HELPER_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; version 2.1 of |
| 10 | * the License. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #include <stdlib.h> |
| 23 | |
| 24 | static inline __attribute__((always_inline)) |
| 25 | void *zmalloc(size_t len) |
| 26 | { |
| 27 | return calloc(len, 1); |
| 28 | } |
| 29 | |
| 30 | #define max_t(type, x, y) \ |
| 31 | ({ \ |
| 32 | type __max1 = (x); \ |
| 33 | type __max2 = (y); \ |
| 34 | __max1 > __max2 ? __max1: __max2; \ |
| 35 | }) |
| 36 | |
| 37 | #define min_t(type, x, y) \ |
| 38 | ({ \ |
| 39 | type __min1 = (x); \ |
| 40 | type __min2 = (y); \ |
| 41 | __min1 <= __min2 ? __min1: __min2; \ |
| 42 | }) |
| 43 | |
| 44 | #define LTTNG_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
| 45 | |
| 46 | /* |
| 47 | * Use of __builtin_return_address(0) sometimes seems to cause stack |
| 48 | * corruption on 32-bit PowerPC. Disable this feature on that |
| 49 | * architecture for now by always using the NULL value for the ip |
| 50 | * context. |
| 51 | */ |
| 52 | #if defined(__PPC__) && !defined(__PPC64__) |
| 53 | #define LTTNG_UST_CALLER_IP() NULL |
| 54 | #else /* #if defined(__PPC__) && !defined(__PPC64__) */ |
| 55 | #define LTTNG_UST_CALLER_IP() __builtin_return_address(0) |
| 56 | #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */ |
| 57 | |
| 58 | #endif /* _LTTNG_UST_HELPER_H */ |