diff options
-rw-r--r-- | firmware/buflib.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/firmware/buflib.c b/firmware/buflib.c index 0a87a4c4d8..f6a565715d 100644 --- a/firmware/buflib.c +++ b/firmware/buflib.c | |||
@@ -25,6 +25,7 @@ | |||
25 | * | 25 | * |
26 | ****************************************************************************/ | 26 | ****************************************************************************/ |
27 | 27 | ||
28 | #include <stdarg.h> | ||
28 | #include <stdlib.h> /* for abs() */ | 29 | #include <stdlib.h> /* for abs() */ |
29 | #include <stdio.h> /* for snprintf() */ | 30 | #include <stdio.h> /* for snprintf() */ |
30 | #include <stddef.h> /* for ptrdiff_t */ | 31 | #include <stddef.h> /* for ptrdiff_t */ |
@@ -92,6 +93,8 @@ | |||
92 | #define BDEBUGF(...) do { } while(0) | 93 | #define BDEBUGF(...) do { } while(0) |
93 | #endif | 94 | #endif |
94 | 95 | ||
96 | #define BPANICF panicf | ||
97 | |||
95 | #define IS_MOVABLE(a) (!a[2].ops || a[2].ops->move_callback) | 98 | #define IS_MOVABLE(a) (!a[2].ops || a[2].ops->move_callback) |
96 | static union buflib_data* find_first_free(struct buflib_context *ctx); | 99 | static union buflib_data* find_first_free(struct buflib_context *ctx); |
97 | static union buflib_data* find_block_before(struct buflib_context *ctx, | 100 | static union buflib_data* find_block_before(struct buflib_context *ctx, |
@@ -147,6 +150,19 @@ bool buflib_context_relocate(struct buflib_context *ctx, void *buf) | |||
147 | return true; | 150 | return true; |
148 | } | 151 | } |
149 | 152 | ||
153 | static void buflib_panic(struct buflib_context *ctx, const char *message, ...) | ||
154 | { | ||
155 | char buf[128]; | ||
156 | va_list ap; | ||
157 | |||
158 | va_start(ap, message); | ||
159 | vsnprintf(buf, sizeof(buf), message, ap); | ||
160 | va_end(ap); | ||
161 | |||
162 | BPANICF("buflib error (CTX:%p, %zd bytes):\n%s", ctx, | ||
163 | (ctx->handle_table - ctx->buf_start) * sizeof(union buflib_data), buf); | ||
164 | } | ||
165 | |||
150 | /* Allocate a new handle, returning 0 on failure */ | 166 | /* Allocate a new handle, returning 0 on failure */ |
151 | static inline | 167 | static inline |
152 | union buflib_data* handle_alloc(struct buflib_context *ctx) | 168 | union buflib_data* handle_alloc(struct buflib_context *ctx) |
@@ -235,7 +251,7 @@ move_block(struct buflib_context* ctx, union buflib_data* block, int shift) | |||
235 | 251 | ||
236 | /* check for cookie validity */ | 252 | /* check for cookie validity */ |
237 | if (crc != crc_slot->crc) | 253 | if (crc != crc_slot->crc) |
238 | panicf("buflib cookie corrupted, crc: 0x%08x, expected: 0x%08x", | 254 | buflib_panic(ctx, "buflib cookie corrupted, crc: 0x%08x, expected: 0x%08x", |
239 | (unsigned int)crc, (unsigned int)crc_slot->crc); | 255 | (unsigned int)crc, (unsigned int)crc_slot->crc); |
240 | 256 | ||
241 | if (!IS_MOVABLE(block)) | 257 | if (!IS_MOVABLE(block)) |
@@ -901,7 +917,7 @@ void buflib_check_valid(struct buflib_context *ctx) | |||
901 | crc = crc_32((void *)this, cookie_size, 0xffffffff); | 917 | crc = crc_32((void *)this, cookie_size, 0xffffffff); |
902 | 918 | ||
903 | if (crc != crc_slot->crc) | 919 | if (crc != crc_slot->crc) |
904 | panicf("buflib check crc: 0x%08x, expected: 0x%08x", | 920 | buflib_panic(ctx, "crc mismatch: 0x%08x, expected: 0x%08x", |
905 | (unsigned int)crc, (unsigned int)crc_slot->crc); | 921 | (unsigned int)crc, (unsigned int)crc_slot->crc); |
906 | } | 922 | } |
907 | } | 923 | } |