Now it works.
[cbs-scheduler.git] / include / asm-generic / bug.h
blobf2687d3f34d746d09ab70aeaf128f303a7ef7477
1 #ifndef _ASM_GENERIC_BUG_H
2 #define _ASM_GENERIC_BUG_H
4 #include <linux/compiler.h>
6 #ifndef __ASSEMBLY__
7 extern void __WARN_ON(const char *func, const char *file, const int line);
8 #endif /* __ASSEMBLY__ */
10 #ifdef CONFIG_BUG
12 #ifdef CONFIG_GENERIC_BUG
13 #ifndef __ASSEMBLY__
14 struct bug_entry {
15 #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
16 unsigned long bug_addr;
17 #else
18 signed int bug_addr_disp;
19 #endif
20 #ifdef CONFIG_DEBUG_BUGVERBOSE
21 #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
22 const char *file;
23 #else
24 signed int file_disp;
25 #endif
26 unsigned short line;
27 #endif
28 unsigned short flags;
30 #endif /* __ASSEMBLY__ */
32 #define BUGFLAG_WARNING (1<<0)
33 #endif /* CONFIG_GENERIC_BUG */
36 * Don't use BUG() or BUG_ON() unless there's really no way out; one
37 * example might be detecting data structure corruption in the middle
38 * of an operation that can't be backed out of. If the (sub)system
39 * can somehow continue operating, perhaps with reduced functionality,
40 * it's probably not BUG-worthy.
42 * If you're tempted to BUG(), think again: is completely giving up
43 * really the *only* solution? There are usually better options, where
44 * users don't need to reboot ASAP and can mostly shut down cleanly.
46 #ifndef HAVE_ARCH_BUG
47 #define BUG() do { \
48 printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
49 panic("BUG!"); \
50 } while (0)
51 #endif
53 #ifndef HAVE_ARCH_BUG_ON
54 #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
55 #endif
58 * WARN(), WARN_ON(), WARN_ON_ONCE, and so on can be used to report
59 * significant issues that need prompt attention if they should ever
60 * appear at runtime. Use the versions with printk format strings
61 * to provide better diagnostics.
63 #ifndef __WARN
64 #ifndef __ASSEMBLY__
65 extern void warn_slowpath(const char *file, const int line,
66 const char *fmt, ...) __attribute__((format(printf, 3, 4)));
67 #define WANT_WARN_ON_SLOWPATH
68 #endif
69 #define __WARN() warn_slowpath(__FILE__, __LINE__, NULL)
70 #define __WARN_printf(arg...) warn_slowpath(__FILE__, __LINE__, arg)
71 #else
72 #define __WARN_printf(arg...) do { printk(arg); __WARN(); } while (0)
73 #endif
75 #ifndef WARN_ON
76 #define WARN_ON(condition) ({ \
77 int __ret_warn_on = !!(condition); \
78 if (unlikely(__ret_warn_on)) \
79 __WARN(); \
80 unlikely(__ret_warn_on); \
82 #endif
84 #ifndef WARN
85 #define WARN(condition, format...) ({ \
86 int __ret_warn_on = !!(condition); \
87 if (unlikely(__ret_warn_on)) \
88 __WARN_printf(format); \
89 unlikely(__ret_warn_on); \
91 #endif
93 #else /* !CONFIG_BUG */
94 #ifndef HAVE_ARCH_BUG
95 #define BUG()
96 #endif
98 #ifndef HAVE_ARCH_BUG_ON
99 #define BUG_ON(condition) do { if (condition) ; } while(0)
100 #endif
102 #ifndef HAVE_ARCH_WARN_ON
103 #define WARN_ON(condition) ({ \
104 int __ret_warn_on = !!(condition); \
105 unlikely(__ret_warn_on); \
107 #endif
109 #ifndef WARN
110 static inline int __attribute__ ((format(printf, 2, 3)))
111 __WARN(int condition, const char *fmt, ...) { return condition; }
112 #define WARN(condition, format...) __WARN(!!(condition), format)
113 #endif
115 #endif
117 #define WARN_ON_ONCE(condition) ({ \
118 static int __warned; \
119 int __ret_warn_once = !!(condition); \
121 if (unlikely(__ret_warn_once)) \
122 if (WARN_ON(!__warned)) \
123 __warned = 1; \
124 unlikely(__ret_warn_once); \
127 #define WARN_ONCE(condition, format...) ({ \
128 static int __warned; \
129 int __ret_warn_once = !!(condition); \
131 if (unlikely(__ret_warn_once)) \
132 if (WARN(!__warned, format)) \
133 __warned = 1; \
134 unlikely(__ret_warn_once); \
137 #define WARN_ON_RATELIMIT(condition, state) \
138 WARN_ON((condition) && __ratelimit(state))
140 #ifdef CONFIG_SMP
141 # define WARN_ON_SMP(x) WARN_ON(x)
142 #else
143 # define WARN_ON_SMP(x) do { } while (0)
144 #endif
146 #ifdef CONFIG_PREEMPT_RT
147 # define BUG_ON_RT(c) BUG_ON(c)
148 # define BUG_ON_NONRT(c) do { } while (0)
149 # define WARN_ON_RT(condition) WARN_ON(condition)
150 # define WARN_ON_NONRT(condition) do { } while (0)
151 # define WARN_ON_ONCE_NONRT(condition) do { } while (0)
152 #else
153 # define BUG_ON_RT(c) do { } while (0)
154 # define BUG_ON_NONRT(c) BUG_ON(c)
155 # define WARN_ON_RT(condition) do { } while (0)
156 # define WARN_ON_NONRT(condition) WARN_ON(condition)
157 # define WARN_ON_ONCE_NONRT(condition) WARN_ON_ONCE(condition)
158 #endif
160 #endif