bug.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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_fmt(const char *file, const int line,
  55. const char *fmt, ...) __attribute__((format(printf, 3, 4)));
  56. extern void warn_slowpath_null(const char *file, const int line);
  57. #define WANT_WARN_ON_SLOWPATH
  58. #endif
  59. #define __WARN() warn_slowpath_null(__FILE__, __LINE__)
  60. #define __WARN_printf(arg...) warn_slowpath_fmt(__FILE__, __LINE__, arg)
  61. #else
  62. #define __WARN_printf(arg...) do { printk(arg); __WARN(); } while (0)
  63. #endif
  64. #ifndef WARN_ON
  65. #define WARN_ON(condition) ({ \
  66. int __ret_warn_on = !!(condition); \
  67. if (unlikely(__ret_warn_on)) \
  68. __WARN(); \
  69. unlikely(__ret_warn_on); \
  70. })
  71. #endif
  72. #ifndef WARN
  73. #define WARN(condition, format...) ({ \
  74. int __ret_warn_on = !!(condition); \
  75. if (unlikely(__ret_warn_on)) \
  76. __WARN_printf(format); \
  77. unlikely(__ret_warn_on); \
  78. })
  79. #endif
  80. #else /* !CONFIG_BUG */
  81. #ifndef HAVE_ARCH_BUG
  82. #define BUG() do {} while(0)
  83. #endif
  84. #ifndef HAVE_ARCH_BUG_ON
  85. #define BUG_ON(condition) do { if (condition) ; } while(0)
  86. #endif
  87. #ifndef HAVE_ARCH_WARN_ON
  88. #define WARN_ON(condition) ({ \
  89. int __ret_warn_on = !!(condition); \
  90. unlikely(__ret_warn_on); \
  91. })
  92. #endif
  93. #ifndef WARN
  94. #define WARN(condition, format...) ({ \
  95. int __ret_warn_on = !!(condition); \
  96. unlikely(__ret_warn_on); \
  97. })
  98. #endif
  99. #endif
  100. #define WARN_ON_ONCE(condition) ({ \
  101. static int __warned; \
  102. int __ret_warn_once = !!(condition); \
  103. \
  104. if (unlikely(__ret_warn_once)) \
  105. if (WARN_ON(!__warned)) \
  106. __warned = 1; \
  107. unlikely(__ret_warn_once); \
  108. })
  109. #define WARN_ONCE(condition, format...) ({ \
  110. static int __warned; \
  111. int __ret_warn_once = !!(condition); \
  112. \
  113. if (unlikely(__ret_warn_once)) \
  114. if (WARN(!__warned, format)) \
  115. __warned = 1; \
  116. unlikely(__ret_warn_once); \
  117. })
  118. #define WARN_ON_RATELIMIT(condition, state) \
  119. WARN_ON((condition) && __ratelimit(state))
  120. #ifdef CONFIG_SMP
  121. # define WARN_ON_SMP(x) WARN_ON(x)
  122. #else
  123. # define WARN_ON_SMP(x) do { } while (0)
  124. #endif
  125. #endif