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