diff options
author | Marvin Borner | 2021-03-14 16:06:57 +0100 |
---|---|---|
committer | Marvin Borner | 2021-03-14 16:06:57 +0100 |
commit | 6dec7db5158447b66f31a3f786ce2916cab83cec (patch) | |
tree | 2dbc3e52d90dab4aae8021773f09b6b72a74b8cb /kernel/features | |
parent | 2f8328f2a41b77eea297ee7fc28818331d4e6c54 (diff) |
Maaany fixes :)
I don't have the motivation to write better commit messages...
Diffstat (limited to 'kernel/features')
-rw-r--r-- | kernel/features/fs.c | 4 | ||||
-rw-r--r-- | kernel/features/mm.c | 4 | ||||
-rw-r--r-- | kernel/features/proc.c | 20 |
3 files changed, 19 insertions, 9 deletions
diff --git a/kernel/features/fs.c b/kernel/features/fs.c index 20d00e5..c8ad317 100644 --- a/kernel/features/fs.c +++ b/kernel/features/fs.c @@ -122,7 +122,7 @@ s32 vfs_mount(struct device *dev, const char *path) s32 vfs_read(const char *path, void *buf, u32 offset, u32 count) { - /* printf("%s READ: %s\n", proc_current()->name, path); */ + /* printf("%s READ: %s\n", proc_current() ? proc_current()->name : "Unknown", path); */ if (!count) return 0; @@ -148,7 +148,7 @@ s32 vfs_read(const char *path, void *buf, u32 offset, u32 count) s32 vfs_write(const char *path, void *buf, u32 offset, u32 count) { - /* printf("%s WRITE: %s\n", proc_current()->name, path); */ + /* printf("%s WRITE: %s\n", proc_current() ? proc_current()->name : "Unknown", path); */ if (!count) return 0; diff --git a/kernel/features/mm.c b/kernel/features/mm.c index bd32683..9eca438 100644 --- a/kernel/features/mm.c +++ b/kernel/features/mm.c @@ -32,7 +32,7 @@ static void paging_switch_dir(u32 dir) extern void paging_invalidate_tlb(void); -static void page_fault(struct regs *r) +void page_fault_handler(struct regs *r) { // Check error code const char *type = (r->err_code & 1) ? "present" : "non-present"; @@ -495,6 +495,4 @@ void memory_install(struct mem_info *mem_info, struct vid_info *vid_info) memory_switch_dir(&kernel_dir); paging_enable(); - - isr_install_handler(14, page_fault); } diff --git a/kernel/features/proc.c b/kernel/features/proc.c index 6bbe894..b93f7c8 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -305,6 +305,11 @@ static enum stream_defaults procfs_stream(const char *path) } } +struct procfs_message { + u8 *data; + u32 size; +}; + static s32 procfs_write(const char *path, void *buf, u32 offset, u32 count, struct device *dev) { u32 pid = 0; @@ -318,7 +323,10 @@ static s32 procfs_write(const char *path, void *buf, u32 offset, u32 count, stru if (!memcmp(path, "msg", 4)) { void *msg_data = malloc(count); memcpy(msg_data, buf, count); - stack_push_bot(p->messages, msg_data); // TODO: Use offset + struct procfs_message *msg = malloc(sizeof(*msg)); + msg->data = msg_data; + msg->size = count; + stack_push_bot(p->messages, msg); // TODO: Use offset proc_enable_waiting(pid, PROC_WAIT_MSG); return count; } else if (!memcmp(path, "io/", 3)) { @@ -371,12 +379,13 @@ static s32 procfs_read(const char *path, void *buf, u32 offset, u32 count, struc if (stack_empty(p->messages)) { return -1; // This shouldn't happen } else { - u8 *msg = stack_pop(p->messages); + struct procfs_message *msg = stack_pop(p->messages); if (!msg) return -1; - memcpy(buf, msg + offset, count); + memcpy(buf, msg->data + offset, MIN(count, msg->size)); + free(msg->data); free(msg); - return count; + return MIN(count, msg->size); } } else if (!memcmp(path, "io/", 3)) { path += 3; @@ -500,7 +509,10 @@ void proc_init(void) printf("Jumping to userspace!\n"); memory_switch_dir(((struct proc *)new->data)->page_dir); + + // You're waiting for a train. A train that will take you far away... proc_jump_userspace(); + while (1) { }; } |