1 #ifndef __TOOLS_LINUX_BUG_H
2 #define __TOOLS_LINUX_BUG_H
5 #include <linux/compiler.h>
8 #include <valgrind/memcheck.h>
10 #define DEBUG_MEMORY_FREED(p, len) VALGRIND_MAKE_MEM_UNDEFINED(p, len)
13 #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
14 BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
15 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
16 #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
18 #define BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2*!!(cond)]))
20 #define BUG() do { fflush(stdout); assert(0); unreachable(); } while (0)
21 #define BUG_ON(cond) assert(!(cond))
23 #define WARN(cond, fmt, ...) \
25 int __ret_warn_on = unlikely(!!(cond)); \
27 fprintf(stderr, "WARNING at " __FILE__ ":%d: " fmt "\n",\
28 __LINE__, ##__VA_ARGS__); \
34 fprintf(stderr, "WARNING at " __FILE__ ":%d\n", __LINE__); \
37 #define WARN_ON(cond) ({ \
38 int __ret_warn_on = unlikely(!!(cond)); \
44 #define WARN_ONCE(cond, fmt, ...) \
46 static bool __warned; \
47 int __ret_warn_on = unlikely(!!(cond)); \
48 if (__ret_warn_on && !__warned) { \
55 #define WARN_ON_ONCE(cond) ({ \
56 static bool __warned; \
57 int __ret_warn_on = unlikely(!!(cond)); \
58 if (__ret_warn_on && !__warned) { \
65 #endif /* __TOOLS_LINUX_BUG_H */