Subversion Repositories Kolibri OS

Rev

Rev 5056 | Rev 6082 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef _ASM_GENERIC_BUG_H
  2. #define _ASM_GENERIC_BUG_H
  3.  
  4. #include <linux/compiler.h>
  5.  
  6. #define __WARN()                printf("\nWARNING: at %s:%d\n", __FILE__, __LINE__)
  7. //#define __WARN_printf(arg...)   printf("\nWARNING: at %s:%d\n", __FILE__, __LINE__)
  8. #define __WARN_printf(arg...)   do { printf(arg); __WARN(); } while (0)
  9.  
  10. #define WARN(condition, format...) ({                                   \
  11.         int __ret_warn_on = !!(condition);                              \
  12.         if (unlikely(__ret_warn_on))                                    \
  13.             __WARN_printf(format);                                      \
  14.         unlikely(__ret_warn_on);                                        \
  15. })
  16.  
  17.  
  18. #define WARN_ON(condition) ({                                           \
  19.         int __ret_warn_on = !!(condition);                              \
  20.         if (unlikely(__ret_warn_on))                                    \
  21.                 __WARN();                                               \
  22.         unlikely(__ret_warn_on);                                        \
  23. })
  24.  
  25.  
  26. #define WARN_ONCE(condition, format...) ({                      \
  27.         static bool __warned;                                   \
  28.         int __ret_warn_once = !!(condition);                    \
  29.                                                                 \
  30.         if (unlikely(__ret_warn_once))                          \
  31.                 if (WARN(!__warned, format))                    \
  32.                         __warned = true;                        \
  33.         unlikely(__ret_warn_once);                              \
  34. })
  35.  
  36.  
  37. #define WARN_ON_ONCE(condition) ({                              \
  38.         static bool __warned;                                   \
  39.         int __ret_warn_once = !!(condition);                    \
  40.                                                                 \
  41.         if (unlikely(__ret_warn_once))                          \
  42.                 if (WARN_ON(!__warned))                         \
  43.                         __warned = true;                        \
  44.         unlikely(__ret_warn_once);                              \
  45. })
  46.  
  47. #define BUG() do { \
  48.          printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
  49.  } while (0)
  50.  
  51. #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
  52.  
  53. /* Force a compilation error if a constant expression is not a power of 2 */
  54. #define BUILD_BUG_ON_NOT_POWER_OF_2(n)                  \
  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.  */
  112. #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
  113.  
  114.  
  115.  
  116.  
  117. #define pr_warn_once(fmt, ...)                                  \
  118.         printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
  119.  
  120. #endif
  121.