bug.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef _LINUX_BUG_H
  2. #define _LINUX_BUG_H
  3. #include <asm/bug.h>
  4. #include <linux/compiler.h>
  5. #include <linux/build_bug.h>
  6. enum bug_trap_type {
  7. BUG_TRAP_TYPE_NONE = 0,
  8. BUG_TRAP_TYPE_WARN = 1,
  9. BUG_TRAP_TYPE_BUG = 2,
  10. };
  11. struct pt_regs;
  12. #ifdef __CHECKER__
  13. #define MAYBE_BUILD_BUG_ON(cond) (0)
  14. #else /* __CHECKER__ */
  15. #define MAYBE_BUILD_BUG_ON(cond) \
  16. do { \
  17. if (__builtin_constant_p((cond))) \
  18. BUILD_BUG_ON(cond); \
  19. else \
  20. BUG_ON(cond); \
  21. } while (0)
  22. #endif /* __CHECKER__ */
  23. #ifdef CONFIG_GENERIC_BUG
  24. #include <asm-generic/bug.h>
  25. static inline int is_warning_bug(const struct bug_entry *bug)
  26. {
  27. return bug->flags & BUGFLAG_WARNING;
  28. }
  29. struct bug_entry *find_bug(unsigned long bugaddr);
  30. enum bug_trap_type report_bug(unsigned long bug_addr, struct pt_regs *regs);
  31. /* These are defined by the architecture */
  32. int is_valid_bugaddr(unsigned long addr);
  33. #else /* !CONFIG_GENERIC_BUG */
  34. static inline enum bug_trap_type report_bug(unsigned long bug_addr,
  35. struct pt_regs *regs)
  36. {
  37. return BUG_TRAP_TYPE_BUG;
  38. }
  39. #endif /* CONFIG_GENERIC_BUG */
  40. /*
  41. * Since detected data corruption should stop operation on the affected
  42. * structures. Return value must be checked and sanely acted on by caller.
  43. */
  44. static inline __must_check bool check_data_corruption(bool v) { return v; }
  45. #define CHECK_DATA_CORRUPTION(condition, fmt, ...) \
  46. check_data_corruption(({ \
  47. bool corruption = unlikely(condition); \
  48. if (corruption) { \
  49. if (IS_ENABLED(CONFIG_BUG_ON_DATA_CORRUPTION)) { \
  50. pr_err(fmt, ##__VA_ARGS__); \
  51. BUG(); \
  52. } else \
  53. WARN(1, fmt, ##__VA_ARGS__); \
  54. } \
  55. corruption; \
  56. }))
  57. #endif /* _LINUX_BUG_H */