1 /* $OpenBSD: bug.h,v 1.1 2019/04/14 10:14:53 jsg Exp $ */ 2 /* 3 * Copyright (c) 2013, 2014, 2015 Mark Kettenis 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #ifndef _LINUX_BUG_H 19 #define _LINUX_BUG_H 20 21 #include <sys/types.h> 22 #include <sys/systm.h> 23 #include <linux/compiler.h> 24 25 #define BUG() \ 26 do { \ 27 panic("BUG at %s:%d", __FILE__, __LINE__); \ 28 } while (0) 29 30 #ifndef DIAGNOSTIC 31 #define BUG_ON(x) ((void)(x)) 32 #else 33 #define BUG_ON(x) KASSERT(!(x)) 34 #endif 35 36 #define BUILD_BUG() 37 #define BUILD_BUG_ON(x) CTASSERT(!(x)) 38 #define BUILD_BUG_ON_NOT_POWER_OF_2(x) 0 39 #define BUILD_BUG_ON_MSG(x, y) do { } while (0) 40 #define BUILD_BUG_ON_INVALID(x) ((void)0) 41 #define BUILD_BUG_ON_ZERO(x) 0 42 43 #define WARN(condition, fmt...) ({ \ 44 int __ret = !!(condition); \ 45 if (__ret) \ 46 printf(fmt); \ 47 unlikely(__ret); \ 48 }) 49 50 #define WARN_ONCE(condition, fmt...) ({ \ 51 static int __warned; \ 52 int __ret = !!(condition); \ 53 if (__ret && !__warned) { \ 54 printf(fmt); \ 55 __warned = 1; \ 56 } \ 57 unlikely(__ret); \ 58 }) 59 60 #define _WARN_STR(x) #x 61 62 #define WARN_ON(condition) ({ \ 63 int __ret = !!(condition); \ 64 if (__ret) \ 65 printf("WARNING %s failed at %s:%d\n", \ 66 _WARN_STR(condition), __FILE__, __LINE__); \ 67 unlikely(__ret); \ 68 }) 69 70 #define WARN_ON_ONCE(condition) ({ \ 71 static int __warned; \ 72 int __ret = !!(condition); \ 73 if (__ret && !__warned) { \ 74 printf("WARNING %s failed at %s:%d\n", \ 75 _WARN_STR(condition), __FILE__, __LINE__); \ 76 __warned = 1; \ 77 } \ 78 unlikely(__ret); \ 79 }) 80 81 #endif 82