diff options
Diffstat (limited to 'firmware/include')
-rw-r--r-- | firmware/include/buflib.h | 47 | ||||
-rw-r--r-- | firmware/include/core_alloc.h | 14 |
2 files changed, 37 insertions, 24 deletions
diff --git a/firmware/include/buflib.h b/firmware/include/buflib.h index 349e4a3e7a..49e4db11c0 100644 --- a/firmware/include/buflib.h +++ b/firmware/include/buflib.h | |||
@@ -23,15 +23,21 @@ | |||
23 | * KIND, either express or implied. | 23 | * KIND, either express or implied. |
24 | * | 24 | * |
25 | ****************************************************************************/ | 25 | ****************************************************************************/ |
26 | |||
27 | #ifndef _BUFLIB_H_ | 26 | #ifndef _BUFLIB_H_ |
28 | #define _BUFLIB_H_ | 27 | #define _BUFLIB_H_ |
28 | |||
29 | #include <stdint.h> | 29 | #include <stdint.h> |
30 | #include <stdbool.h> | 30 | #include <stdbool.h> |
31 | #include <string.h> | 31 | #include <string.h> |
32 | 32 | ||
33 | /* enable single block debugging */ | 33 | /* add extra checks to buflib_get_data to catch bad handles */ |
34 | #define BUFLIB_DEBUG_BLOCK_SINGLE | 34 | //#define BUFLIB_DEBUG_GET_DATA |
35 | |||
36 | /* support integrity check */ | ||
37 | //#define BUFLIB_DEBUG_CHECK_VALID | ||
38 | |||
39 | /* support debug printing of memory blocks */ | ||
40 | //#define BUFLIB_DEBUG_PRINT | ||
35 | 41 | ||
36 | union buflib_data | 42 | union buflib_data |
37 | { | 43 | { |
@@ -260,12 +266,12 @@ int buflib_alloc_maximum(struct buflib_context* ctx, | |||
260 | * | 266 | * |
261 | * Returns: The start pointer of the allocation | 267 | * Returns: The start pointer of the allocation |
262 | */ | 268 | */ |
263 | #ifdef DEBUG | 269 | #ifdef BUFLIB_DEBUG_GET_DATA |
264 | void* buflib_get_data(struct buflib_context *ctx, int handle); | 270 | void *buflib_get_data(struct buflib_context *ctx, int handle); |
265 | #else | 271 | #else |
266 | static inline void* buflib_get_data(struct buflib_context *ctx, int handle) | 272 | static inline void *buflib_get_data(struct buflib_context *ctx, int handle) |
267 | { | 273 | { |
268 | return (void*)(ctx->handle_table[-handle].alloc); | 274 | return (void *)ctx->handle_table[-handle].alloc; |
269 | } | 275 | } |
270 | #endif | 276 | #endif |
271 | 277 | ||
@@ -342,29 +348,34 @@ void* buflib_buffer_out(struct buflib_context *ctx, size_t *size); | |||
342 | */ | 348 | */ |
343 | void buflib_buffer_in(struct buflib_context *ctx, int size); | 349 | void buflib_buffer_in(struct buflib_context *ctx, int size); |
344 | 350 | ||
345 | /* debugging */ | 351 | #ifdef BUFLIB_DEBUG_PRINT |
346 | |||
347 | /** | 352 | /** |
348 | * Gets the number of blocks in the entire buffer, allocated or unallocated | 353 | * Return the number of blocks in the buffer, allocated or unallocated. |
349 | * | 354 | * |
350 | * Only available if BUFLIB_DEBUG_BLOCK_SIGNLE is defined | 355 | * Only available if BUFLIB_DEBUG_PRINT is defined. |
351 | */ | 356 | */ |
352 | int buflib_get_num_blocks(struct buflib_context *ctx); | 357 | int buflib_get_num_blocks(struct buflib_context *ctx); |
353 | 358 | ||
354 | /** | 359 | /** |
355 | * Print information about a single block as indicated by block_num | 360 | * Write a string describing the block at index block_num to the |
356 | * into buf | 361 | * provided buffer. The buffer will always be null terminated and |
362 | * there is no provision to detect truncation. (A 40-byte buffer | ||
363 | * is enough to contain any returned string.) | ||
357 | * | 364 | * |
358 | * buflib_get_num_blocks() beforehand to get the total number of blocks, | 365 | * Returns false if the block index is out of bounds, and writes |
359 | * as passing an block_num higher than that is undefined | 366 | * an empty string. |
360 | * | 367 | * |
361 | * Only available if BUFLIB_DEBUG_BLOCK_SIGNLE is defined | 368 | * Only available if BUFLIB_DEBUG_PRINT is defined. |
362 | */ | 369 | */ |
363 | void buflib_print_block_at(struct buflib_context *ctx, int block_num, | 370 | bool buflib_print_block_at(struct buflib_context *ctx, int block_num, |
364 | char* buf, size_t bufsize); | 371 | char *buf, size_t bufsize); |
372 | #endif | ||
365 | 373 | ||
374 | #ifdef BUFLIB_DEBUG_CHECK_VALID | ||
366 | /** | 375 | /** |
367 | * Check integrity of given buflib context | 376 | * Check integrity of given buflib context |
368 | */ | 377 | */ |
369 | void buflib_check_valid(struct buflib_context *ctx); | 378 | void buflib_check_valid(struct buflib_context *ctx); |
370 | #endif | 379 | #endif |
380 | |||
381 | #endif /* _BUFLIB_H_ */ | ||
diff --git a/firmware/include/core_alloc.h b/firmware/include/core_alloc.h index 8011c227b1..22cc1988da 100644 --- a/firmware/include/core_alloc.h +++ b/firmware/include/core_alloc.h | |||
@@ -21,21 +21,23 @@ unsigned core_pin_count(int handle); | |||
21 | int core_free(int handle); | 21 | int core_free(int handle); |
22 | size_t core_available(void); | 22 | size_t core_available(void); |
23 | size_t core_allocatable(void); | 23 | size_t core_allocatable(void); |
24 | #ifdef DEBUG | 24 | |
25 | #ifdef BUFLIB_DEBUG_CHECK_VALID | ||
25 | void core_check_valid(void); | 26 | void core_check_valid(void); |
26 | #endif | 27 | #endif |
27 | 28 | ||
28 | /* DO NOT ADD wrappers for buflib_buffer_out/in. They do not call | 29 | /* DO NOT ADD wrappers for buflib_buffer_out/in. They do not call |
29 | * the move callbacks and are therefore unsafe in the core */ | 30 | * the move callbacks and are therefore unsafe in the core */ |
30 | 31 | ||
31 | #ifdef BUFLIB_DEBUG_BLOCK_SINGLE | 32 | #ifdef BUFLIB_DEBUG_PRINT |
32 | int core_get_num_blocks(void); | 33 | int core_get_num_blocks(void); |
33 | void core_print_block_at(int block_num, char* buf, size_t bufsize); | 34 | bool core_print_block_at(int block_num, char* buf, size_t bufsize); |
34 | #endif | ||
35 | 35 | ||
36 | /* frees the debug test alloc created at initialization, | 36 | /* frees the debug test alloc created at initialization, |
37 | * since this is the first any further alloc should force a compaction run */ | 37 | * since this is the first any further alloc should force a compaction run |
38 | * only used if debug print is active */ | ||
38 | bool core_test_free(void); | 39 | bool core_test_free(void); |
40 | #endif | ||
39 | 41 | ||
40 | static inline void* core_get_data(int handle) | 42 | static inline void* core_get_data(int handle) |
41 | { | 43 | { |