From 5fcf57739e68a8b5053e03778aaee0eed445babd Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Thu, 11 Mar 2021 22:00:22 -0500 Subject: settings editor, and lots of changes in service of that --- src/user/knob/block.c | 5 ++++- src/user/knob/file.c | 7 ++++++- src/user/knob/heap.c | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) (limited to 'src/user/knob') diff --git a/src/user/knob/block.c b/src/user/knob/block.c index 5b4590f..9f3f353 100644 --- a/src/user/knob/block.c +++ b/src/user/knob/block.c @@ -1,6 +1,7 @@ +#include +#include #include #include -#include //unsophisticated, should copy by dwords where available void blockcpy(void *to, const void *from, uint32_t size) { @@ -31,6 +32,8 @@ char *strdup(const char *from) { while (*(end++)) ; char *buf = get_block(end - from); + if (!buf) + PANIC("get_block returned 0 in strdup"); blockcpy(buf, from, end - from); return buf; } diff --git a/src/user/knob/file.c b/src/user/knob/file.c index db38e52..999778e 100644 --- a/src/user/knob/file.c +++ b/src/user/knob/file.c @@ -73,7 +73,7 @@ uint32_t read_from_file(struct file *f, uint32_t max, void *buf) { return read; } -uint32_t write_to_file(struct file *f, uint32_t max, void *buf) { +uint32_t write_to_file(struct file *f, uint32_t max, const void *buf) { if (f->position + max > f->length) _set_file_size(f->handle, f->length = f->position + max); @@ -109,6 +109,11 @@ int32_t seek_file_by(struct file *f, int32_t by) { return to - old; } +__attribute__ ((pure)) +uint32_t get_file_pos(struct file *f) { + return f->position; +} + __attribute__ ((pure)) uint32_t file_size(struct file *f) { return f->length; diff --git a/src/user/knob/heap.c b/src/user/knob/heap.c index b770542..6e57000 100644 --- a/src/user/knob/heap.c +++ b/src/user/knob/heap.c @@ -25,8 +25,18 @@ static void add_header(struct block_header *bh) { first_block = bh; } +//static const char *const hextab = "0123456789abcdef"; +//static char *const get_debug = "getting 0x........ byte block"; +//static char *const free_debug = "freeing 0x........ byte block"; + __attribute__ ((malloc)) void *get_block(uint32_t bytes) { + if (!bytes) + return 0; +//for (uint8_t i = 0; i < 8; ++i) +// get_debug[10 + 7 - i] = hextab[(bytes >> (i * 4)) & 0xf]; +//_system_log(get_debug); + struct block_header *header = 0; for (struct block_header *ptr = first_block; ptr; ptr = ptr->next) { if (ptr->allocated) @@ -88,6 +98,10 @@ static void remove_header(struct block_header *bh) { void free_block(void *block) { struct block_header *header = block - sizeof(struct block_header); +//for (uint8_t i = 0; i < 8; ++i) +// free_debug[10 + 7 - i] = hextab[(header->length >> (i * 4)) & 0xf]; +//_system_log(free_debug); + header->allocated = false; void *after = block + header->length; -- cgit v1.2.3