diff options
Diffstat (limited to 'firmware/buflib.c')
-rw-r--r-- | firmware/buflib.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/firmware/buflib.c b/firmware/buflib.c index 0e00f1fe1f..06b52ca934 100644 --- a/firmware/buflib.c +++ b/firmware/buflib.c | |||
@@ -55,7 +55,7 @@ | |||
55 | * to find the start of the character array (and therefore the start of the | 55 | * to find the start of the character array (and therefore the start of the |
56 | * entire block) when only the handle or payload start is known. | 56 | * entire block) when only the handle or payload start is known. |
57 | * | 57 | * |
58 | * UPDATE BUFLIB_ALLOC_OVERHEAD (buflib.h) WHEN THIS COOKIE CHANGES! | 58 | * UPDATE BUFLIB_ALLOC_OVERHEAD (buflib.h) WHEN THE METADATA CHANGES! |
59 | * | 59 | * |
60 | * Example: | 60 | * Example: |
61 | * |<- alloc block #1 ->|<- unalloc block ->|<- alloc block #2 ->|<-handle table->| | 61 | * |<- alloc block #1 ->|<- unalloc block ->|<- alloc block #2 ->|<-handle table->| |
@@ -66,7 +66,7 @@ | |||
66 | * C - pointer to struct buflib_callbacks | 66 | * C - pointer to struct buflib_callbacks |
67 | * c - variable sized string identifier | 67 | * c - variable sized string identifier |
68 | * L2 - second length marker for string identifier | 68 | * L2 - second length marker for string identifier |
69 | * crc - crc32 protecting buflib cookie integrity | 69 | * crc - crc32 protecting buflib metadata integrity |
70 | * X - actual payload | 70 | * X - actual payload |
71 | * Y - unallocated space | 71 | * Y - unallocated space |
72 | * | 72 | * |
@@ -251,12 +251,12 @@ move_block(struct buflib_context* ctx, union buflib_data* block, int shift) | |||
251 | union buflib_data *new_block, *tmp = block[1].handle, *crc_slot; | 251 | union buflib_data *new_block, *tmp = block[1].handle, *crc_slot; |
252 | struct buflib_callbacks *ops = block[2].ops; | 252 | struct buflib_callbacks *ops = block[2].ops; |
253 | crc_slot = (union buflib_data*)tmp->alloc - 1; | 253 | crc_slot = (union buflib_data*)tmp->alloc - 1; |
254 | int cookie_size = (crc_slot - block)*sizeof(union buflib_data); | 254 | const int metadata_size = (crc_slot - block)*sizeof(union buflib_data); |
255 | uint32_t crc = crc_32((void *)block, cookie_size, 0xffffffff); | 255 | uint32_t crc = crc_32((void *)block, metadata_size, 0xffffffff); |
256 | 256 | ||
257 | /* check for cookie validity */ | 257 | /* check for metadata validity */ |
258 | if (crc != crc_slot->crc) | 258 | if (crc != crc_slot->crc) |
259 | buflib_panic(ctx, "buflib cookie corrupted, crc: 0x%08x, expected: 0x%08x", | 259 | buflib_panic(ctx, "buflib metadata corrupted, crc: 0x%08x, expected: 0x%08x", |
260 | (unsigned int)crc, (unsigned int)crc_slot->crc); | 260 | (unsigned int)crc, (unsigned int)crc_slot->crc); |
261 | 261 | ||
262 | if (!IS_MOVABLE(block)) | 262 | if (!IS_MOVABLE(block)) |
@@ -827,7 +827,7 @@ bool | |||
827 | buflib_shrink(struct buflib_context* ctx, int handle, void* new_start, size_t new_size) | 827 | buflib_shrink(struct buflib_context* ctx, int handle, void* new_start, size_t new_size) |
828 | { | 828 | { |
829 | union buflib_data *crc_slot; | 829 | union buflib_data *crc_slot; |
830 | int cookie_size; | 830 | int size_for_crc32; |
831 | char* oldstart = buflib_get_data(ctx, handle); | 831 | char* oldstart = buflib_get_data(ctx, handle); |
832 | char* newstart = new_start; | 832 | char* newstart = new_start; |
833 | char* newend = newstart + new_size; | 833 | char* newend = newstart + new_size; |
@@ -873,10 +873,10 @@ buflib_shrink(struct buflib_context* ctx, int handle, void* new_start, size_t ne | |||
873 | block = new_block; | 873 | block = new_block; |
874 | } | 874 | } |
875 | 875 | ||
876 | /* update crc of the cookie */ | 876 | /* update crc of the metadata */ |
877 | crc_slot = (union buflib_data*)new_block[1].handle->alloc - 1; | 877 | crc_slot = (union buflib_data*)new_block[1].handle->alloc - 1; |
878 | cookie_size = (crc_slot - new_block)*sizeof(union buflib_data); | 878 | size_for_crc32 = (crc_slot - new_block)*sizeof(union buflib_data); |
879 | crc_slot->crc = crc_32((void *)new_block, cookie_size, 0xffffffff); | 879 | crc_slot->crc = crc_32((void *)new_block, size_for_crc32, 0xffffffff); |
880 | 880 | ||
881 | /* Now deal with size changes that create free blocks after the allocation */ | 881 | /* Now deal with size changes that create free blocks after the allocation */ |
882 | if (old_next_block != new_next_block) | 882 | if (old_next_block != new_next_block) |
@@ -919,7 +919,7 @@ void *buflib_get_data(struct buflib_context *ctx, int handle) | |||
919 | void buflib_check_valid(struct buflib_context *ctx) | 919 | void buflib_check_valid(struct buflib_context *ctx) |
920 | { | 920 | { |
921 | union buflib_data *crc_slot; | 921 | union buflib_data *crc_slot; |
922 | int cookie_size; | 922 | int metadata_size; |
923 | uint32_t crc; | 923 | uint32_t crc; |
924 | 924 | ||
925 | for(union buflib_data* this = ctx->buf_start; | 925 | for(union buflib_data* this = ctx->buf_start; |
@@ -931,8 +931,8 @@ void buflib_check_valid(struct buflib_context *ctx) | |||
931 | 931 | ||
932 | crc_slot = (union buflib_data*) | 932 | crc_slot = (union buflib_data*) |
933 | ((union buflib_data*)this[1].handle)->alloc - 1; | 933 | ((union buflib_data*)this[1].handle)->alloc - 1; |
934 | cookie_size = (crc_slot - this)*sizeof(union buflib_data); | 934 | metadata_size = (crc_slot - this)*sizeof(union buflib_data); |
935 | crc = crc_32((void *)this, cookie_size, 0xffffffff); | 935 | crc = crc_32((void *)this, metadata_size, 0xffffffff); |
936 | 936 | ||
937 | if (crc != crc_slot->crc) | 937 | if (crc != crc_slot->crc) |
938 | buflib_panic(ctx, "crc mismatch: 0x%08x, expected: 0x%08x", | 938 | buflib_panic(ctx, "crc mismatch: 0x%08x, expected: 0x%08x", |