0001
0002 #ifndef _ASM_GENERIC_BUG_H
0003 #define _ASM_GENERIC_BUG_H
0004
0005 #include <linux/compiler.h>
0006 #include <linux/instrumentation.h>
0007 #include <linux/once_lite.h>
0008
0009 #define CUT_HERE "------------[ cut here ]------------\n"
0010
0011 #ifdef CONFIG_GENERIC_BUG
0012 #define BUGFLAG_WARNING (1 << 0)
0013 #define BUGFLAG_ONCE (1 << 1)
0014 #define BUGFLAG_DONE (1 << 2)
0015 #define BUGFLAG_NO_CUT_HERE (1 << 3)
0016 #define BUGFLAG_TAINT(taint) ((taint) << 8)
0017 #define BUG_GET_TAINT(bug) ((bug)->flags >> 8)
0018 #endif
0019
0020 #ifndef __ASSEMBLY__
0021 #include <linux/panic.h>
0022 #include <linux/printk.h>
0023
0024 struct warn_args;
0025 struct pt_regs;
0026
0027 void __warn(const char *file, int line, void *caller, unsigned taint,
0028 struct pt_regs *regs, struct warn_args *args);
0029
0030 #ifdef CONFIG_BUG
0031
0032 #ifdef CONFIG_GENERIC_BUG
0033 struct bug_entry {
0034 #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
0035 unsigned long bug_addr;
0036 #else
0037 signed int bug_addr_disp;
0038 #endif
0039 #ifdef CONFIG_DEBUG_BUGVERBOSE
0040 #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
0041 const char *file;
0042 #else
0043 signed int file_disp;
0044 #endif
0045 unsigned short line;
0046 #endif
0047 unsigned short flags;
0048 };
0049 #endif
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062 #ifndef HAVE_ARCH_BUG
0063 #define BUG() do { \
0064 printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
0065 barrier_before_unreachable(); \
0066 panic("BUG!"); \
0067 } while (0)
0068 #endif
0069
0070 #ifndef HAVE_ARCH_BUG_ON
0071 #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
0072 #endif
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 #ifndef __WARN_FLAGS
0091 extern __printf(4, 5)
0092 void warn_slowpath_fmt(const char *file, const int line, unsigned taint,
0093 const char *fmt, ...);
0094 #define __WARN() __WARN_printf(TAINT_WARN, NULL)
0095 #define __WARN_printf(taint, arg...) do { \
0096 instrumentation_begin(); \
0097 warn_slowpath_fmt(__FILE__, __LINE__, taint, arg); \
0098 instrumentation_end(); \
0099 } while (0)
0100 #else
0101 extern __printf(1, 2) void __warn_printk(const char *fmt, ...);
0102 #define __WARN() __WARN_FLAGS(BUGFLAG_TAINT(TAINT_WARN))
0103 #define __WARN_printf(taint, arg...) do { \
0104 instrumentation_begin(); \
0105 __warn_printk(arg); \
0106 __WARN_FLAGS(BUGFLAG_NO_CUT_HERE | BUGFLAG_TAINT(taint));\
0107 instrumentation_end(); \
0108 } while (0)
0109 #define WARN_ON_ONCE(condition) ({ \
0110 int __ret_warn_on = !!(condition); \
0111 if (unlikely(__ret_warn_on)) \
0112 __WARN_FLAGS(BUGFLAG_ONCE | \
0113 BUGFLAG_TAINT(TAINT_WARN)); \
0114 unlikely(__ret_warn_on); \
0115 })
0116 #endif
0117
0118
0119
0120 #ifndef WARN_ON
0121 #define WARN_ON(condition) ({ \
0122 int __ret_warn_on = !!(condition); \
0123 if (unlikely(__ret_warn_on)) \
0124 __WARN(); \
0125 unlikely(__ret_warn_on); \
0126 })
0127 #endif
0128
0129 #ifndef WARN
0130 #define WARN(condition, format...) ({ \
0131 int __ret_warn_on = !!(condition); \
0132 if (unlikely(__ret_warn_on)) \
0133 __WARN_printf(TAINT_WARN, format); \
0134 unlikely(__ret_warn_on); \
0135 })
0136 #endif
0137
0138 #define WARN_TAINT(condition, taint, format...) ({ \
0139 int __ret_warn_on = !!(condition); \
0140 if (unlikely(__ret_warn_on)) \
0141 __WARN_printf(taint, format); \
0142 unlikely(__ret_warn_on); \
0143 })
0144
0145 #ifndef WARN_ON_ONCE
0146 #define WARN_ON_ONCE(condition) \
0147 DO_ONCE_LITE_IF(condition, WARN_ON, 1)
0148 #endif
0149
0150 #define WARN_ONCE(condition, format...) \
0151 DO_ONCE_LITE_IF(condition, WARN, 1, format)
0152
0153 #define WARN_TAINT_ONCE(condition, taint, format...) \
0154 DO_ONCE_LITE_IF(condition, WARN_TAINT, 1, taint, format)
0155
0156 #else
0157 #ifndef HAVE_ARCH_BUG
0158 #define BUG() do {} while (1)
0159 #endif
0160
0161 #ifndef HAVE_ARCH_BUG_ON
0162 #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
0163 #endif
0164
0165 #ifndef HAVE_ARCH_WARN_ON
0166 #define WARN_ON(condition) ({ \
0167 int __ret_warn_on = !!(condition); \
0168 unlikely(__ret_warn_on); \
0169 })
0170 #endif
0171
0172 #ifndef WARN
0173 #define WARN(condition, format...) ({ \
0174 int __ret_warn_on = !!(condition); \
0175 no_printk(format); \
0176 unlikely(__ret_warn_on); \
0177 })
0178 #endif
0179
0180 #define WARN_ON_ONCE(condition) WARN_ON(condition)
0181 #define WARN_ONCE(condition, format...) WARN(condition, format)
0182 #define WARN_TAINT(condition, taint, format...) WARN(condition, format)
0183 #define WARN_TAINT_ONCE(condition, taint, format...) WARN(condition, format)
0184
0185 #endif
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210 #ifdef CONFIG_SMP
0211 # define WARN_ON_SMP(x) WARN_ON(x)
0212 #else
0213
0214
0215
0216
0217
0218
0219
0220 # define WARN_ON_SMP(x) ({0;})
0221 #endif
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233 #if defined(CONFIG_CFI_CLANG) && defined(CONFIG_MODULES)
0234 # define WARN_ON_FUNCTION_MISMATCH(x, fn) ({ 0; })
0235 #else
0236 # define WARN_ON_FUNCTION_MISMATCH(x, fn) WARN_ON_ONCE((x) != (fn))
0237 #endif
0238
0239 #endif
0240
0241 #endif