2013-02-26 17:08:43 +04:00
|
|
|
#ifndef __CR_BUG_H__
|
|
|
|
#define __CR_BUG_H__
|
|
|
|
|
|
|
|
#include <signal.h>
|
2014-02-21 01:06:00 +04:00
|
|
|
#include <stdbool.h>
|
2013-02-26 17:08:43 +04:00
|
|
|
|
2016-10-24 14:58:02 +03:00
|
|
|
#include "common/compiler.h"
|
2013-02-26 17:08:43 +04:00
|
|
|
|
|
|
|
#ifndef BUG_ON_HANDLER
|
|
|
|
|
|
|
|
#ifdef CR_NOGLIBC
|
2021-07-19 07:39:51 +00:00
|
|
|
#define __raise()
|
2013-02-26 17:08:43 +04:00
|
|
|
#else
|
2021-07-19 07:39:51 +00:00
|
|
|
#define __raise() raise(SIGABRT)
|
2013-02-26 17:08:43 +04:00
|
|
|
#endif
|
|
|
|
|
2013-04-03 21:31:02 +04:00
|
|
|
#ifndef __clang_analyzer__
|
2021-07-19 07:39:51 +00:00
|
|
|
#ifndef pr_err
|
|
|
|
#error pr_err macro must be defined
|
|
|
|
#endif
|
|
|
|
#define BUG_ON_HANDLER(condition) \
|
|
|
|
do { \
|
|
|
|
if ((condition)) { \
|
|
|
|
pr_err("BUG at %s:%d\n", __FILE__, __LINE__); \
|
|
|
|
__raise(); \
|
|
|
|
*(volatile unsigned long *)NULL = 0xdead0000 + __LINE__; \
|
|
|
|
__builtin_unreachable(); \
|
|
|
|
} \
|
2013-02-26 17:08:43 +04:00
|
|
|
} while (0)
|
2013-04-03 21:31:02 +04:00
|
|
|
#else
|
2021-07-19 07:39:51 +00:00
|
|
|
#define BUG_ON_HANDLER(condition) \
|
|
|
|
do { \
|
|
|
|
assert(!condition); \
|
2013-04-03 21:31:02 +04:00
|
|
|
} while (0)
|
|
|
|
#endif
|
2013-02-26 17:08:43 +04:00
|
|
|
|
|
|
|
#endif /* BUG_ON_HANDLER */
|
|
|
|
|
2021-07-19 07:39:51 +00:00
|
|
|
#define BUG_ON(condition) BUG_ON_HANDLER((condition))
|
|
|
|
#define BUG() BUG_ON(true)
|
2013-02-26 17:08:43 +04:00
|
|
|
|
|
|
|
#endif /* __CR_BUG_H__ */
|