diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/include/malloc.h | 1 | ||||
-rw-r--r-- | src/common/libalgo/btree.c | 346 | ||||
-rw-r--r-- | src/common/libc/printf.c | 13 | ||||
-rw-r--r-- | src/common/libc/string.c | 12 | ||||
-rw-r--r-- | src/common/libkogata/region_alloc.c | 18 | ||||
-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 | ||||
-rw-r--r-- | src/kernel/dev/vesa.c | 2 | ||||
-rw-r--r-- | src/kernel/user/ipc.c | 14 | ||||
-rw-r--r-- | src/kernel/user/process.c | 18 | ||||
-rw-r--r-- | src/kernel/user/syscall.c | 8 | ||||
-rw-r--r-- | src/lib/libkogata/draw.c | 6 | ||||
-rw-r--r-- | src/lib/libkogata/malloc.c | 10 | ||||
-rw-r--r-- | src/lib/libkogata/unistd.c | 2 | ||||
-rw-r--r-- | src/sysbin/init/main.c | 9 | ||||
-rw-r--r-- | src/tests/ktests/btree2/test.c | 11 |
17 files changed, 260 insertions, 235 deletions
diff --git a/src/common/include/malloc.h b/src/common/include/malloc.h index 0ba5572..ec29d69 100644 --- a/src/common/include/malloc.h +++ b/src/common/include/malloc.h @@ -7,5 +7,6 @@ void* malloc(size_t sz); void free(void* ptr); +void* calloc(size_t nmemb, size_t sz); /* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/libalgo/btree.c b/src/common/libalgo/btree.c index d5b34bb..d1bfd18 100644 --- a/src/common/libalgo/btree.c +++ b/src/common/libalgo/btree.c @@ -32,18 +32,17 @@ btree_t* create_btree(key_cmp_fun_t cf, kv_iter_fun_t relf) { return t; } -void delete_btree(btree_t *t) { - void delete_item_rec(btree_item_t *i,kv_iter_fun_t relf) { - if (i == 0) return; - - delete_item_rec(i->left, relf); - delete_item_rec(i->right, relf); +void _btree_delete_item_rec(btree_item_t *i,kv_iter_fun_t relf) { + if (i == 0) return; - if (relf) relf(i->key, i->val); - free(i); - } + _btree_delete_item_rec(i->left, relf); + _btree_delete_item_rec(i->right, relf); - delete_item_rec(t->root, t->releasef); + if (relf) relf(i->key, i->val); + free(i); +} +void delete_btree(btree_t *t) { + _btree_delete_item_rec(t->root, t->releasef); free(t); } @@ -115,20 +114,19 @@ btree_item_t* btree_equilibrate(btree_item_t *i) { // ADDING AND DELETING // // =================== // -bool btree_add(btree_t *t, void* key, void* val) { - btree_item_t* insert(btree_t *t, btree_item_t *root, btree_item_t *i) { - if (root == 0) return i; +btree_item_t* _btree_insert(btree_t *t, btree_item_t *root, btree_item_t *i) { + if (root == 0) return i; - if (t->cf(i->key, root->key) <= 0) { - root->left = insert(t, root->left, i); - } else { - root->right = insert(t, root->right, i); - } - btree_recalc_height(root); - - return btree_equilibrate(root); + if (t->cf(i->key, root->key) <= 0) { + root->left = _btree_insert(t, root->left, i); + } else { + root->right = _btree_insert(t, root->right, i); } + btree_recalc_height(root); + return btree_equilibrate(root); +} +bool btree_add(btree_t *t, void* key, void* val) { btree_item_t *x = (btree_item_t*)malloc(sizeof(btree_item_t)); if (x == 0) return false; @@ -137,181 +135,175 @@ bool btree_add(btree_t *t, void* key, void* val) { x->left = x->right = 0; btree_recalc_height(x); - t->root = insert(t, t->root, x); + t->root = _btree_insert(t, t->root, x); t->nitems++; return true; } -void btree_remove(btree_t *t, const void* key) { - btree_item_t *extract_smallest(btree_item_t *i, btree_item_t **out_smallest) { - ASSERT(i != 0); - if (i->left == 0) { - *out_smallest = i; - return i->right; - } else { - i->left = extract_smallest(i->left, out_smallest); - btree_recalc_height(i); - return btree_equilibrate(i); - } +btree_item_t *_btree_extract_smallest(btree_item_t *i, btree_item_t **out_smallest) { + ASSERT(i != 0); + if (i->left == 0) { + *out_smallest = i; + return i->right; + } else { + i->left = _btree_extract_smallest(i->left, out_smallest); + btree_recalc_height(i); + return btree_equilibrate(i); } +} +btree_item_t *_btree_remove_aux(btree_t *t, btree_item_t *i, const void* key) { + if (i == 0) return 0; - btree_item_t *remove_aux(btree_t *t, btree_item_t *i, const void* key) { - if (i == 0) return 0; - - int c = t->cf(key, i->key); - if (c < 0) { - i->left = remove_aux(t, i->left, key); - return btree_equilibrate(i); - } else if (c > 0) { - i->right = remove_aux(t, i->right, key); - return btree_equilibrate(i); + int c = t->cf(key, i->key); + if (c < 0) { + i->left = _btree_remove_aux(t, i->left, key); + return btree_equilibrate(i); + } else if (c > 0) { + i->right = _btree_remove_aux(t, i->right, key); + return btree_equilibrate(i); + } else { + // remove item i + + btree_item_t *new_i; + if (i->right == 0 || i->left == 0) { + new_i = (i->right == 0 ? i->left : i->right); } else { - // remove item i + btree_item_t *new_i_right = _btree_extract_smallest(i->right, &new_i); - btree_item_t *new_i; - if (i->right == 0 || i->left == 0) { - new_i = (i->right == 0 ? i->left : i->right); - } else { - btree_item_t *new_i_right = extract_smallest(i->right, &new_i); + new_i->left = i->left; + new_i->right = new_i_right; - new_i->left = i->left; - new_i->right = new_i_right; - - btree_recalc_height(new_i); - new_i = btree_equilibrate(new_i); - } + btree_recalc_height(new_i); + new_i = btree_equilibrate(new_i); + } - if (t->releasef) t->releasef(i->key, i->val); - free(i); - t->nitems--; + if (t->releasef) t->releasef(i->key, i->val); + free(i); + t->nitems--; - return remove_aux(t, new_i, key); // loop because several elements may correspond - } + return _btree_remove_aux(t, new_i, key); // loop because several elements may correspond } - - t->root = remove_aux(t, t->root, key); +} +void btree_remove(btree_t *t, const void* key) { + t->root = _btree_remove_aux(t, t->root, key); } -void btree_remove_v(btree_t *t, const void* key, const void* val) { - btree_item_t *extract_smallest(btree_item_t *i, btree_item_t **out_smallest) { - ASSERT(i != 0); - if (i->left == 0) { - *out_smallest = i; - return i->right; - } else { - i->left = extract_smallest(i->left, out_smallest); - btree_recalc_height(i); - return btree_equilibrate(i); - } +btree_item_t *_btree_extract_smallest_v(btree_item_t *i, btree_item_t **out_smallest) { + ASSERT(i != 0); + if (i->left == 0) { + *out_smallest = i; + return i->right; + } else { + i->left = _btree_extract_smallest_v(i->left, out_smallest); + btree_recalc_height(i); + return btree_equilibrate(i); } +} +btree_item_t *_btree_remove_aux_v(btree_t *t, btree_item_t *i, const void* key, const void* val) { + if (i == 0) return 0; - btree_item_t *remove_aux(btree_t *t, btree_item_t *i, const void* key, const void* val) { - if (i == 0) return 0; - - int c = t->cf(key, i->key); - if (c < 0) { - i->left = remove_aux(t, i->left, key, val); - return btree_equilibrate(i); - } else if (c > 0) { - i->right = remove_aux(t, i->right, key, val); - return btree_equilibrate(i); - } else if (i->val == val) { - // remove item i - - btree_item_t *new_i; - if (i->right == 0 || i->left == 0) { - new_i = (i->right == 0 ? i->left : i->right); - } else { - btree_item_t *new_i_right = extract_smallest(i->right, &new_i); - - new_i->left = i->left; - new_i->right = new_i_right; - - btree_recalc_height(new_i); - new_i = btree_equilibrate(new_i); - } - - if (t->releasef) t->releasef(i->key, i->val); - free(i); - t->nitems--; - - return remove_aux(t, new_i, key, val); // loop because several elements may correspond + int c = t->cf(key, i->key); + if (c < 0) { + i->left = _btree_remove_aux_v(t, i->left, key, val); + return btree_equilibrate(i); + } else if (c > 0) { + i->right = _btree_remove_aux_v(t, i->right, key, val); + return btree_equilibrate(i); + } else if (i->val == val) { + // remove item i + + btree_item_t *new_i; + if (i->right == 0 || i->left == 0) { + new_i = (i->right == 0 ? i->left : i->right); } else { - i->left = remove_aux(t, i->left, key, val); - i->right = remove_aux(t, i->right, key, val); - btree_recalc_height(i); - return btree_equilibrate(i); + btree_item_t *new_i_right = _btree_extract_smallest_v(i->right, &new_i); + + new_i->left = i->left; + new_i->right = new_i_right; + + btree_recalc_height(new_i); + new_i = btree_equilibrate(new_i); } - } - t->root = remove_aux(t, t->root, key, val); + if (t->releasef) t->releasef(i->key, i->val); + free(i); + t->nitems--; + + return _btree_remove_aux_v(t, new_i, key, val); // loop because several elements may correspond + } else { + i->left = _btree_remove_aux_v(t, i->left, key, val); + i->right = _btree_remove_aux_v(t, i->right, key, val); + btree_recalc_height(i); + return btree_equilibrate(i); + } +} +void btree_remove_v(btree_t *t, const void* key, const void* val) { + t->root = _btree_remove_aux_v(t, t->root, key, val); } // ======================== // // LOOKING UP AND ITERATING // // ======================== // -void* btree_find(btree_t *t, const void* key) { - btree_item_t *find_aux(btree_t *t, btree_item_t *i, const void* key) { - if (i == 0) return 0; - - int c = t->cf(key, i->key); - if (c == 0) { - return i; - } else if (c < 0) { - return find_aux(t, i->left, key); - } else { - return find_aux(t, i->right, key); - } +btree_item_t *_btree_find_aux(btree_t *t, btree_item_t *i, const void* key) { + if (i == 0) return 0; + + int c = t->cf(key, i->key); + if (c == 0) { + return i; + } else if (c < 0) { + return _btree_find_aux(t, i->left, key); + } else { + return _btree_find_aux(t, i->right, key); } +} +void* btree_find(btree_t *t, const void* key) { - btree_item_t *i = find_aux(t, t->root, key); + btree_item_t *i = _btree_find_aux(t, t->root, key); if (i == 0) return 0; return i->val; } -void* btree_lower(btree_t *t, const void* key, void** actual_key) { - btree_item_t *find_aux(btree_t *t, btree_item_t *i, const void* key) { - if (i == 0) return 0; - - int c = t->cf(key, i->key); - if (c == 0) { - return i; - } else if (c < 0) { - return find_aux(t, i->left, key); - } else { - btree_item_t *r = find_aux(t, i->right, key); - if (r == 0) r = i; - return r; - } - } +btree_item_t *_btree_lower_aux(btree_t *t, btree_item_t *i, const void* key) { + if (i == 0) return 0; - btree_item_t *i = find_aux(t, t->root, key); + int c = t->cf(key, i->key); + if (c == 0) { + return i; + } else if (c < 0) { + return _btree_lower_aux(t, i->left, key); + } else { + btree_item_t *r = _btree_lower_aux(t, i->right, key); + if (r == 0) r = i; + return r; + } +} +void* btree_lower(btree_t *t, const void* key, void** actual_key) { + btree_item_t *i = _btree_lower_aux(t, t->root, key); if (i == 0) return 0; if (actual_key != 0) *actual_key = i->key; return i->val; } -void* btree_upper(btree_t *t, const void* key, void** actual_key) { - btree_item_t *find_aux(btree_t *t, btree_item_t *i, const void* key) { - if (i == 0) return 0; - - int c = t->cf(key, i->key); - if (c == 0) { - return i; - } else if (c < 0) { - btree_item_t *r = find_aux(t, i->left, key); - if (r == 0) r = i; - return r; - } else { - return find_aux(t, i->right, key); - } - } +btree_item_t *_btree_upper_aux(btree_t *t, btree_item_t *i, const void* key) { + if (i == 0) return 0; - btree_item_t *i = find_aux(t, t->root, key); + int c = t->cf(key, i->key); + if (c == 0) { + return i; + } else if (c < 0) { + btree_item_t *r = _btree_upper_aux(t, i->left, key); + if (r == 0) r = i; + return r; + } else { + return _btree_upper_aux(t, i->right, key); + } +} +void* btree_upper(btree_t *t, const void* key, void** actual_key) { + btree_item_t *i = _btree_upper_aux(t, t->root, key); if (i == 0) return 0; if (actual_key != 0) *actual_key = i->key; @@ -319,35 +311,33 @@ void* btree_upper(btree_t *t, const void* key, void** actual_key) { } +void _btree_iter_aux(btree_item_t *i, kv_iter_fun_t f) { + if (i == 0) return; + + _btree_iter_aux(i->left, f); + f(i->key, i->val); + _btree_iter_aux(i->right, f); +} void btree_iter(btree_t *t, kv_iter_fun_t f) { - void iter_aux(btree_item_t *i, kv_iter_fun_t f) { - if (i == 0) return; + _btree_iter_aux(t->root, f); +} + +void _btree_iter_on_aux(btree_t *t, btree_item_t *i, const void* key, kv_iter_fun_t f) { + if (i == 0) return; - iter_aux(i->left, f); + int c = t->cf(key, i->key); + if (c == 0) { + _btree_iter_on_aux(t, i->left, key, f); f(i->key, i->val); - iter_aux(i->right, f); + _btree_iter_on_aux(t, i->right, key, f); + } else if (c < 0) { + _btree_iter_on_aux(t, i->left, key, f); + } else { + _btree_iter_on_aux(t, i->right, key, f); } - - iter_aux(t->root, f); } - void btree_iter_on(btree_t *t, const void* key, kv_iter_fun_t f) { - void iter_aux(btree_t *t, btree_item_t *i, const void* key, kv_iter_fun_t f) { - if (i == 0) return; - - int c = t->cf(key, i->key); - if (c == 0) { - iter_aux(t, i->left, key, f); - f(i->key, i->val); - iter_aux(t, i->right, key, f); - } else if (c < 0) { - iter_aux(t, i->left, key, f); - } else { - iter_aux(t, i->right, key, f); - } - } - - iter_aux(t, t->root, key, f); + _btree_iter_on_aux(t, t->root, key, f); } /* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/libc/printf.c b/src/common/libc/printf.c index 68e08d8..8618741 100644 --- a/src/common/libc/printf.c +++ b/src/common/libc/printf.c @@ -69,10 +69,9 @@ int vsnprintf(char *buff, size_t len, const char* format, va_list ap){ } case 'x': { unsigned int hexa = va_arg(ap,int); - unsigned int nb; - int j, had_nonzero = 0; - for(j = 0; j < 8; j++) { - nb = (unsigned int)(hexa << (j*4)); + int had_nonzero = 0; + for(int j = 0; j < 8; j++) { + unsigned int nb = (unsigned int)(hexa << (j*4)); nb = (nb >> 28) & 0xf; // Skip the leading zeros if (nb == 0) { @@ -92,10 +91,8 @@ int vsnprintf(char *buff, size_t len, const char* format, va_list ap){ } case 'p': { unsigned int hexa = va_arg(ap,int); - unsigned int nb; - int j; - for (j = 0; j < 8; j++) { - nb = (unsigned int)(hexa << (j*4)); + for (int j = 0; j < 8; j++) { + unsigned int nb = (unsigned int)(hexa << (j*4)); nb = (nb >> 28) & 0xf; if (nb < 10) PUTCHAR('0'+nb); diff --git a/src/common/libc/string.c b/src/common/libc/string.c index 82c290f..d2a5f2f 100644 --- a/src/common/libc/string.c +++ b/src/common/libc/string.c @@ -107,9 +107,17 @@ int memcmp(const void *va, const void *vb, size_t count) { } void *memset(void *dest, int val, size_t count) { + uint8_t uval = (val & 0xFF); + uint32_t wval = (uval<<24)|(uval<<16)|(uval<<8)|uval; + + uint32_t *dest_w = (uint32_t*)dest; + for (size_t i = 0; i < count/4; i++) { + dest_w[i] = wval; + } + uint8_t *dest_c = (uint8_t*)dest; - for (size_t i = 0; i < count; i++) { - dest_c[i] = val; + for (size_t i = count - (count%4); i < count; i++) { + dest_c[i] = uval; } return dest; } diff --git a/src/common/libkogata/region_alloc.c b/src/common/libkogata/region_alloc.c index 96a0f07..1f2fe0f 100644 --- a/src/common/libkogata/region_alloc.c +++ b/src/common/libkogata/region_alloc.c @@ -86,6 +86,13 @@ void remove_free_region(descriptor_t *d) { } } +descriptor_t *_region_alloc_rec_check_first_bigger(descriptor_t *it, size_t sz) { + if (it == 0) return 0; + ASSERT(_region_alloc_rec_check_first_bigger(it->free.next_by_size, it->free.size) == it->free.first_bigger); + if (it->free.size > sz) return it; + return it->free.first_bigger; +} + void add_free_region(descriptor_t *d) { /*dbg_printf("Add free region 0x%p - 0x%p\n", d->free.addr, d->free.size + d->free.addr);*/ // Find position of region in address-ordered list @@ -119,7 +126,8 @@ void add_free_region(descriptor_t *d) { d->free.next_by_addr = i; first_free_region_by_addr = d; } else { - while (i != 0) { + while (true) { + ASSERT(i != 0); ASSERT(d->free.addr > i->free.addr); if (i->free.addr + i->free.size == d->free.addr) { // concatenate i . d @@ -193,13 +201,7 @@ void add_free_region(descriptor_t *d) { // Explanation: the first_bigger field is meant to point at the first free descriptor with strictly // superior size, intending to make the finding a suitable free region faster, but this field // is a bit complicated to keep up to date (see the messy code above...) - descriptor_t *rec_check_first_bigger(descriptor_t *it, size_t sz) { - if (it == 0) return 0; - ASSERT(rec_check_first_bigger(it->free.next_by_size, it->free.size) == it->free.first_bigger); - if (it->free.size > sz) return it; - return it->free.first_bigger; - } - ASSERT(rec_check_first_bigger(first_free_region_by_size, 0) == first_free_region_by_size); + ASSERT(_region_alloc_rec_check_first_bigger(first_free_region_by_size, 0) == first_free_region_by_size); } descriptor_t *find_used_region(void* addr) { 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); } diff --git a/src/kernel/dev/vesa.c b/src/kernel/dev/vesa.c index 03418b4..390eee0 100644 --- a/src/kernel/dev/vesa.c +++ b/src/kernel/dev/vesa.c @@ -332,7 +332,7 @@ void vesa_init_driver(fs_t *iofs, vesa_mode_t *mode_data, int mode_data_c) { if (d == 0) goto fail_setup; d->pager = new_device_pager(0, 0); - if (d == 0) goto fail_setup; + if (d->pager == 0) goto fail_setup; d->modes = mode_data; d->nmodes = mode_data_c; diff --git a/src/kernel/user/ipc.c b/src/kernel/user/ipc.c index 3643eb2..54122e3 100644 --- a/src/kernel/user/ipc.c +++ b/src/kernel/user/ipc.c @@ -357,19 +357,19 @@ typedef struct { static token_table_entry_t *expired_token = 0; +void _find_expired_token(void* k, void* x) { + token_table_entry_t *e = (token_table_entry_t*)x; + if (e->time + TOKEN_LIFETIME < get_kernel_time()) { + expired_token = e; + } +} void token_expiration_check(void* x) { mutex_lock(&token_table_mutex); do { expired_token = 0; - void find_expired_token(void* k, void* x) { - token_table_entry_t *e = (token_table_entry_t*)x; - if (e->time + TOKEN_LIFETIME < get_kernel_time()) { - expired_token = e; - } - } - hashtbl_iter(token_table, find_expired_token); + hashtbl_iter(token_table, _find_expired_token); if (expired_token != 0) { hashtbl_remove(token_table, &expired_token->tok); diff --git a/src/kernel/user/process.c b/src/kernel/user/process.c index 43294ce..5c057e7 100644 --- a/src/kernel/user/process.c +++ b/src/kernel/user/process.c @@ -34,7 +34,7 @@ typedef struct { // ============================== // process_t *new_process(process_t *parent) { - process_t *proc = (process_t*)malloc(sizeof(process_t)); + process_t *proc = (process_t*)calloc(1, sizeof(process_t)); if (proc == 0) goto error; proc->filesystems = create_hashtbl(str_key_eq_fun, str_hash_fun, free_key); @@ -175,6 +175,12 @@ void current_process_exit(int status, int exit_code) { exit(); } +void _process_exit_release_fd(void* a, void* fd) { + unref_file((fs_handle_t*)fd); +} +void _process_exit_release_fs(void* a, void* fs) { + unref_fs((fs_t*)fs); +} void process_exit(process_t *p, int status, int exit_code) { // --- Make sure we are not running in a thread we are about to kill ASSERT(current_process() != p); @@ -217,10 +223,7 @@ void process_exit(process_t *p, int status, int exit_code) { } // release file descriptors - void release_fd(void* a, void* fd) { - unref_file((fs_handle_t*)fd); - } - hashtbl_iter(p->files, release_fd); + hashtbl_iter(p->files, _process_exit_release_fd); delete_hashtbl(p->files); p->files = 0; @@ -233,10 +236,7 @@ void process_exit(process_t *p, int status, int exit_code) { p->regions_idx = 0; // release filesystems - void release_fs(void* a, void* fs) { - unref_fs((fs_t*)fs); - } - hashtbl_iter(p->filesystems, release_fs); + hashtbl_iter(p->filesystems, _process_exit_release_fs); delete_hashtbl(p->filesystems); p->filesystems = 0; diff --git a/src/kernel/user/syscall.c b/src/kernel/user/syscall.c index 42b06eb..9497bf2 100644 --- a/src/kernel/user/syscall.c +++ b/src/kernel/user/syscall.c @@ -297,6 +297,9 @@ uint32_t fctl_sc(sc_args_t args) { } } +void _select_sc_resume_on_v(void*x) { + resume_on(x); +} uint32_t select_sc(sc_args_t args) { sel_fd_t *fds = (sel_fd_t*)args.a; size_t n = args.b; @@ -336,10 +339,7 @@ uint32_t select_sc(sc_args_t args) { if (timeout >= 0 && time - select_begin_time >= (uint64_t)timeout) break; // ---- Do a wait, if interrupted (killed or whatever) return false - void resume_on_v(void*x) { - resume_on(x); - } - if (timeout > 0) worker_push_in(time - select_begin_time - timeout, resume_on_v, current_thread); + if (timeout > 0) worker_push_in(time - select_begin_time - timeout, _select_sc_resume_on_v, current_thread); if (!wait_on_many(wait_objs, n_wait_objs)) break; } diff --git a/src/lib/libkogata/draw.c b/src/lib/libkogata/draw.c index 53070ad..2806df4 100644 --- a/src/lib/libkogata/draw.c +++ b/src/lib/libkogata/draw.c @@ -88,7 +88,7 @@ void g_hline(fb_t *fb, int x, int y, int w, color_t c) { for (int u = x; u < x + w; u++) { fb->data[y * fb->geom.pitch + u] = (c & 0xFF); } - } else if (fb->geom.bpp == 15 || fb->geom.bpp == 15) { + } else if (fb->geom.bpp == 15 || fb->geom.bpp == 16) { for (int u = x; u < x + w; u++) { uint16_t *p = (uint16_t*)(fb->data + y * fb->geom.pitch + 2 * u); *p = (c & 0xFFFF); @@ -110,7 +110,7 @@ void g_vline(fb_t *fb, int x, int y, int h, color_t c) { for (int v = y; v < y + h; v++) { fb->data[v * fb->geom.pitch + x] = (c & 0xFF); } - } else if (fb->geom.bpp == 15 || fb->geom.bpp == 15) { + } else if (fb->geom.bpp == 15 || fb->geom.bpp == 16) { for (int v = y; v < y + h; v++) { uint16_t *p = (uint16_t*)(fb->data + v * fb->geom.pitch + 2 * x); *p = (c & 0xFFFF); @@ -145,7 +145,7 @@ void g_fillrect(fb_t *fb, int x, int y, int w, int h, color_t c) { fb->data[v * fb->geom.pitch + u] = (c & 0xFF); } } - } else if (fb->geom.bpp == 15 || fb->geom.bpp == 15) { + } else if (fb->geom.bpp == 15 || fb->geom.bpp == 16) { for (int v = y; v < y + h; v++) { for (int u = x; u < x + w; u++) { uint16_t *p = (uint16_t*)(fb->data + v * fb->geom.pitch + 2 * u); diff --git a/src/lib/libkogata/malloc.c b/src/lib/libkogata/malloc.c index 2a3345f..3777123 100644 --- a/src/lib/libkogata/malloc.c +++ b/src/lib/libkogata/malloc.c @@ -1,6 +1,8 @@ #include <malloc.h> #include <slab_alloc.h> +#include <string.h> + #include <syscall.h> #include <region_alloc.h> @@ -50,9 +52,17 @@ void malloc_setup() { } void* malloc(size_t size) { + if (size == 0) return 0; + return slab_alloc(mem_allocator, size); } +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) { slab_free(mem_allocator, ptr); } diff --git a/src/lib/libkogata/unistd.c b/src/lib/libkogata/unistd.c index 80a32e4..101e02e 100644 --- a/src/lib/libkogata/unistd.c +++ b/src/lib/libkogata/unistd.c @@ -24,7 +24,7 @@ int chdir(const char* path) { stat_t st; if (!stat(cwd_buf2, &st)) return -1; - if (!st.type & FT_DIR) return -1; + if (!(st.type & FT_DIR)) return -1; strcpy(cwd_buf, cwd_buf2); return 0; diff --git a/src/sysbin/init/main.c b/src/sysbin/init/main.c index 36ca884..6be0a87 100644 --- a/src/sysbin/init/main.c +++ b/src/sysbin/init/main.c @@ -12,6 +12,10 @@ pid_t giosrv_pid = 0, login_pid = 0; fd_pair_t root_gip_chan; +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); @@ -41,10 +45,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/tests/ktests/btree2/test.c b/src/tests/ktests/btree2/test.c index dd62237..f139363 100644 --- a/src/tests/ktests/btree2/test.c +++ b/src/tests/ktests/btree2/test.c @@ -36,8 +36,15 @@ void test_btree_2() { if (k[i] <= xk && (ilower == -1 || k[i] > k[ilower])) ilower = i; if (k[i] >= xk && (iupper == -1 || k[i] < k[iupper])) iupper = i; } - dbg_printf("random %d : lower %d (= %d), upper %d (= %d) ; ", - xk, k[ilower], v[ilower], k[iupper], v[iupper]); + dbg_printf("random %d : ", xk); + if (ilower == -1) + dbg_printf("no lower, "); + else + dbg_printf("lower %d (= %d), ", k[ilower], v[ilower]); + if (iupper == -1) + dbg_printf("no upper ; "); + else + dbg_printf("upper %d (= %d) ; ", k[iupper], v[iupper]); const uint32_t bt_lower = (uint32_t)btree_lower(ht, (void*)xk, 0); const uint32_t bt_upper = (uint32_t)btree_upper(ht, (void*)xk, 0); dbg_printf("got lower %d, upper %d\n", bt_lower, bt_upper); |