Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_BUG_H
0003 #define _LINUX_BUG_H
0004 
0005 #include <asm/bug.h>
0006 #include <linux/compiler.h>
0007 #include <linux/build_bug.h>
0008 
0009 enum bug_trap_type {
0010     BUG_TRAP_TYPE_NONE = 0,
0011     BUG_TRAP_TYPE_WARN = 1,
0012     BUG_TRAP_TYPE_BUG = 2,
0013 };
0014 
0015 struct pt_regs;
0016 
0017 #ifdef __CHECKER__
0018 #define MAYBE_BUILD_BUG_ON(cond) (0)
0019 #else /* __CHECKER__ */
0020 
0021 #define MAYBE_BUILD_BUG_ON(cond)            \
0022     do {                        \
0023         if (__builtin_constant_p((cond)))       \
0024             BUILD_BUG_ON(cond);             \
0025         else                                    \
0026             BUG_ON(cond);                   \
0027     } while (0)
0028 
0029 #endif  /* __CHECKER__ */
0030 
0031 #ifdef CONFIG_GENERIC_BUG
0032 #include <asm-generic/bug.h>
0033 
0034 static inline int is_warning_bug(const struct bug_entry *bug)
0035 {
0036     return bug->flags & BUGFLAG_WARNING;
0037 }
0038 
0039 void bug_get_file_line(struct bug_entry *bug, const char **file,
0040                unsigned int *line);
0041 
0042 struct bug_entry *find_bug(unsigned long bugaddr);
0043 
0044 enum bug_trap_type report_bug(unsigned long bug_addr, struct pt_regs *regs);
0045 
0046 /* These are defined by the architecture */
0047 int is_valid_bugaddr(unsigned long addr);
0048 
0049 void generic_bug_clear_once(void);
0050 
0051 #else   /* !CONFIG_GENERIC_BUG */
0052 
0053 static inline void *find_bug(unsigned long bugaddr)
0054 {
0055     return NULL;
0056 }
0057 
0058 static inline enum bug_trap_type report_bug(unsigned long bug_addr,
0059                         struct pt_regs *regs)
0060 {
0061     return BUG_TRAP_TYPE_BUG;
0062 }
0063 
0064 struct bug_entry;
0065 static inline void bug_get_file_line(struct bug_entry *bug, const char **file,
0066                      unsigned int *line)
0067 {
0068     *file = NULL;
0069     *line = 0;
0070 }
0071 
0072 static inline void generic_bug_clear_once(void) {}
0073 
0074 #endif  /* CONFIG_GENERIC_BUG */
0075 
0076 /*
0077  * Since detected data corruption should stop operation on the affected
0078  * structures. Return value must be checked and sanely acted on by caller.
0079  */
0080 static inline __must_check bool check_data_corruption(bool v) { return v; }
0081 #define CHECK_DATA_CORRUPTION(condition, fmt, ...)           \
0082     check_data_corruption(({                     \
0083         bool corruption = unlikely(condition);           \
0084         if (corruption) {                    \
0085             if (IS_ENABLED(CONFIG_BUG_ON_DATA_CORRUPTION)) { \
0086                 pr_err(fmt, ##__VA_ARGS__);      \
0087                 BUG();                   \
0088             } else                       \
0089                 WARN(1, fmt, ##__VA_ARGS__);         \
0090         }                            \
0091         corruption;                      \
0092     }))
0093 
0094 #endif  /* _LINUX_BUG_H */