blob: a3f738cffdb61a0057ffb8a1cd9a012e30b72f24 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ASM_GENERIC_BUG_H
2#define _ASM_GENERIC_BUG_H
3
4#include <linux/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
Matt Mackallc8538a72005-05-01 08:59:01 -07006#ifdef CONFIG_BUG
Jeremy Fitzhardinge7664c5a2006-12-08 02:36:19 -08007
8#ifdef CONFIG_GENERIC_BUG
9#ifndef __ASSEMBLY__
10struct 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 Torvalds1da177e2005-04-16 15:20:36 -070023#ifndef HAVE_ARCH_BUG
24#define BUG() do { \
Ingo Molnar91368d72006-03-23 03:00:54 -080025 printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 panic("BUG!"); \
27} while (0)
28#endif
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#ifndef HAVE_ARCH_BUG_ON
Alexey Dobriyan2a41de42007-07-17 04:03:56 -070031#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#endif
33
Olof Johansson3a6a62f92008-01-30 13:32:50 +010034#ifndef __WARN
Arjan van de Ven79b4cc52008-01-30 13:32:50 +010035#ifndef __ASSEMBLY__
36extern void warn_on_slowpath(const char *file, const int line);
Arjan van de Vena8f18b92008-07-25 01:45:53 -070037extern void warn_slowpath(const char *file, const int line,
38 const char *fmt, ...) __attribute__((format(printf, 3, 4)));
Arjan van de Ven79b4cc52008-01-30 13:32:50 +010039#define WANT_WARN_ON_SLOWPATH
40#endif
41#define __WARN() warn_on_slowpath(__FILE__, __LINE__)
Arjan van de Vena8f18b92008-07-25 01:45:53 -070042#define __WARN_printf(arg...) warn_slowpath(__FILE__, __LINE__, arg)
43#else
44#define __WARN_printf(arg...) __WARN()
Olof Johansson3a6a62f92008-01-30 13:32:50 +010045#endif
46
47#ifndef WARN_ON
Herbert Xu684f9782006-09-29 01:59:06 -070048#define WARN_ON(condition) ({ \
Linus Torvalds8d4fbcf2007-07-31 21:12:07 -070049 int __ret_warn_on = !!(condition); \
Olof Johansson3a6a62f92008-01-30 13:32:50 +010050 if (unlikely(__ret_warn_on)) \
51 __WARN(); \
Herbert Xu684f9782006-09-29 01:59:06 -070052 unlikely(__ret_warn_on); \
53})
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#endif
55
Arjan van de Vena8f18b92008-07-25 01:45:53 -070056#ifndef WARN
57#define WARN(condition, format...) ({ \
58 int __ret_warn_on = !!(condition); \
59 if (unlikely(__ret_warn_on)) \
60 __WARN_printf(format); \
61 unlikely(__ret_warn_on); \
62})
63#endif
64
Matt Mackallc8538a72005-05-01 08:59:01 -070065#else /* !CONFIG_BUG */
66#ifndef HAVE_ARCH_BUG
67#define BUG()
68#endif
69
Matt Mackallc8538a72005-05-01 08:59:01 -070070#ifndef HAVE_ARCH_BUG_ON
71#define BUG_ON(condition) do { if (condition) ; } while(0)
72#endif
73
74#ifndef HAVE_ARCH_WARN_ON
Ralf Baechle8c7c7c92006-10-19 23:28:34 -070075#define WARN_ON(condition) ({ \
Linus Torvalds8d4fbcf2007-07-31 21:12:07 -070076 int __ret_warn_on = !!(condition); \
Ralf Baechle8c7c7c92006-10-19 23:28:34 -070077 unlikely(__ret_warn_on); \
78})
Matt Mackallc8538a72005-05-01 08:59:01 -070079#endif
Arjan van de Vena8f18b92008-07-25 01:45:53 -070080
81#ifndef WARN
82#define WARN(condition, format...) ({ \
83 int __ret_warn_on = !!(condition); \
84 unlikely(__ret_warn_on); \
85})
86#endif
87
Matt Mackallc8538a72005-05-01 08:59:01 -070088#endif
89
Andrew Mortond69a8922006-10-06 00:43:49 -070090#define WARN_ON_ONCE(condition) ({ \
91 static int __warned; \
Linus Torvalds8d4fbcf2007-07-31 21:12:07 -070092 int __ret_warn_once = !!(condition); \
Andrew Mortond69a8922006-10-06 00:43:49 -070093 \
94 if (unlikely(__ret_warn_once)) \
95 if (WARN_ON(!__warned)) \
96 __warned = 1; \
97 unlikely(__ret_warn_once); \
Ingo Molnar74bb6a02006-06-25 05:48:09 -070098})
99
Dave Young717115e2008-07-25 01:45:58 -0700100#define WARN_ON_RATELIMIT(condition, state) \
101 WARN_ON((condition) && __ratelimit(state))
102
Ingo Molnar8eb94f82006-06-27 02:54:50 -0700103#ifdef CONFIG_SMP
104# define WARN_ON_SMP(x) WARN_ON(x)
105#else
106# define WARN_ON_SMP(x) do { } while (0)
107#endif
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#endif