bug.h 1.6 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5
#ifndef _ASM_GENERIC_BUG_H
#define _ASM_GENERIC_BUG_H

#include <linux/compiler.h>

M
Matt Mackall 已提交
6
#ifdef CONFIG_BUG
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

#ifdef CONFIG_GENERIC_BUG
#ifndef __ASSEMBLY__
struct bug_entry {
	unsigned long	bug_addr;
#ifdef CONFIG_DEBUG_BUGVERBOSE
	const char	*file;
	unsigned short	line;
#endif
	unsigned short	flags;
};
#endif		/* __ASSEMBLY__ */

#define BUGFLAG_WARNING	(1<<0)
#endif	/* CONFIG_GENERIC_BUG */

L
Linus Torvalds 已提交
23 24
#ifndef HAVE_ARCH_BUG
#define BUG() do { \
25
	printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
L
Linus Torvalds 已提交
26 27 28 29 30
	panic("BUG!"); \
} while (0)
#endif

#ifndef HAVE_ARCH_BUG_ON
31
#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
L
Linus Torvalds 已提交
32 33 34
#endif

#ifndef HAVE_ARCH_WARN_ON
35
#define WARN_ON(condition) ({						\
L
Linus Torvalds 已提交
36
	int __ret_warn_on = !!(condition);				\
37
	if (unlikely(__ret_warn_on)) {					\
38
		printk("WARNING: at %s:%d %s()\n", __FILE__,		\
39 40 41 42 43
			__LINE__, __FUNCTION__);			\
		dump_stack();						\
	}								\
	unlikely(__ret_warn_on);					\
})
L
Linus Torvalds 已提交
44 45
#endif

M
Matt Mackall 已提交
46 47 48 49 50 51 52 53 54 55
#else /* !CONFIG_BUG */
#ifndef HAVE_ARCH_BUG
#define BUG()
#endif

#ifndef HAVE_ARCH_BUG_ON
#define BUG_ON(condition) do { if (condition) ; } while(0)
#endif

#ifndef HAVE_ARCH_WARN_ON
56
#define WARN_ON(condition) ({						\
L
Linus Torvalds 已提交
57
	int __ret_warn_on = !!(condition);				\
58 59
	unlikely(__ret_warn_on);					\
})
M
Matt Mackall 已提交
60 61 62
#endif
#endif

63 64
#define WARN_ON_ONCE(condition)	({				\
	static int __warned;					\
L
Linus Torvalds 已提交
65
	int __ret_warn_once = !!(condition);			\
66 67 68 69 70
								\
	if (unlikely(__ret_warn_once))				\
		if (WARN_ON(!__warned)) 			\
			__warned = 1;				\
	unlikely(__ret_warn_once);				\
71 72
})

73 74 75 76 77 78
#ifdef CONFIG_SMP
# define WARN_ON_SMP(x)			WARN_ON(x)
#else
# define WARN_ON_SMP(x)			do { } while (0)
#endif

L
Linus Torvalds 已提交
79
#endif