1 /* $OpenBSD: bug.h,v 1.2 2021/07/07 02:38:36 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 #include <linux/build_bug.h> 25 26 #define BUG() \ 27 do { \ 28 panic("BUG at %s:%d", __FILE__, __LINE__); \ 29 } while (0) 30 31 #ifndef DIAGNOSTIC 32 #define BUG_ON(x) ((void)(x)) 33 #else 34 #define BUG_ON(x) KASSERT(!(x)) 35 #endif 36 37 #define WARN(condition, fmt...) ({ \ 38 int __ret = !!(condition); \ 39 if (__ret) \ 40 printf(fmt); \ 41 unlikely(__ret); \ 42 }) 43 44 #define WARN_ONCE(condition, fmt...) ({ \ 45 static int __warned; \ 46 int __ret = !!(condition); \ 47 if (__ret && !__warned) { \ 48 printf(fmt); \ 49 __warned = 1; \ 50 } \ 51 unlikely(__ret); \ 52 }) 53 54 #define _WARN_STR(x) #x 55 56 #define WARN_ON(condition) ({ \ 57 int __ret = !!(condition); \ 58 if (__ret) \ 59 printf("WARNING %s failed at %s:%d\n", \ 60 _WARN_STR(condition), __FILE__, __LINE__); \ 61 unlikely(__ret); \ 62 }) 63 64 #define WARN_ON_ONCE(condition) ({ \ 65 static int __warned; \ 66 int __ret = !!(condition); \ 67 if (__ret && !__warned) { \ 68 printf("WARNING %s failed at %s:%d\n", \ 69 _WARN_STR(condition), __FILE__, __LINE__); \ 70 __warned = 1; \ 71 } \ 72 unlikely(__ret); \ 73 }) 74 75 #endif 76