diff options
Diffstat (limited to 'src/kernel/core')
-rw-r--r-- | src/kernel/core/kmain.c | 8 | ||||
-rw-r--r-- | src/kernel/core/kmalloc.c | 9 | ||||
-rw-r--r-- | src/kernel/core/thread.c | 8 |
3 files changed, 17 insertions, 8 deletions
diff --git a/src/kernel/core/kmain.c b/src/kernel/core/kmain.c index 38336a9..d09a1b5 100644 --- a/src/kernel/core/kmain.c +++ b/src/kernel/core/kmain.c @@ -190,6 +190,9 @@ void kernel_init_stage2(void* data) { dbg_printf("Reached kmain end! I'll just stop here and do nothing.\n"); } +void _parse_cmdline_iter(void* a, void* b) { + dbg_printf(" '%s' -> '%s'\n", a, b); +} btree_t *parse_cmdline(const char* x) { btree_t *ret = create_btree(str_key_cmp_fun, free_key_val); ASSERT(ret != 0); @@ -219,10 +222,7 @@ btree_t *parse_cmdline(const char* x) { } } - void iter(void* a, void* b) { - dbg_printf(" '%s' -> '%s'\n", a, b); - } - btree_iter(ret, iter); + btree_iter(ret, _parse_cmdline_iter); return ret; } diff --git a/src/kernel/core/kmalloc.c b/src/kernel/core/kmalloc.c index 95347b3..985df41 100644 --- a/src/kernel/core/kmalloc.c +++ b/src/kernel/core/kmalloc.c @@ -2,6 +2,7 @@ #include <slab_alloc.h> #include <mutex.h> +#include <string.h> #include <frame.h> #include <paging.h> @@ -77,6 +78,8 @@ void* malloc0(size_t sz) { } void* malloc(size_t sz) { + if (sz == 0) return 0; + void* res; int tries = 0; @@ -88,6 +91,12 @@ void* malloc(size_t sz) { return res; } +void* calloc(size_t nmemb, size_t sz) { + void* r = malloc(nmemb * sz); + if (r != 0) memset(r, 0, nmemb * sz); + return r; +} + void free(void* ptr) { mutex_lock(&malloc_mutex); slab_free(kernel_allocator, ptr); diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c index f2ddf9b..37226ae 100644 --- a/src/kernel/core/thread.c +++ b/src/kernel/core/thread.c @@ -337,13 +337,13 @@ bool wait_on_many(void** x, size_t n) { return true; } +void _usleep_resume_on_v(void* x) { + resume_on(x); +} void usleep(int usecs) { if (current_thread == 0) return; - void resume_on_v(void* x) { - resume_on(x); - } - bool ok = worker_push_in(usecs, resume_on_v, current_thread); + bool ok = worker_push_in(usecs, _usleep_resume_on_v, current_thread); if (ok) wait_on(current_thread); } |