| 1 | #include <console/crash.h> |
| 2 | #include <console/printf.h> |
| 3 | #include <stdarg.h> |
| 4 | #include <string.h> |
| 5 | |
| 6 | __noreturn void assert_impl_default(struct crash_payload pluh, const char *file, |
| 7 | int line, const char *func, const char *fmt, |
| 8 | ...) { |
| 9 | unused(pluh); |
| 10 | static char msg[CRASH_MSG_MAX]; |
| 11 | va_list args; |
| 12 | va_start(args, fmt); |
| 13 | vsnprintf(buffer: msg, buffer_len: sizeof(msg), format: fmt, args); |
| 14 | va_end(args); |
| 15 | |
| 16 | crash_full(ctx: &(struct crash_context){ |
| 17 | .payload = pluh, |
| 18 | .source = CRASH_SOURCE_ASSERT, |
| 19 | .formats = CRASH_FMT_DEFAULT, |
| 20 | .file = file, |
| 21 | .line = line, |
| 22 | .func = func, |
| 23 | .msg = msg, |
| 24 | }); |
| 25 | } |
| 26 | |
| 27 | __noreturn void assert_impl_assertion(struct crash_payload pluh, |
| 28 | const char *file, int line, |
| 29 | const char *func, const char *prefix, |
| 30 | const char *assertion, const char *fmt, |
| 31 | ...) { |
| 32 | unused(pluh); |
| 33 | static char msg[CRASH_MSG_MAX]; |
| 34 | |
| 35 | int n = snprintf(buffer: msg, buffer_len: sizeof(msg), format: "%s%s" , prefix ? prefix : "" , |
| 36 | assertion ? assertion : "" ); |
| 37 | |
| 38 | if (n < 0) |
| 39 | n = 0; |
| 40 | if (n > (int) sizeof(msg) - 1) |
| 41 | n = (int) sizeof(msg) - 1; |
| 42 | |
| 43 | if (fmt) { |
| 44 | n += snprintf(buffer: msg + n, buffer_len: (int) sizeof(msg) - n, format: ": " ); |
| 45 | if (n > (int) sizeof(msg) - 1) |
| 46 | n = (int) sizeof(msg) - 1; |
| 47 | |
| 48 | va_list args; |
| 49 | va_start(args, fmt); |
| 50 | vsnprintf(buffer: msg + n, buffer_len: (int) sizeof(msg) - n, format: fmt, args); |
| 51 | va_end(args); |
| 52 | } |
| 53 | |
| 54 | crash_full(ctx: &(struct crash_context){ |
| 55 | .payload = pluh, |
| 56 | .source = CRASH_SOURCE_ASSERT, |
| 57 | .formats = CRASH_FMT_DEFAULT, |
| 58 | .file = file, |
| 59 | .line = line, |
| 60 | .func = func, |
| 61 | .msg = msg, |
| 62 | }); |
| 63 | } |
| 64 | |