summaryrefslogtreecommitdiffstats
path: root/firmware/buflib.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2014-01-28 15:32:23 +0100
committerThomas Martitz <kugel@rockbox.org>2014-02-02 16:59:29 +0100
commitd608d2203aff93d6d68e7afbac7767cf95c03b8b (patch)
treea9f64ddd28d618a650880d8b6df8f67060b10877 /firmware/buflib.c
parenta11c6a532b00be687dfc61b269114ae70616bc28 (diff)
downloadrockbox-d608d2203aff93d6d68e7afbac7767cf95c03b8b.tar.gz
rockbox-d608d2203aff93d6d68e7afbac7767cf95c03b8b.tar.bz2
rockbox-d608d2203aff93d6d68e7afbac7767cf95c03b8b.zip
buflib: Abstract panicf() into buflib_panic().
Change-Id: I4968a9bc290e10e30a77c36c19f694e286e7ef22
Diffstat (limited to 'firmware/buflib.c')
-rw-r--r--firmware/buflib.c20
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 @@
*
****************************************************************************/
+#include <stdarg.h>
#include <stdlib.h> /* for abs() */
#include <stdio.h> /* for snprintf() */
#include <stddef.h> /* 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);
}
}