2017-01-08 12:13:18 +03:00
|
|
|
#ifndef __TOOLS_LINUX_BUG_H
|
|
|
|
#define __TOOLS_LINUX_BUG_H
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <linux/compiler.h>
|
2019-12-05 01:49:34 +03:00
|
|
|
|
|
|
|
#ifdef CONFIG_VALGRIND
|
2019-10-05 02:25:50 +03:00
|
|
|
#include <valgrind/memcheck.h>
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2019-12-05 01:49:34 +03:00
|
|
|
#define DEBUG_MEMORY_FREED(p, len) VALGRIND_MAKE_MEM_UNDEFINED(p, len)
|
|
|
|
#endif
|
|
|
|
|
2017-01-08 12:13:18 +03:00
|
|
|
#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
|
|
|
|
BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
|
|
|
|
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
|
|
|
|
#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
|
|
|
|
|
2019-03-08 22:41:43 +03:00
|
|
|
#define BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2*!!(cond)]))
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2022-03-31 06:20:39 +03:00
|
|
|
#define BUG() do { fflush(stdout); assert(0); unreachable(); } while (0)
|
2017-01-08 12:13:18 +03:00
|
|
|
#define BUG_ON(cond) assert(!(cond))
|
|
|
|
|
2019-03-08 22:41:43 +03:00
|
|
|
#define WARN(cond, fmt, ...) \
|
|
|
|
({ \
|
|
|
|
int __ret_warn_on = unlikely(!!(cond)); \
|
|
|
|
if (__ret_warn_on) \
|
|
|
|
fprintf(stderr, "WARNING at " __FILE__ ":%d: " fmt "\n",\
|
|
|
|
__LINE__, ##__VA_ARGS__); \
|
|
|
|
__ret_warn_on; \
|
|
|
|
})
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2021-05-17 23:47:05 +03:00
|
|
|
#define __WARN() \
|
|
|
|
do { \
|
|
|
|
fprintf(stderr, "WARNING at " __FILE__ ":%d\n", __LINE__); \
|
|
|
|
} while (0)
|
|
|
|
|
2019-03-08 22:41:43 +03:00
|
|
|
#define WARN_ON(cond) ({ \
|
|
|
|
int __ret_warn_on = unlikely(!!(cond)); \
|
2017-04-04 11:28:13 +03:00
|
|
|
if (__ret_warn_on) \
|
2021-05-17 23:47:05 +03:00
|
|
|
__WARN(); \
|
2019-03-08 22:41:43 +03:00
|
|
|
__ret_warn_on; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define WARN_ONCE(cond, fmt, ...) \
|
|
|
|
({ \
|
|
|
|
static bool __warned; \
|
|
|
|
int __ret_warn_on = unlikely(!!(cond)); \
|
|
|
|
if (__ret_warn_on && !__warned) { \
|
|
|
|
__warned = true; \
|
2021-05-17 23:47:05 +03:00
|
|
|
__WARN(); \
|
2019-03-08 22:41:43 +03:00
|
|
|
} \
|
|
|
|
__ret_warn_on; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define WARN_ON_ONCE(cond) ({ \
|
|
|
|
static bool __warned; \
|
|
|
|
int __ret_warn_on = unlikely(!!(cond)); \
|
|
|
|
if (__ret_warn_on && !__warned) { \
|
|
|
|
__warned = true; \
|
2021-05-17 23:47:05 +03:00
|
|
|
__WARN(); \
|
2019-03-08 22:41:43 +03:00
|
|
|
} \
|
2017-04-04 11:28:13 +03:00
|
|
|
__ret_warn_on; \
|
2017-01-08 12:13:18 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
#endif /* __TOOLS_LINUX_BUG_H */
|