~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/bug.h

Version: ~ [ linux-5.3 ] ~ [ linux-5.2.15 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.73 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.144 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.193 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.193 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.73 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #ifndef _LINUX_BUG_H
  2 #define _LINUX_BUG_H
  3 
  4 #include <asm/bug.h>
  5 #include <linux/compiler.h>
  6 
  7 enum bug_trap_type {
  8         BUG_TRAP_TYPE_NONE = 0,
  9         BUG_TRAP_TYPE_WARN = 1,
 10         BUG_TRAP_TYPE_BUG = 2,
 11 };
 12 
 13 struct 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 #else /* __CHECKER__ */
 24 
 25 /* Force a compilation error if a constant expression is not a power of 2 */
 26 #define BUILD_BUG_ON_NOT_POWER_OF_2(n)                  \
 27         BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
 28 
 29 /* Force a compilation error if condition is true, but also produce a
 30    result (of value 0 and type size_t), so the expression can be used
 31    e.g. in a structure initializer (or where-ever else comma expressions
 32    aren't permitted). */
 33 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
 34 #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
 35 
 36 /*
 37  * BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the
 38  * expression but avoids the generation of any code, even if that expression
 39  * has side-effects.
 40  */
 41 #define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e))))
 42 
 43 /**
 44  * BUILD_BUG_ON_MSG - break compile if a condition is true & emit supplied
 45  *                    error message.
 46  * @condition: the condition which the compiler should know is false.
 47  *
 48  * See BUILD_BUG_ON for description.
 49  */
 50 #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
 51 
 52 /**
 53  * BUILD_BUG_ON - break compile if a condition is true.
 54  * @condition: the condition which the compiler should know is false.
 55  *
 56  * If you have some code which relies on certain constants being equal, or
 57  * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to
 58  * detect if someone changes it.
 59  *
 60  * The implementation uses gcc's reluctance to create a negative array, but gcc
 61  * (as of 4.4) only emits that error for obvious cases (e.g. not arguments to
 62  * inline functions).  Luckily, in 4.3 they added the "error" function
 63  * attribute just for this type of case.  Thus, we use a negative sized array
 64  * (should always create an error on gcc versions older than 4.4) and then call
 65  * an undefined function with the error attribute (should always create an
 66  * error on gcc 4.3 and later).  If for some reason, neither creates a
 67  * compile-time error, we'll still have a link-time error, which is harder to
 68  * track down.
 69  */
 70 #ifndef __OPTIMIZE__
 71 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
 72 #else
 73 #define BUILD_BUG_ON(condition) \
 74         BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
 75 #endif
 76 
 77 /**
 78  * BUILD_BUG - break compile if used.
 79  *
 80  * If you have some code that you expect the compiler to eliminate at
 81  * build time, you should use BUILD_BUG to detect if it is
 82  * unexpectedly used.
 83  */
 84 #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
 85 
 86 #endif  /* __CHECKER__ */
 87 
 88 #ifdef CONFIG_GENERIC_BUG
 89 #include <asm-generic/bug.h>
 90 
 91 static inline int is_warning_bug(const struct bug_entry *bug)
 92 {
 93         return bug->flags & BUGFLAG_WARNING;
 94 }
 95 
 96 const struct bug_entry *find_bug(unsigned long bugaddr);
 97 
 98 enum bug_trap_type report_bug(unsigned long bug_addr, struct pt_regs *regs);
 99 
100 /* These are defined by the architecture */
101 int is_valid_bugaddr(unsigned long addr);
102 
103 #else   /* !CONFIG_GENERIC_BUG */
104 
105 static inline enum bug_trap_type report_bug(unsigned long bug_addr,
106                                             struct pt_regs *regs)
107 {
108         return BUG_TRAP_TYPE_BUG;
109 }
110 
111 #endif  /* CONFIG_GENERIC_BUG */
112 #endif  /* _LINUX_BUG_H */
113 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp