summaryrefslogtreecommitdiff
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.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 @@
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)
96static union buflib_data* find_first_free(struct buflib_context *ctx); 99static union buflib_data* find_first_free(struct buflib_context *ctx);
97static union buflib_data* find_block_before(struct buflib_context *ctx, 100static 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
153static 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 */
151static inline 167static inline
152union buflib_data* handle_alloc(struct buflib_context *ctx) 168union 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}