bug.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #ifndef HAVE_ARCH_BUG
  27. #define BUG() do { \
  28. printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
  29. panic("BUG!"); \
  30. } while (0)
  31. #endif
  32. #ifndef HAVE_ARCH_BUG_ON
  33. #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
  34. #endif
  35. #ifndef __WARN
  36. #ifndef __ASSEMBLY__
  37. extern void warn_on_slowpath(const char *file, const int line);
  38. extern void warn_slowpath(const char *file, const int line,
  39. const char *fmt, ...) __attribute__((format(printf, 3, 4)));
  40. #define WANT_WARN_ON_SLOWPATH
  41. #endif
  42. #define __WARN() warn_on_slowpath(__FILE__, __LINE__)
  43. #define __WARN_printf(arg...) warn_slowpath(__FILE__, __LINE__, arg)
  44. #else
  45. #define __WARN_printf(arg...) do { printk(arg); __WARN(); } while (0)
  46. #endif
  47. #ifndef WARN_ON
  48. #define WARN_ON(condition) ({ \
  49. int __ret_warn_on = !!(condition); \
  50. if (unlikely(__ret_warn_on)) \
  51. __WARN(); \
  52. unlikely(__ret_warn_on); \
  53. })
  54. #endif
  55. #ifndef WARN
  56. #define WARN(condition, format...) ({ \
  57. int __ret_warn_on = !!(condition); \
  58. if (unlikely(__ret_warn_on)) \
  59. __WARN_printf(format); \
  60. unlikely(__ret_warn_on); \
  61. })
  62. #endif
  63. #else /* !CONFIG_BUG */
  64. #ifndef HAVE_ARCH_BUG
  65. #define BUG()
  66. #endif
  67. #ifndef HAVE_ARCH_BUG_ON
  68. #define BUG_ON(condition) do { if (condition) ; } while(0)
  69. #endif
  70. #ifndef HAVE_ARCH_WARN_ON
  71. #define WARN_ON(condition) ({ \
  72. int __ret_warn_on = !!(condition); \
  73. unlikely(__ret_warn_on); \
  74. })
  75. #endif
  76. #ifndef WARN
  77. #define WARN(condition, format...) ({ \
  78. int __ret_warn_on = !!(condition); \
  79. unlikely(__ret_warn_on); \
  80. })
  81. #endif
  82. #endif
  83. #define WARN_ON_ONCE(condition) ({ \
  84. static int __warned; \
  85. int __ret_warn_once = !!(condition); \
  86. \
  87. if (unlikely(__ret_warn_once)) \
  88. if (WARN_ON(!__warned)) \
  89. __warned = 1; \
  90. unlikely(__ret_warn_once); \
  91. })
  92. #define WARN_ONCE(condition, format...) ({ \
  93. static int __warned; \
  94. int __ret_warn_once = !!(condition); \
  95. \
  96. if (unlikely(__ret_warn_once)) \
  97. if (WARN(!__warned, format)) \
  98. __warned = 1; \
  99. unlikely(__ret_warn_once); \
  100. })
  101. #define WARN_ON_RATELIMIT(condition, state) \
  102. WARN_ON((condition) && __ratelimit(state))
  103. #ifdef CONFIG_SMP
  104. # define WARN_ON_SMP(x) WARN_ON(x)
  105. #else
  106. # define WARN_ON_SMP(x) do { } while (0)
  107. #endif
  108. #endif