| 1 | #ifndef _LTTNG_BUG_H |
| 2 | #define _LTTNG_BUG_H |
| 3 | |
| 4 | /* |
| 5 | * lib/bug.h |
| 6 | * |
| 7 | * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU Lesser General Public |
| 11 | * License as published by the Free Software Foundation; only |
| 12 | * version 2.1 of the License. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * Lesser General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public |
| 20 | * License along with this library; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | */ |
| 23 | |
| 24 | #include <linux/version.h> |
| 25 | |
| 26 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) |
| 27 | #define LTTNG_BUILD_BUG_ON(cond) BUILD_BUG_ON(cond) |
| 28 | #else |
| 29 | #define LTTNG_BUILD_BUG_ON(cond) MAYBE_BUILD_BUG_ON(cond) |
| 30 | #endif |
| 31 | |
| 32 | /** |
| 33 | * BUILD_RUNTIME_BUG_ON - check condition at build (if constant) or runtime |
| 34 | * @condition: the condition which should be false. |
| 35 | * |
| 36 | * If the condition is a constant and true, the compiler will generate a build |
| 37 | * error. If the condition is not constant, a BUG will be triggered at runtime |
| 38 | * if the condition is ever true. If the condition is constant and false, no |
| 39 | * code is emitted. |
| 40 | */ |
| 41 | #define BUILD_RUNTIME_BUG_ON(condition) \ |
| 42 | do { \ |
| 43 | if (__builtin_constant_p(condition)) \ |
| 44 | LTTNG_BUILD_BUG_ON(condition); \ |
| 45 | else \ |
| 46 | BUG_ON(condition); \ |
| 47 | } while (0) |
| 48 | |
| 49 | #endif |