summaryrefslogtreecommitdiffstats
path: root/firmware/include
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2014-01-09 21:37:07 +0100
committerMarcin Bukat <marcin.bukat@gmail.com>2014-01-16 10:17:39 +0100
commit7ab237b025cbb4c25d345604da32e894379c1721 (patch)
tree92d147029519c55d57db4273066d57b960ad7158 /firmware/include
parent7f5dce4116bf4e62e0cd3ef16730157e17625e1c (diff)
downloadrockbox-7ab237b025cbb4c25d345604da32e894379c1721.tar.gz
rockbox-7ab237b025cbb4c25d345604da32e894379c1721.tar.bz2
rockbox-7ab237b025cbb4c25d345604da32e894379c1721.zip
buflib: Add crc field protecting buflib cookie integrity
This should catch the case of buffer misuse which results in corrupted cookie of next allocation. The check is performed on move_block() so it may be a bit late. There is buflib_check_valid() provided which checks the integrity of all cookies for given context. On DEBUG build with --sdl-thread this check is carried out for core_ctx on every context switch to catch problems earlier. Change-Id: I999d4576084592394e3dbd3bdf0f32935ff5f601 Reviewed-on: http://gerrit.rockbox.org/711 Reviewed-by: Thomas Martitz <kugel@rockbox.org>
Diffstat (limited to 'firmware/include')
-rw-r--r--firmware/include/buflib.h6
-rw-r--r--firmware/include/core_alloc.h3
-rw-r--r--firmware/include/crc32.h4
3 files changed, 12 insertions, 1 deletions
diff --git a/firmware/include/buflib.h b/firmware/include/buflib.h
index 0b26c04bcd..171ab5bcd7 100644
--- a/firmware/include/buflib.h
+++ b/firmware/include/buflib.h
@@ -40,6 +40,7 @@ union buflib_data
struct buflib_callbacks* ops;
char* alloc;
union buflib_data *handle;
+ uint32_t crc;
};
struct buflib_context
@@ -346,4 +347,9 @@ int buflib_get_num_blocks(struct buflib_context *ctx);
*/
void buflib_print_block_at(struct buflib_context *ctx, int block_num,
char* buf, size_t bufsize);
+
+/**
+ * Check integrity of given buflib context
+ */
+void buflib_check_valid(struct buflib_context *ctx);
#endif
diff --git a/firmware/include/core_alloc.h b/firmware/include/core_alloc.h
index a100b7cc6c..095cb5da11 100644
--- a/firmware/include/core_alloc.h
+++ b/firmware/include/core_alloc.h
@@ -17,6 +17,9 @@ bool core_shrink(int handle, void* new_start, size_t new_size);
int core_free(int handle);
size_t core_available(void);
size_t core_allocatable(void);
+#ifdef DEBUG
+void core_check_valid(void);
+#endif
/* DO NOT ADD wrappers for buflib_buffer_out/in. They do not call
* the move callbacks and are therefore unsafe in the core */
diff --git a/firmware/include/crc32.h b/firmware/include/crc32.h
index 034c3984ab..8e1f868988 100644
--- a/firmware/include/crc32.h
+++ b/firmware/include/crc32.h
@@ -18,10 +18,12 @@
* KIND, either express or implied.
*
****************************************************************************/
+#include <stdint.h>
+
#ifndef _CRC32_H
#define _CRC32_H
-unsigned crc_32(const void *src, unsigned len, unsigned crc32);
+uint32_t crc_32(const void *src, uint32_t len, uint32_t crc32);
#endif