bug.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef _ASM_GENERIC_BUG_H
  2. #define _ASM_GENERIC_BUG_H
  3. #include <linux/compiler.h>
  4. #ifdef CONFIG_BUG
  5. #ifdef CONFIG_GENERIC_BUG
  6. #ifndef __ASSEMBLY__
  7. struct bug_entry {
  8. unsigned long bug_addr;
  9. #ifdef CONFIG_DEBUG_BUGVERBOSE
  10. const char *file;
  11. unsigned short line;
  12. #endif
  13. unsigned short flags;
  14. };
  15. #endif /* __ASSEMBLY__ */
  16. #define BUGFLAG_WARNING (1<<0)
  17. #endif /* CONFIG_GENERIC_BUG */
  18. #ifndef HAVE_ARCH_BUG
  19. #define BUG() do { \
  20. printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
  21. panic("BUG!"); \
  22. } while (0)
  23. #endif
  24. #ifndef HAVE_ARCH_BUG_ON
  25. #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
  26. #endif
  27. #ifndef __WARN
  28. #ifndef __ASSEMBLY__
  29. extern void warn_on_slowpath(const char *file, const int line);
  30. #define WANT_WARN_ON_SLOWPATH
  31. #endif
  32. #define __WARN() warn_on_slowpath(__FILE__, __LINE__)
  33. #endif
  34. #ifndef WARN_ON
  35. #define WARN_ON(condition) ({ \
  36. int __ret_warn_on = !!(condition); \
  37. if (unlikely(__ret_warn_on)) \
  38. __WARN(); \
  39. unlikely(__ret_warn_on); \
  40. })
  41. #endif
  42. #else /* !CONFIG_BUG */
  43. #ifndef HAVE_ARCH_BUG
  44. #define BUG()
  45. #endif
  46. #ifndef HAVE_ARCH_BUG_ON
  47. #define BUG_ON(condition) do { if (condition) ; } while(0)
  48. #endif
  49. #ifndef HAVE_ARCH_WARN_ON
  50. #define WARN_ON(condition) ({ \
  51. int __ret_warn_on = !!(condition); \
  52. unlikely(__ret_warn_on); \
  53. })
  54. #endif
  55. #endif
  56. #define WARN_ON_ONCE(condition) ({ \
  57. static int __warned; \
  58. int __ret_warn_once = !!(condition); \
  59. \
  60. if (unlikely(__ret_warn_once)) \
  61. if (WARN_ON(!__warned)) \
  62. __warned = 1; \
  63. unlikely(__ret_warn_once); \
  64. })
  65. #ifdef CONFIG_SMP
  66. # define WARN_ON_SMP(x) WARN_ON(x)
  67. #else
  68. # define WARN_ON_SMP(x) do { } while (0)
  69. #endif
  70. #endif