Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bug.h
Go to the documentation of this file.
1 #ifndef _LINUX_BUG_H
2 #define _LINUX_BUG_H
3 
4 #include <asm/bug.h>
5 
10 };
11 
12 struct pt_regs;
13 
14 #ifdef __CHECKER__
15 #define BUILD_BUG_ON_NOT_POWER_OF_2(n)
16 #define BUILD_BUG_ON_ZERO(e) (0)
17 #define BUILD_BUG_ON_NULL(e) ((void*)0)
18 #define BUILD_BUG_ON_INVALID(e) (0)
19 #define BUILD_BUG_ON(condition)
20 #define BUILD_BUG() (0)
21 #else /* __CHECKER__ */
22 
23 /* Force a compilation error if a constant expression is not a power of 2 */
24 #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
25  BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
26 
27 /* Force a compilation error if condition is true, but also produce a
28  result (of value 0 and type size_t), so the expression can be used
29  e.g. in a structure initializer (or where-ever else comma expressions
30  aren't permitted). */
31 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
32 #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
33 
34 /*
35  * BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the
36  * expression but avoids the generation of any code, even if that expression
37  * has side-effects.
38  */
39 #define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e))))
40 
56 #ifndef __OPTIMIZE__
57 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
58 #else
59 extern int __build_bug_on_failed;
60 #define BUILD_BUG_ON(condition) \
61  do { \
62  ((void)sizeof(char[1 - 2*!!(condition)])); \
63  if (condition) __build_bug_on_failed = 1; \
64  } while(0)
65 #endif
66 
74 #define BUILD_BUG() \
75  do { \
76  extern void __build_bug_failed(void) \
77  __linktime_error("BUILD_BUG failed"); \
78  __build_bug_failed(); \
79  } while (0)
80 
81 #endif /* __CHECKER__ */
82 
83 #ifdef CONFIG_GENERIC_BUG
84 #include <asm-generic/bug.h>
85 
86 static inline int is_warning_bug(const struct bug_entry *bug)
87 {
88  return bug->flags & BUGFLAG_WARNING;
89 }
90 
91 const struct bug_entry *find_bug(unsigned long bugaddr);
92 
93 enum bug_trap_type report_bug(unsigned long bug_addr, struct pt_regs *regs);
94 
95 /* These are defined by the architecture */
96 int is_valid_bugaddr(unsigned long addr);
97 
98 #else /* !CONFIG_GENERIC_BUG */
99 
100 static inline enum bug_trap_type report_bug(unsigned long bug_addr,
101  struct pt_regs *regs)
102 {
103  return BUG_TRAP_TYPE_BUG;
104 }
105 
106 #endif /* CONFIG_GENERIC_BUG */
107 #endif /* _LINUX_BUG_H */