Rev 5056 | Rev 6588 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5056 | Rev 5270 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #ifndef _ASM_GENERIC_BUG_H |
1 | #ifndef _ASM_GENERIC_BUG_H |
2 | #define _ASM_GENERIC_BUG_H |
2 | #define _ASM_GENERIC_BUG_H |
Line 3... | Line -... | ||
3 | - | ||
4 | //extern __printf(3, 4) |
- | |
5 | //void warn_slowpath_fmt(const char *file, const int line, |
- | |
6 | // const char *fmt, ...); |
3 | |
7 | //extern __printf(4, 5) |
- | |
8 | //void warn_slowpath_fmt_taint(const char *file, const int line, unsigned taint, |
- | |
9 | // const char *fmt, ...); |
- | |
10 | - | ||
Line 11... | Line 4... | ||
11 | //extern void warn_slowpath_null(const char *file, const int line); |
4 | #include |
12 | 5 | ||
13 | #define __WARN() printf("\nWARNING: at %s:%d\n", __FILE__, __LINE__) |
6 | #define __WARN() printf("\nWARNING: at %s:%d\n", __FILE__, __LINE__) |
Line 59... | Line 52... | ||
59 | 52 | ||
60 | /* Force a compilation error if a constant expression is not a power of 2 */ |
53 | /* Force a compilation error if a constant expression is not a power of 2 */ |
61 | #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ |
54 | #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ |
Line -... | Line 55... | ||
- | 55 | BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) |
|
- | 56 | ||
- | 57 | /* Force a compilation error if condition is true, but also produce a |
|
- | 58 | result (of value 0 and type size_t), so the expression can be used |
|
- | 59 | e.g. in a structure initializer (or where-ever else comma expressions |
|
- | 60 | aren't permitted). */ |
|
- | 61 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) |
|
- | 62 | #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) |
|
- | 63 | ||
- | 64 | /* |
|
- | 65 | * BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the |
|
- | 66 | * expression but avoids the generation of any code, even if that expression |
|
- | 67 | * has side-effects. |
|
- | 68 | */ |
|
- | 69 | #define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e)))) |
|
- | 70 | ||
- | 71 | /** |
|
- | 72 | * BUILD_BUG_ON_MSG - break compile if a condition is true & emit supplied |
|
- | 73 | * error message. |
|
- | 74 | * @condition: the condition which the compiler should know is false. |
|
- | 75 | * |
|
- | 76 | * See BUILD_BUG_ON for description. |
|
- | 77 | */ |
|
- | 78 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) |
|
- | 79 | ||
- | 80 | /** |
|
- | 81 | * BUILD_BUG_ON - break compile if a condition is true. |
|
- | 82 | * @condition: the condition which the compiler should know is false. |
|
- | 83 | * |
|
- | 84 | * If you have some code which relies on certain constants being equal, or |
|
- | 85 | * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to |
|
- | 86 | * detect if someone changes it. |
|
- | 87 | * |
|
- | 88 | * The implementation uses gcc's reluctance to create a negative array, but gcc |
|
- | 89 | * (as of 4.4) only emits that error for obvious cases (e.g. not arguments to |
|
- | 90 | * inline functions). Luckily, in 4.3 they added the "error" function |
|
- | 91 | * attribute just for this type of case. Thus, we use a negative sized array |
|
- | 92 | * (should always create an error on gcc versions older than 4.4) and then call |
|
- | 93 | * an undefined function with the error attribute (should always create an |
|
- | 94 | * error on gcc 4.3 and later). If for some reason, neither creates a |
|
- | 95 | * compile-time error, we'll still have a link-time error, which is harder to |
|
- | 96 | * track down. |
|
- | 97 | */ |
|
- | 98 | #ifndef __OPTIMIZE__ |
|
- | 99 | #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) |
|
- | 100 | #else |
|
- | 101 | #define BUILD_BUG_ON(condition) \ |
|
- | 102 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) |
|
- | 103 | #endif |
|
- | 104 | ||
- | 105 | /** |
|
- | 106 | * BUILD_BUG - break compile if used. |
|
- | 107 | * |
|
- | 108 | * If you have some code that you expect the compiler to eliminate at |
|
- | 109 | * build time, you should use BUILD_BUG to detect if it is |
|
- | 110 | * unexpectedly used. |
|
- | 111 | */ |
|
Line 62... | Line -... | ||
62 | BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) |
- | |
63 | - | ||
64 | - | ||
65 | #define printk_once(fmt, ...) \ |
- | |
66 | ({ \ |
- | |
67 | static bool __print_once; \ |
- | |
68 | \ |
- | |
69 | if (!__print_once) { \ |
- | |
70 | __print_once = true; \ |
- | |
Line 71... | Line 112... | ||
71 | printk(fmt, ##__VA_ARGS__); \ |
112 | #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed") |
72 | } \ |
113 |