aboutsummaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/core/kmain.c8
-rw-r--r--src/kernel/core/kmalloc.c9
-rw-r--r--src/kernel/core/thread.c8
-rw-r--r--src/kernel/dev/vesa.c2
-rw-r--r--src/kernel/user/ipc.c14
-rw-r--r--src/kernel/user/process.c18
-rw-r--r--src/kernel/user/syscall.c8
7 files changed, 38 insertions, 29 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);
}
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;
}