Subversion Repositories Kolibri OS

Rev

Rev 6082 | Rev 6936 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6082 Rev 6588
1
#ifndef _ASM_GENERIC_BUG_H
1
#ifndef _ASM_GENERIC_BUG_H
2
#define _ASM_GENERIC_BUG_H
2
#define _ASM_GENERIC_BUG_H
3
 
3
 
4
#include 
4
#include 
-
 
5
 
-
 
6
int printf(const char *fmt, ...);
5
 
7
 
6
#define __WARN()                printf("\nWARNING: at %s:%d\n", __FILE__, __LINE__)
8
#define __WARN()                printf("\nWARNING: at %s:%d\n", __FILE__, __LINE__)
7
//#define __WARN_printf(arg...)   printf("\nWARNING: at %s:%d\n", __FILE__, __LINE__)
9
//#define __WARN_printf(arg...)   printf("\nWARNING: at %s:%d\n", __FILE__, __LINE__)
8
#define __WARN_printf(arg...)   do { printf(arg); __WARN(); } while (0)
10
#define __WARN_printf(arg...)   do { printf(arg); __WARN(); } while (0)
9
 
11
 
10
#define WARN(condition, format...) ({                                   \
12
#define WARN(condition, format...) ({                                   \
11
        int __ret_warn_on = !!(condition);                              \
13
        int __ret_warn_on = !!(condition);                              \
12
        if (unlikely(__ret_warn_on))                                    \
14
        if (unlikely(__ret_warn_on))                                    \
13
            __WARN_printf(format);                                      \
15
            __WARN_printf(format);                                      \
14
        unlikely(__ret_warn_on);                                        \
16
        unlikely(__ret_warn_on);                                        \
15
})
17
})
16
 
18
 
17
 
19
 
18
#define WARN_ON(condition) ({                                           \
20
#define WARN_ON(condition) ({                                           \
19
        int __ret_warn_on = !!(condition);                              \
21
        int __ret_warn_on = !!(condition);                              \
20
        if (unlikely(__ret_warn_on))                                    \
22
        if (unlikely(__ret_warn_on))                                    \
21
                __WARN();                                               \
23
                __WARN();                                               \
22
        unlikely(__ret_warn_on);                                        \
24
        unlikely(__ret_warn_on);                                        \
23
})
25
})
24
 
26
 
25
 
27
 
26
#define WARN_ONCE(condition, format...) ({                      \
28
#define WARN_ONCE(condition, format...) ({                      \
27
        static bool __warned;                                   \
29
        static bool __warned;                                   \
28
        int __ret_warn_once = !!(condition);                    \
30
        int __ret_warn_once = !!(condition);                    \
29
                                                                \
31
                                                                \
30
        if (unlikely(__ret_warn_once))                          \
32
        if (unlikely(__ret_warn_once))                          \
31
                if (WARN(!__warned, format))                    \
33
                if (WARN(!__warned, format))                    \
32
                        __warned = true;                        \
34
                        __warned = true;                        \
33
        unlikely(__ret_warn_once);                              \
35
        unlikely(__ret_warn_once);                              \
34
})
36
})
35
 
37
 
36
 
38
 
37
#define WARN_ON_ONCE(condition) ({                              \
39
#define WARN_ON_ONCE(condition) ({                              \
38
        static bool __warned;                                   \
40
        static bool __warned;                                   \
39
        int __ret_warn_once = !!(condition);                    \
41
        int __ret_warn_once = !!(condition);                    \
40
                                                                \
42
                                                                \
41
        if (unlikely(__ret_warn_once))                          \
43
        if (unlikely(__ret_warn_once))                          \
42
                if (WARN_ON(!__warned))                         \
44
                if (WARN_ON(!__warned))                         \
43
                        __warned = true;                        \
45
                        __warned = true;                        \
44
        unlikely(__ret_warn_once);                              \
46
        unlikely(__ret_warn_once);                              \
45
})
47
})
46
 
48
 
47
#define BUG() do { \
49
#define BUG() do { \
48
         printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
50
         printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
49
 } while (0)
51
 } while (0)
50
 
52
 
51
#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
53
#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
52
 
54
 
53
/* Force a compilation error if a constant expression is not a power of 2 */
55
/* Force a compilation error if a constant expression is not a power of 2 */
54
#define BUILD_BUG_ON_NOT_POWER_OF_2(n)			\
56
#define BUILD_BUG_ON_NOT_POWER_OF_2(n)			\
55
	BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
57
	BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
56
 
58
 
57
/* Force a compilation error if condition is true, but also produce a
59
/* 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
60
   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
61
   e.g. in a structure initializer (or where-ever else comma expressions
60
   aren't permitted). */
62
   aren't permitted). */
61
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
63
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
62
#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
64
#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
63
 
65
 
64
/*
66
/*
65
 * BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the
67
 * 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
68
 * expression but avoids the generation of any code, even if that expression
67
 * has side-effects.
69
 * has side-effects.
68
 */
70
 */
69
#define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e))))
71
#define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e))))
70
 
72
 
71
/**
73
/**
72
 * BUILD_BUG_ON_MSG - break compile if a condition is true & emit supplied
74
 * BUILD_BUG_ON_MSG - break compile if a condition is true & emit supplied
73
 *		      error message.
75
 *		      error message.
74
 * @condition: the condition which the compiler should know is false.
76
 * @condition: the condition which the compiler should know is false.
75
 *
77
 *
76
 * See BUILD_BUG_ON for description.
78
 * See BUILD_BUG_ON for description.
77
 */
79
 */
78
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
80
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
79
 
81
 
80
/**
82
/**
81
 * BUILD_BUG_ON - break compile if a condition is true.
83
 * BUILD_BUG_ON - break compile if a condition is true.
82
 * @condition: the condition which the compiler should know is false.
84
 * @condition: the condition which the compiler should know is false.
83
 *
85
 *
84
 * If you have some code which relies on certain constants being equal, or
86
 * 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
87
 * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to
86
 * detect if someone changes it.
88
 * detect if someone changes it.
87
 *
89
 *
88
 * The implementation uses gcc's reluctance to create a negative array, but gcc
90
 * 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
91
 * (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
92
 * 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
93
 * 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
94
 * (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
95
 * 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
96
 * 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
97
 * compile-time error, we'll still have a link-time error, which is harder to
96
 * track down.
98
 * track down.
97
 */
99
 */
98
#ifndef __OPTIMIZE__
100
#ifndef __OPTIMIZE__
99
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
101
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
100
#else
102
#else
101
#define BUILD_BUG_ON(condition) \
103
#define BUILD_BUG_ON(condition) \
102
	BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
104
	BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
103
#endif
105
#endif
104
 
106
 
105
/**
107
/**
106
 * BUILD_BUG - break compile if used.
108
 * BUILD_BUG - break compile if used.
107
 *
109
 *
108
 * If you have some code that you expect the compiler to eliminate at
110
 * 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
111
 * build time, you should use BUILD_BUG to detect if it is
110
 * unexpectedly used.
112
 * unexpectedly used.
111
 */
113
 */
112
#define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
114
#define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
113
 
115
 
114
 
116
 
115
 
117
 
116
 
118
 
117
#define pr_warn_once(fmt, ...)                                  \
119
#define pr_warn_once(fmt, ...)                                  \
118
        printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
120
        printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
119
 
121
 
120
#endif
122
#endif