bug.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
  9. unsigned long bug_addr;
  10. #else
  11. signed int bug_addr_disp;
  12. #endif
  13. #ifdef CONFIG_DEBUG_BUGVERBOSE
  14. #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
  15. const char *file;
  16. #else
  17. signed int file_disp;
  18. #endif
  19. unsigned short line;
  20. #endif
  21. unsigned short flags;
  22. };
  23. #endif /* __ASSEMBLY__ */
  24. #define BUGFLAG_WARNING (1<<0)
  25. #endif /* CONFIG_GENERIC_BUG */
  26. /*
  27. * Don't use BUG() or BUG_ON() unless there's really no way out; one
  28. * example might be detecting data structure corruption in the middle
  29. * of an operation that can't be backed out of. If the (sub)system
  30. * can somehow continue operating, perhaps with reduced functionality,
  31. * it's probably not BUG-worthy.
  32. *
  33. * If you're tempted to BUG(), think again: is completely giving up
  34. * really the *only* solution? There are usually better options, where
  35. * users don't need to reboot ASAP and can mostly shut down cleanly.
  36. */
  37. #ifndef HAVE_ARCH_BUG
  38. #define BUG() do { \
  39. printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
  40. panic("BUG!"); \
  41. } while (0)
  42. #endif
  43. #ifndef HAVE_ARCH_BUG_ON
  44. #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
  45. #endif
  46. /*
  47. * WARN(), WARN_ON(), WARN_ON_ONCE, and so on can be used to report
  48. * significant issues that need prompt attention if they should ever
  49. * appear at runtime. Use the versions with printk format strings
  50. * to provide better diagnostics.
  51. */
  52. #ifndef __WARN
  53. #ifndef __ASSEMBLY__
  54. extern void warn_slowpath(const char *file, const int line,
  55. const char *fmt, ...) __attribute__((format(printf, 3, 4)));
  56. #define WANT_WARN_ON_SLOWPATH
  57. #endif
  58. #define __WARN() warn_slowpath(__FILE__, __LINE__, NULL)
  59. #define __WARN_printf(arg...) warn_slowpath(__FILE__, __LINE__, arg)
  60. #else
  61. #define __WARN_printf(arg...) do { printk(arg); __WARN(); } while (0)
  62. #endif
  63. #ifndef WARN_ON
  64. #define WARN_ON(condition) ({ \
  65. int __ret_warn_on = !!(condition); \
  66. if (unlikely(__ret_warn_on)) \
  67. __WARN(); \
  68. unlikely(__ret_warn_on); \
  69. })
  70. #endif
  71. #ifndef WARN
  72. #define WARN(condition, format...) ({ \
  73. int __ret_warn_on = !!(condition); \
  74. if (unlikely(__ret_warn_on)) \
  75. __WARN_printf(format); \
  76. unlikely(__ret_warn_on); \
  77. })
  78. #endif
  79. #else /* !CONFIG_BUG */
  80. #ifndef HAVE_ARCH_BUG
  81. #define BUG()
  82. #endif
  83. #ifndef HAVE_ARCH_BUG_ON
  84. #define BUG_ON(condition) do { if (condition) ; } while(0)
  85. #endif
  86. #ifndef HAVE_ARCH_WARN_ON
  87. #define WARN_ON(condition) ({ \
  88. int __ret_warn_on = !!(condition); \
  89. unlikely(__ret_warn_on); \
  90. })
  91. #endif
  92. #ifndef WARN
  93. #define WARN(condition, format...) ({ \
  94. int __ret_warn_on = !!(condition); \
  95. unlikely(__ret_warn_on); \
  96. })
  97. #endif
  98. #endif
  99. #define WARN_ON_ONCE(condition) ({ \
  100. static int __warned; \
  101. int __ret_warn_once = !!(condition); \
  102. \
  103. if (unlikely(__ret_warn_once)) \
  104. if (WARN_ON(!__warned)) \
  105. __warned = 1; \
  106. unlikely(__ret_warn_once); \
  107. })
  108. #define WARN_ONCE(condition, format...) ({ \
  109. static int __warned; \
  110. int __ret_warn_once = !!(condition); \
  111. \
  112. if (unlikely(__ret_warn_once)) \
  113. if (WARN(!__warned, format)) \
  114. __warned = 1; \
  115. unlikely(__ret_warn_once); \
  116. })
  117. #define WARN_ON_RATELIMIT(condition, state) \
  118. WARN_ON((condition) && __ratelimit(state))
  119. #ifdef CONFIG_SMP
  120. # define WARN_ON_SMP(x) WARN_ON(x)
  121. #else
  122. # define WARN_ON_SMP(x) do { } while (0)
  123. #endif
  124. #endif