1 #ifndef __TOOLS_LINUX_BUG_H
2 #define __TOOLS_LINUX_BUG_H
6 #include <linux/compiler.h>
9 #include <valgrind/memcheck.h>
11 #define DEBUG_MEMORY_FREED(p, len) VALGRIND_MAKE_MEM_UNDEFINED(p, len)
14 #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
15 BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
16 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
17 #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
19 #define BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2*!!(cond)]))
21 #define BUG() do { fflush(stdout); assert(0); unreachable(); } while (0)
22 #define BUG_ON(cond) assert(!(cond))
24 #define WARN(cond, fmt, ...) \
26 int __ret_warn_on = unlikely(!!(cond)); \
28 fprintf(stderr, "WARNING at " __FILE__ ":%d: " fmt "\n",\
29 __LINE__, ##__VA_ARGS__); \
35 fprintf(stderr, "WARNING at " __FILE__ ":%d\n", __LINE__); \
38 #define WARN_ON(cond) ({ \
39 int __ret_warn_on = unlikely(!!(cond)); \
45 #define WARN_ONCE(cond, fmt, ...) \
47 static bool __warned; \
48 int __ret_warn_on = unlikely(!!(cond)); \
49 if (__ret_warn_on && !__warned) { \
56 #define WARN_ON_ONCE(cond) ({ \
57 static bool __warned; \
58 int __ret_warn_on = unlikely(!!(cond)); \
59 if (__ret_warn_on && !__warned) { \
66 #endif /* __TOOLS_LINUX_BUG_H */