Basic POSIX signal handling (XCC)
[akaros.git] / user / parlib / include / rassert.h
1 /* See COPYRIGHT for copyright information. */
2
3 #ifndef ROS_INC_ASSERT_H
4 #define ROS_INC_ASSERT_H
5
6 #include <assert.h>
7 #include <vcore.h>
8 #include <ros_debug.h>
9 #undef assert
10
11 void _warn(const char*, int, const char*, ...);
12 void _panic(const char*, int, const char*, ...) __attribute__((noreturn));
13
14 #define warn(...) _warn(__FILE__, __LINE__, __VA_ARGS__)
15 #define panic(...) _panic(__FILE__, __LINE__, __VA_ARGS__)
16
17 #define assert(x)                                                                  \
18         do {                                                                       \
19                 if (!(x)) {                                                            \
20                         ros_debug("[user] %s:%d, vcore %d, Assertion failed: %s\n",        \
21                                   __FILE__, __LINE__, vcore_id(), #x);                     \
22                         breakpoint();                                                      \
23                         abort();                                                           \
24                 }                                                                      \
25         } while (0)
26
27 // static_assert(x) will generate a compile-time error if 'x' is false.
28 #define static_assert(x)        switch (x) case 0: case (x):
29
30 #endif /* !ROS_INC_ASSERT_H */