2005-04-16 22:20:36 +00:00
|
|
|
#ifndef _ASM_GENERIC_BUG_H
|
|
|
|
#define _ASM_GENERIC_BUG_H
|
|
|
|
|
|
|
|
#include <linux/compiler.h>
|
|
|
|
|
2005-05-01 15:59:01 +00:00
|
|
|
#ifdef CONFIG_BUG
|
[PATCH] Generic BUG implementation
This patch adds common handling for kernel BUGs, for use by architectures as
they wish. The code is derived from arch/powerpc.
The advantages of having common BUG handling are:
- consistent BUG reporting across architectures
- shared implementation of out-of-line file/line data
- implement CONFIG_DEBUG_BUGVERBOSE consistently
This means that in inline impact of BUG is just the illegal instruction
itself, which is an improvement for i386 and x86-64.
A BUG is represented in the instruction stream as an illegal instruction,
which has file/line information associated with it. This extra information is
stored in the __bug_table section in the ELF file.
When the kernel gets an illegal instruction, it first confirms it might
possibly be from a BUG (ie, in kernel mode, the right illegal instruction).
It then calls report_bug(). This searches __bug_table for a matching
instruction pointer, and if found, prints the corresponding file/line
information. If report_bug() determines that it wasn't a BUG which caused the
trap, it returns BUG_TRAP_TYPE_NONE.
Some architectures (powerpc) implement WARN using the same mechanism; if the
illegal instruction was the result of a WARN, then report_bug(Q) returns
CONFIG_DEBUG_BUGVERBOSE; otherwise it returns BUG_TRAP_TYPE_BUG.
lib/bug.c keeps a list of loaded modules which can be searched for __bug_table
entries. The architecture must call
module_bug_finalize()/module_bug_cleanup() from its corresponding
module_finalize/cleanup functions.
Unsetting CONFIG_DEBUG_BUGVERBOSE will reduce the kernel size by some amount.
At the very least, filename and line information will not be recorded for each
but, but architectures may decide to store no extra information per BUG at
all.
Unfortunately, gcc doesn't have a general way to mark an asm() as noreturn, so
architectures will generally have to include an infinite loop (or similar) in
the BUG code, so that gcc knows execution won't continue beyond that point.
gcc does have a __builtin_trap() operator which may be useful to achieve the
same effect, unfortunately it cannot be used to actually implement the BUG
itself, because there's no way to get the instruction's address for use in
generating the __bug_table entry.
[randy.dunlap@oracle.com: Handle BUG=n, GENERIC_BUG=n to prevent build errors]
[bunk@stusta.de: include/linux/bug.h must always #include <linux/module.h]
Signed-off-by: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Andi Kleen <ak@muc.de>
Cc: Hugh Dickens <hugh@veritas.com>
Cc: Michael Ellerman <michael@ellerman.id.au>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-12-08 10:36:19 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_GENERIC_BUG
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
struct bug_entry {
|
2008-12-16 11:40:27 +00:00
|
|
|
#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
|
[PATCH] Generic BUG implementation
This patch adds common handling for kernel BUGs, for use by architectures as
they wish. The code is derived from arch/powerpc.
The advantages of having common BUG handling are:
- consistent BUG reporting across architectures
- shared implementation of out-of-line file/line data
- implement CONFIG_DEBUG_BUGVERBOSE consistently
This means that in inline impact of BUG is just the illegal instruction
itself, which is an improvement for i386 and x86-64.
A BUG is represented in the instruction stream as an illegal instruction,
which has file/line information associated with it. This extra information is
stored in the __bug_table section in the ELF file.
When the kernel gets an illegal instruction, it first confirms it might
possibly be from a BUG (ie, in kernel mode, the right illegal instruction).
It then calls report_bug(). This searches __bug_table for a matching
instruction pointer, and if found, prints the corresponding file/line
information. If report_bug() determines that it wasn't a BUG which caused the
trap, it returns BUG_TRAP_TYPE_NONE.
Some architectures (powerpc) implement WARN using the same mechanism; if the
illegal instruction was the result of a WARN, then report_bug(Q) returns
CONFIG_DEBUG_BUGVERBOSE; otherwise it returns BUG_TRAP_TYPE_BUG.
lib/bug.c keeps a list of loaded modules which can be searched for __bug_table
entries. The architecture must call
module_bug_finalize()/module_bug_cleanup() from its corresponding
module_finalize/cleanup functions.
Unsetting CONFIG_DEBUG_BUGVERBOSE will reduce the kernel size by some amount.
At the very least, filename and line information will not be recorded for each
but, but architectures may decide to store no extra information per BUG at
all.
Unfortunately, gcc doesn't have a general way to mark an asm() as noreturn, so
architectures will generally have to include an infinite loop (or similar) in
the BUG code, so that gcc knows execution won't continue beyond that point.
gcc does have a __builtin_trap() operator which may be useful to achieve the
same effect, unfortunately it cannot be used to actually implement the BUG
itself, because there's no way to get the instruction's address for use in
generating the __bug_table entry.
[randy.dunlap@oracle.com: Handle BUG=n, GENERIC_BUG=n to prevent build errors]
[bunk@stusta.de: include/linux/bug.h must always #include <linux/module.h]
Signed-off-by: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Andi Kleen <ak@muc.de>
Cc: Hugh Dickens <hugh@veritas.com>
Cc: Michael Ellerman <michael@ellerman.id.au>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-12-08 10:36:19 +00:00
|
|
|
unsigned long bug_addr;
|
2008-12-16 11:40:27 +00:00
|
|
|
#else
|
|
|
|
signed int bug_addr_disp;
|
|
|
|
#endif
|
[PATCH] Generic BUG implementation
This patch adds common handling for kernel BUGs, for use by architectures as
they wish. The code is derived from arch/powerpc.
The advantages of having common BUG handling are:
- consistent BUG reporting across architectures
- shared implementation of out-of-line file/line data
- implement CONFIG_DEBUG_BUGVERBOSE consistently
This means that in inline impact of BUG is just the illegal instruction
itself, which is an improvement for i386 and x86-64.
A BUG is represented in the instruction stream as an illegal instruction,
which has file/line information associated with it. This extra information is
stored in the __bug_table section in the ELF file.
When the kernel gets an illegal instruction, it first confirms it might
possibly be from a BUG (ie, in kernel mode, the right illegal instruction).
It then calls report_bug(). This searches __bug_table for a matching
instruction pointer, and if found, prints the corresponding file/line
information. If report_bug() determines that it wasn't a BUG which caused the
trap, it returns BUG_TRAP_TYPE_NONE.
Some architectures (powerpc) implement WARN using the same mechanism; if the
illegal instruction was the result of a WARN, then report_bug(Q) returns
CONFIG_DEBUG_BUGVERBOSE; otherwise it returns BUG_TRAP_TYPE_BUG.
lib/bug.c keeps a list of loaded modules which can be searched for __bug_table
entries. The architecture must call
module_bug_finalize()/module_bug_cleanup() from its corresponding
module_finalize/cleanup functions.
Unsetting CONFIG_DEBUG_BUGVERBOSE will reduce the kernel size by some amount.
At the very least, filename and line information will not be recorded for each
but, but architectures may decide to store no extra information per BUG at
all.
Unfortunately, gcc doesn't have a general way to mark an asm() as noreturn, so
architectures will generally have to include an infinite loop (or similar) in
the BUG code, so that gcc knows execution won't continue beyond that point.
gcc does have a __builtin_trap() operator which may be useful to achieve the
same effect, unfortunately it cannot be used to actually implement the BUG
itself, because there's no way to get the instruction's address for use in
generating the __bug_table entry.
[randy.dunlap@oracle.com: Handle BUG=n, GENERIC_BUG=n to prevent build errors]
[bunk@stusta.de: include/linux/bug.h must always #include <linux/module.h]
Signed-off-by: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Andi Kleen <ak@muc.de>
Cc: Hugh Dickens <hugh@veritas.com>
Cc: Michael Ellerman <michael@ellerman.id.au>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-12-08 10:36:19 +00:00
|
|
|
#ifdef CONFIG_DEBUG_BUGVERBOSE
|
2008-12-16 11:40:27 +00:00
|
|
|
#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
|
[PATCH] Generic BUG implementation
This patch adds common handling for kernel BUGs, for use by architectures as
they wish. The code is derived from arch/powerpc.
The advantages of having common BUG handling are:
- consistent BUG reporting across architectures
- shared implementation of out-of-line file/line data
- implement CONFIG_DEBUG_BUGVERBOSE consistently
This means that in inline impact of BUG is just the illegal instruction
itself, which is an improvement for i386 and x86-64.
A BUG is represented in the instruction stream as an illegal instruction,
which has file/line information associated with it. This extra information is
stored in the __bug_table section in the ELF file.
When the kernel gets an illegal instruction, it first confirms it might
possibly be from a BUG (ie, in kernel mode, the right illegal instruction).
It then calls report_bug(). This searches __bug_table for a matching
instruction pointer, and if found, prints the corresponding file/line
information. If report_bug() determines that it wasn't a BUG which caused the
trap, it returns BUG_TRAP_TYPE_NONE.
Some architectures (powerpc) implement WARN using the same mechanism; if the
illegal instruction was the result of a WARN, then report_bug(Q) returns
CONFIG_DEBUG_BUGVERBOSE; otherwise it returns BUG_TRAP_TYPE_BUG.
lib/bug.c keeps a list of loaded modules which can be searched for __bug_table
entries. The architecture must call
module_bug_finalize()/module_bug_cleanup() from its corresponding
module_finalize/cleanup functions.
Unsetting CONFIG_DEBUG_BUGVERBOSE will reduce the kernel size by some amount.
At the very least, filename and line information will not be recorded for each
but, but architectures may decide to store no extra information per BUG at
all.
Unfortunately, gcc doesn't have a general way to mark an asm() as noreturn, so
architectures will generally have to include an infinite loop (or similar) in
the BUG code, so that gcc knows execution won't continue beyond that point.
gcc does have a __builtin_trap() operator which may be useful to achieve the
same effect, unfortunately it cannot be used to actually implement the BUG
itself, because there's no way to get the instruction's address for use in
generating the __bug_table entry.
[randy.dunlap@oracle.com: Handle BUG=n, GENERIC_BUG=n to prevent build errors]
[bunk@stusta.de: include/linux/bug.h must always #include <linux/module.h]
Signed-off-by: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Andi Kleen <ak@muc.de>
Cc: Hugh Dickens <hugh@veritas.com>
Cc: Michael Ellerman <michael@ellerman.id.au>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-12-08 10:36:19 +00:00
|
|
|
const char *file;
|
2008-12-16 11:40:27 +00:00
|
|
|
#else
|
|
|
|
signed int file_disp;
|
|
|
|
#endif
|
[PATCH] Generic BUG implementation
This patch adds common handling for kernel BUGs, for use by architectures as
they wish. The code is derived from arch/powerpc.
The advantages of having common BUG handling are:
- consistent BUG reporting across architectures
- shared implementation of out-of-line file/line data
- implement CONFIG_DEBUG_BUGVERBOSE consistently
This means that in inline impact of BUG is just the illegal instruction
itself, which is an improvement for i386 and x86-64.
A BUG is represented in the instruction stream as an illegal instruction,
which has file/line information associated with it. This extra information is
stored in the __bug_table section in the ELF file.
When the kernel gets an illegal instruction, it first confirms it might
possibly be from a BUG (ie, in kernel mode, the right illegal instruction).
It then calls report_bug(). This searches __bug_table for a matching
instruction pointer, and if found, prints the corresponding file/line
information. If report_bug() determines that it wasn't a BUG which caused the
trap, it returns BUG_TRAP_TYPE_NONE.
Some architectures (powerpc) implement WARN using the same mechanism; if the
illegal instruction was the result of a WARN, then report_bug(Q) returns
CONFIG_DEBUG_BUGVERBOSE; otherwise it returns BUG_TRAP_TYPE_BUG.
lib/bug.c keeps a list of loaded modules which can be searched for __bug_table
entries. The architecture must call
module_bug_finalize()/module_bug_cleanup() from its corresponding
module_finalize/cleanup functions.
Unsetting CONFIG_DEBUG_BUGVERBOSE will reduce the kernel size by some amount.
At the very least, filename and line information will not be recorded for each
but, but architectures may decide to store no extra information per BUG at
all.
Unfortunately, gcc doesn't have a general way to mark an asm() as noreturn, so
architectures will generally have to include an infinite loop (or similar) in
the BUG code, so that gcc knows execution won't continue beyond that point.
gcc does have a __builtin_trap() operator which may be useful to achieve the
same effect, unfortunately it cannot be used to actually implement the BUG
itself, because there's no way to get the instruction's address for use in
generating the __bug_table entry.
[randy.dunlap@oracle.com: Handle BUG=n, GENERIC_BUG=n to prevent build errors]
[bunk@stusta.de: include/linux/bug.h must always #include <linux/module.h]
Signed-off-by: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Andi Kleen <ak@muc.de>
Cc: Hugh Dickens <hugh@veritas.com>
Cc: Michael Ellerman <michael@ellerman.id.au>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-12-08 10:36:19 +00:00
|
|
|
unsigned short line;
|
|
|
|
#endif
|
|
|
|
unsigned short flags;
|
|
|
|
};
|
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
|
|
|
|
#define BUGFLAG_WARNING (1<<0)
|
|
|
|
#endif /* CONFIG_GENERIC_BUG */
|
|
|
|
|
2009-01-06 22:41:01 +00:00
|
|
|
/*
|
|
|
|
* Don't use BUG() or BUG_ON() unless there's really no way out; one
|
|
|
|
* example might be detecting data structure corruption in the middle
|
|
|
|
* of an operation that can't be backed out of. If the (sub)system
|
|
|
|
* can somehow continue operating, perhaps with reduced functionality,
|
|
|
|
* it's probably not BUG-worthy.
|
|
|
|
*
|
|
|
|
* If you're tempted to BUG(), think again: is completely giving up
|
|
|
|
* really the *only* solution? There are usually better options, where
|
|
|
|
* users don't need to reboot ASAP and can mostly shut down cleanly.
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
#ifndef HAVE_ARCH_BUG
|
|
|
|
#define BUG() do { \
|
2008-10-16 05:01:24 +00:00
|
|
|
printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
|
2005-04-16 22:20:36 +00:00
|
|
|
panic("BUG!"); \
|
|
|
|
} while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_ARCH_BUG_ON
|
2007-07-17 11:03:56 +00:00
|
|
|
#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
|
2009-01-06 22:41:01 +00:00
|
|
|
/*
|
|
|
|
* WARN(), WARN_ON(), WARN_ON_ONCE, and so on can be used to report
|
|
|
|
* significant issues that need prompt attention if they should ever
|
|
|
|
* appear at runtime. Use the versions with printk format strings
|
|
|
|
* to provide better diagnostics.
|
|
|
|
*/
|
2008-01-30 12:32:50 +00:00
|
|
|
#ifndef __WARN
|
2008-01-30 12:32:50 +00:00
|
|
|
#ifndef __ASSEMBLY__
|
2009-05-06 23:02:53 +00:00
|
|
|
extern void warn_slowpath_fmt(const char *file, const int line,
|
2008-07-25 08:45:53 +00:00
|
|
|
const char *fmt, ...) __attribute__((format(printf, 3, 4)));
|
2009-05-06 23:02:53 +00:00
|
|
|
extern void warn_slowpath_null(const char *file, const int line);
|
2008-01-30 12:32:50 +00:00
|
|
|
#define WANT_WARN_ON_SLOWPATH
|
|
|
|
#endif
|
2009-05-06 23:02:53 +00:00
|
|
|
#define __WARN() warn_slowpath_null(__FILE__, __LINE__)
|
|
|
|
#define __WARN_printf(arg...) warn_slowpath_fmt(__FILE__, __LINE__, arg)
|
2008-07-25 08:45:53 +00:00
|
|
|
#else
|
2008-11-28 16:56:14 +00:00
|
|
|
#define __WARN_printf(arg...) do { printk(arg); __WARN(); } while (0)
|
2008-01-30 12:32:50 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WARN_ON
|
2006-09-29 08:59:06 +00:00
|
|
|
#define WARN_ON(condition) ({ \
|
2007-08-01 04:12:07 +00:00
|
|
|
int __ret_warn_on = !!(condition); \
|
2008-01-30 12:32:50 +00:00
|
|
|
if (unlikely(__ret_warn_on)) \
|
|
|
|
__WARN(); \
|
2006-09-29 08:59:06 +00:00
|
|
|
unlikely(__ret_warn_on); \
|
|
|
|
})
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
|
2008-07-25 08:45:53 +00:00
|
|
|
#ifndef WARN
|
|
|
|
#define WARN(condition, format...) ({ \
|
|
|
|
int __ret_warn_on = !!(condition); \
|
|
|
|
if (unlikely(__ret_warn_on)) \
|
|
|
|
__WARN_printf(format); \
|
|
|
|
unlikely(__ret_warn_on); \
|
|
|
|
})
|
|
|
|
#endif
|
|
|
|
|
2005-05-01 15:59:01 +00:00
|
|
|
#else /* !CONFIG_BUG */
|
|
|
|
#ifndef HAVE_ARCH_BUG
|
2009-04-15 18:34:56 +00:00
|
|
|
#define BUG() do {} while(0)
|
2005-05-01 15:59:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_ARCH_BUG_ON
|
|
|
|
#define BUG_ON(condition) do { if (condition) ; } while(0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_ARCH_WARN_ON
|
2006-10-20 06:28:34 +00:00
|
|
|
#define WARN_ON(condition) ({ \
|
2007-08-01 04:12:07 +00:00
|
|
|
int __ret_warn_on = !!(condition); \
|
2006-10-20 06:28:34 +00:00
|
|
|
unlikely(__ret_warn_on); \
|
|
|
|
})
|
2005-05-01 15:59:01 +00:00
|
|
|
#endif
|
2008-07-25 08:45:53 +00:00
|
|
|
|
|
|
|
#ifndef WARN
|
|
|
|
#define WARN(condition, format...) ({ \
|
|
|
|
int __ret_warn_on = !!(condition); \
|
|
|
|
unlikely(__ret_warn_on); \
|
|
|
|
})
|
|
|
|
#endif
|
|
|
|
|
2005-05-01 15:59:01 +00:00
|
|
|
#endif
|
|
|
|
|
2006-10-06 07:43:49 +00:00
|
|
|
#define WARN_ON_ONCE(condition) ({ \
|
|
|
|
static int __warned; \
|
2007-08-01 04:12:07 +00:00
|
|
|
int __ret_warn_once = !!(condition); \
|
2006-10-06 07:43:49 +00:00
|
|
|
\
|
|
|
|
if (unlikely(__ret_warn_once)) \
|
|
|
|
if (WARN_ON(!__warned)) \
|
|
|
|
__warned = 1; \
|
|
|
|
unlikely(__ret_warn_once); \
|
2006-06-25 12:48:09 +00:00
|
|
|
})
|
|
|
|
|
2008-09-15 23:43:18 +00:00
|
|
|
#define WARN_ONCE(condition, format...) ({ \
|
|
|
|
static int __warned; \
|
|
|
|
int __ret_warn_once = !!(condition); \
|
|
|
|
\
|
|
|
|
if (unlikely(__ret_warn_once)) \
|
|
|
|
if (WARN(!__warned, format)) \
|
|
|
|
__warned = 1; \
|
|
|
|
unlikely(__ret_warn_once); \
|
|
|
|
})
|
|
|
|
|
2008-07-25 08:45:58 +00:00
|
|
|
#define WARN_ON_RATELIMIT(condition, state) \
|
|
|
|
WARN_ON((condition) && __ratelimit(state))
|
|
|
|
|
2006-06-27 09:54:50 +00:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
# define WARN_ON_SMP(x) WARN_ON(x)
|
|
|
|
#else
|
|
|
|
# define WARN_ON_SMP(x) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|