From d608d2203aff93d6d68e7afbac7767cf95c03b8b Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Tue, 28 Jan 2014 15:32:23 +0100 Subject: buflib: Abstract panicf() into buflib_panic(). Change-Id: I4968a9bc290e10e30a77c36c19f694e286e7ef22 --- firmware/buflib.c | 20 ++++++++++++++++++-- 1 file 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 @@ * ****************************************************************************/ +#include #include /* for abs() */ #include /* for snprintf() */ #include /* for ptrdiff_t */ @@ -92,6 +93,8 @@ #define BDEBUGF(...) do { } while(0) #endif +#define BPANICF panicf + #define IS_MOVABLE(a) (!a[2].ops || a[2].ops->move_callback) static union buflib_data* find_first_free(struct buflib_context *ctx); 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) return true; } +static void buflib_panic(struct buflib_context *ctx, const char *message, ...) +{ + char buf[128]; + va_list ap; + + va_start(ap, message); + vsnprintf(buf, sizeof(buf), message, ap); + va_end(ap); + + BPANICF("buflib error (CTX:%p, %zd bytes):\n%s", ctx, + (ctx->handle_table - ctx->buf_start) * sizeof(union buflib_data), buf); +} + /* Allocate a new handle, returning 0 on failure */ static inline 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) /* check for cookie validity */ if (crc != crc_slot->crc) - panicf("buflib cookie corrupted, crc: 0x%08x, expected: 0x%08x", + buflib_panic(ctx, "buflib cookie corrupted, crc: 0x%08x, expected: 0x%08x", (unsigned int)crc, (unsigned int)crc_slot->crc); if (!IS_MOVABLE(block)) @@ -901,7 +917,7 @@ void buflib_check_valid(struct buflib_context *ctx) crc = crc_32((void *)this, cookie_size, 0xffffffff); if (crc != crc_slot->crc) - panicf("buflib check crc: 0x%08x, expected: 0x%08x", + buflib_panic(ctx, "crc mismatch: 0x%08x, expected: 0x%08x", (unsigned int)crc, (unsigned int)crc_slot->crc); } } -- cgit