1#ifndef _LINUX_BUG_H
2#define _LINUX_BUG_H
3
4#include <asm/bug.h>
5#include <linux/compiler.h>
6
7enum bug_trap_type {
8 BUG_TRAP_TYPE_NONE = 0,
9 BUG_TRAP_TYPE_WARN = 1,
10 BUG_TRAP_TYPE_BUG = 2,
11};
12
13struct pt_regs;
14
15#ifdef __CHECKER__
16#define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)
17#define BUILD_BUG_ON_ZERO(e) (0)
18#define BUILD_BUG_ON_NULL(e) ((void*)0)
19#define BUILD_BUG_ON_INVALID(e) (0)
20#define BUILD_BUG_ON_MSG(cond, msg) (0)
21#define BUILD_BUG_ON(condition) (0)
22#define BUILD_BUG() (0)
23#define MAYBE_BUILD_BUG_ON(cond) (0)
24#else
25
26
27#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
28 BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
29
30
31
32
33
34#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
35#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
36
37
38
39
40
41
42#define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e))))
43
44
45
46
47
48
49
50
51#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71#ifndef __OPTIMIZE__
72#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
73#else
74#define BUILD_BUG_ON(condition) \
75 BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
76#endif
77
78
79
80
81
82
83
84
85#define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
86
87#define MAYBE_BUILD_BUG_ON(cond) \
88 do { \
89 if (__builtin_constant_p((cond))) \
90 BUILD_BUG_ON(cond); \
91 else \
92 BUG_ON(cond); \
93 } while (0)
94
95#endif
96
97#ifdef CONFIG_GENERIC_BUG
98#include <asm-generic/bug.h>
99
100static inline int is_warning_bug(const struct bug_entry *bug)
101{
102 return bug->flags & BUGFLAG_WARNING;
103}
104
105const struct bug_entry *find_bug(unsigned long bugaddr);
106
107enum bug_trap_type report_bug(unsigned long bug_addr, struct pt_regs *regs);
108
109
110int is_valid_bugaddr(unsigned long addr);
111
112#else
113
114static inline enum bug_trap_type report_bug(unsigned long bug_addr,
115 struct pt_regs *regs)
116{
117 return BUG_TRAP_TYPE_BUG;
118}
119
120#endif
121#endif
122