Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _ASM_GENERIC_BUG_H |
| 2 | #define _ASM_GENERIC_BUG_H |
| 3 | |
| 4 | #include <linux/compiler.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | |
Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 6 | #ifdef CONFIG_BUG |
Jeremy Fitzhardinge | 7664c5a | 2006-12-08 02:36:19 -0800 | [diff] [blame] | 7 | |
| 8 | #ifdef CONFIG_GENERIC_BUG |
| 9 | #ifndef __ASSEMBLY__ |
| 10 | struct bug_entry { |
| 11 | unsigned long bug_addr; |
| 12 | #ifdef CONFIG_DEBUG_BUGVERBOSE |
| 13 | const char *file; |
| 14 | unsigned short line; |
| 15 | #endif |
| 16 | unsigned short flags; |
| 17 | }; |
| 18 | #endif /* __ASSEMBLY__ */ |
| 19 | |
| 20 | #define BUGFLAG_WARNING (1<<0) |
| 21 | #endif /* CONFIG_GENERIC_BUG */ |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #ifndef HAVE_ARCH_BUG |
| 24 | #define BUG() do { \ |
Ingo Molnar | 91368d7 | 2006-03-23 03:00:54 -0800 | [diff] [blame] | 25 | printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | panic("BUG!"); \ |
| 27 | } while (0) |
| 28 | #endif |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #ifndef HAVE_ARCH_BUG_ON |
| 31 | #define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0) |
| 32 | #endif |
| 33 | |
| 34 | #ifndef HAVE_ARCH_WARN_ON |
Herbert Xu | 684f978 | 2006-09-29 01:59:06 -0700 | [diff] [blame] | 35 | #define WARN_ON(condition) ({ \ |
| 36 | typeof(condition) __ret_warn_on = (condition); \ |
| 37 | if (unlikely(__ret_warn_on)) { \ |
Ingo Molnar | 52e88f5 | 2006-12-29 16:47:10 -0800 | [diff] [blame] | 38 | printk("BUG: at %s:%d %s()\n", __FILE__, \ |
Herbert Xu | 684f978 | 2006-09-29 01:59:06 -0700 | [diff] [blame] | 39 | __LINE__, __FUNCTION__); \ |
| 40 | dump_stack(); \ |
| 41 | } \ |
| 42 | unlikely(__ret_warn_on); \ |
| 43 | }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #endif |
| 45 | |
Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 46 | #else /* !CONFIG_BUG */ |
| 47 | #ifndef HAVE_ARCH_BUG |
| 48 | #define BUG() |
| 49 | #endif |
| 50 | |
Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 51 | #ifndef HAVE_ARCH_BUG_ON |
| 52 | #define BUG_ON(condition) do { if (condition) ; } while(0) |
| 53 | #endif |
| 54 | |
| 55 | #ifndef HAVE_ARCH_WARN_ON |
Ralf Baechle | 8c7c7c9 | 2006-10-19 23:28:34 -0700 | [diff] [blame] | 56 | #define WARN_ON(condition) ({ \ |
| 57 | typeof(condition) __ret_warn_on = (condition); \ |
| 58 | unlikely(__ret_warn_on); \ |
| 59 | }) |
Matt Mackall | c8538a7 | 2005-05-01 08:59:01 -0700 | [diff] [blame] | 60 | #endif |
| 61 | #endif |
| 62 | |
Andrew Morton | d69a892 | 2006-10-06 00:43:49 -0700 | [diff] [blame] | 63 | #define WARN_ON_ONCE(condition) ({ \ |
| 64 | static int __warned; \ |
| 65 | typeof(condition) __ret_warn_once = (condition); \ |
| 66 | \ |
| 67 | if (unlikely(__ret_warn_once)) \ |
| 68 | if (WARN_ON(!__warned)) \ |
| 69 | __warned = 1; \ |
| 70 | unlikely(__ret_warn_once); \ |
Ingo Molnar | 74bb6a0 | 2006-06-25 05:48:09 -0700 | [diff] [blame] | 71 | }) |
| 72 | |
Ingo Molnar | 8eb94f8 | 2006-06-27 02:54:50 -0700 | [diff] [blame] | 73 | #ifdef CONFIG_SMP |
| 74 | # define WARN_ON_SMP(x) WARN_ON(x) |
| 75 | #else |
| 76 | # define WARN_ON_SMP(x) do { } while (0) |
| 77 | #endif |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #endif |