diff options
author | Marvin Borner | 2020-08-22 01:10:59 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-22 01:10:59 +0200 |
commit | 45db1523a02730a172564ca8c2be55422d5d2f0b (patch) | |
tree | 1b64e92fcc5519d3466f15a325267127d6e63905 /kernel/features | |
parent | e72ef04668a87702c92cebc868612b9ebb8b0ad8 (diff) |
Fixed some TODOs
Diffstat (limited to 'kernel/features')
-rw-r--r-- | kernel/features/event.c | 31 | ||||
-rw-r--r-- | kernel/features/proc.c | 8 | ||||
-rw-r--r-- | kernel/features/syscall.c | 4 |
3 files changed, 22 insertions, 21 deletions
diff --git a/kernel/features/event.c b/kernel/features/event.c index 9fd6da2..8a2c904 100644 --- a/kernel/features/event.c +++ b/kernel/features/event.c @@ -10,40 +10,41 @@ struct list *event_table[] = { [EVENT_KEYBOARD] = NULL, [EVENT_MOUSE] = NULL }; -u32 event_map(enum event id, u32 *func) +u32 event_map(enum event id, struct proc *proc, u32 *func) { - // TODO: Check if function is already mapped - if (id >= sizeof(event_table) / sizeof(*event_table)) - return -1; + assert(id < sizeof(event_table) / sizeof(*event_table)); if (event_table[id] == NULL) event_table[id] = (struct list *)list_new(); + struct node *iterator = event_table[id]->head; + do { + assert(((struct event_descriptor *)iterator->data)->func != func); + } while ((iterator = iterator->next) != NULL); + struct event_descriptor *desc = malloc(sizeof(*desc)); desc->func = func; - desc->proc = proc_current(); + desc->proc = proc; list_add((struct list *)event_table[id], (void *)desc); return 0; } -// TODO: Fix unmap -void event_unmap(enum event id, u32 *func) +void event_unmap(enum event id, struct proc *proc, u32 *func) { + assert(id < sizeof(event_table) / sizeof(*event_table)); + struct list *list = ((struct list *)event_table[id]); struct event_descriptor *desc = malloc(sizeof(*desc)); desc->func = func; - desc->proc = proc_current(); + desc->proc = proc; struct node *iterator = list->head; - while (memcmp(iterator->data, (void *)desc, sizeof(*desc)) == 0) { - iterator = iterator->next; - if (!iterator) - return; - } - - list_remove(list, iterator); + do { + if (memcmp(iterator->data, desc, sizeof(*desc)) == 0) + list_remove(list, iterator); + } while ((iterator = iterator->next) != NULL); } u32 event_trigger(enum event id, u32 *data) diff --git a/kernel/features/proc.c b/kernel/features/proc.c index 3e99e35..e4219b0 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -38,7 +38,6 @@ void scheduler(struct regs *regs) } } - /* proc_print(); */ memcpy(regs, &((struct proc *)current->data)->regs, sizeof(struct regs)); if (((struct proc *)current->data)->event) { @@ -77,7 +76,10 @@ void proc_print() struct proc *proc_current() { - return (struct proc *)current->data; + if (current) + return (struct proc *)current->data; + else + return NULL; } void proc_exit(struct proc *proc, int status) @@ -92,7 +94,6 @@ void proc_exit(struct proc *proc, int status) break; } } while ((iterator = iterator->next) != NULL); - proc_print(); } struct proc *proc_make() @@ -121,7 +122,6 @@ void proc_init() struct node *new = list_add(proc_list, proc_make()); bin_load("/init", new->data); - proc_print(); _eip = ((struct proc *)new->data)->regs.eip; _esp = ((struct proc *)new->data)->regs.useresp; diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c index 2704690..e96cb65 100644 --- a/kernel/features/syscall.c +++ b/kernel/features/syscall.c @@ -68,12 +68,12 @@ void syscall_handler(struct regs *r) } case SYS_MAP: { printf("map\n"); - event_map(r->ebx, (u32 *)r->ecx); + event_map(r->ebx, proc_current(), (u32 *)r->ecx); break; } case SYS_UNMAP: { printf("unmap\n"); - event_unmap(r->ebx, (u32 *)r->ecx); + event_unmap(r->ebx, proc_current(), (u32 *)r->ecx); break; } default: { |