Subversion Repositories Kolibri OS

Rev

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