From dc9f9f55cb6b38b87d8c228ae9abb4b53ebfb25c Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Mon, 15 Mar 2021 22:54:54 +0100 Subject: System hardening and errno impl --- kernel/drivers/fb.c | 2 +- kernel/drivers/keyboard.c | 7 +- kernel/drivers/mouse.c | 5 +- kernel/features/fs.c | 189 +++++++++++++++++++++++++++------------------- kernel/features/load.c | 21 +++++- kernel/features/mm.c | 28 +++++-- kernel/features/proc.c | 37 ++++----- kernel/features/syscall.c | 31 +++++--- kernel/inc/fb.h | 4 +- kernel/inc/fs.h | 12 +-- kernel/inc/load.h | 3 +- kernel/inc/mm.h | 6 +- 12 files changed, 214 insertions(+), 131 deletions(-) (limited to 'kernel') diff --git a/kernel/drivers/fb.c b/kernel/drivers/fb.c index 8e73f5b..af8a830 100644 --- a/kernel/drivers/fb.c +++ b/kernel/drivers/fb.c @@ -45,7 +45,7 @@ static s32 fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3, struct devi } } -static u8 fb_ready(void) +static s32 fb_ready(void) { return 1; } diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c index dbee8e1..79cd579 100644 --- a/kernel/drivers/keyboard.c +++ b/kernel/drivers/keyboard.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -62,9 +63,9 @@ static void keyboard_rate(void) static s32 keyboard_read(void *buf, u32 offset, u32 count, struct device *dev) { - (void)dev; + UNUSED(dev); if (stack_empty(queue)) - return -1; + return -EINVAL; struct event_keyboard *e = stack_pop(queue); memcpy(buf, (u8 *)e + offset, MIN(count, sizeof(*e))); @@ -72,7 +73,7 @@ static s32 keyboard_read(void *buf, u32 offset, u32 count, struct device *dev) return MIN(count, sizeof(*e)); } -static u8 keyboard_ready(void) +static s32 keyboard_ready(void) { return !stack_empty(queue); } diff --git a/kernel/drivers/mouse.c b/kernel/drivers/mouse.c index 5c481da..8545099 100644 --- a/kernel/drivers/mouse.c +++ b/kernel/drivers/mouse.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -83,7 +84,7 @@ static u8 mouse_serial_read(void) return inb(0x60); } -static u8 mouse_ready(void) +static s32 mouse_ready(void) { return !stack_empty(queue); } @@ -92,7 +93,7 @@ static s32 mouse_read(void *buf, u32 offset, u32 count, struct device *dev) { (void)dev; if (stack_empty(queue)) - return -1; + return -EINVAL; struct event_mouse *e = stack_pop(queue); memcpy(buf, (u8 *)e + offset, MIN(count, sizeof(*e))); diff --git a/kernel/features/fs.c b/kernel/features/fs.c index c692aac..56d253a 100644 --- a/kernel/features/fs.c +++ b/kernel/features/fs.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -107,9 +108,14 @@ static void vfs_list_mounts() s32 vfs_mount(struct device *dev, const char *path) { - // TODO: Check if already mounted - if (!dev || !dev->id || vfs_mounted(dev, path)) - return -1; + if (!path || !memory_valid(path)) + return -EFAULT; + + if (!dev || !memory_valid(dev) || !dev->id) + return -EFAULT; + + if (vfs_mounted(dev, path)) + return -EBUSY; char *fixed = vfs_normalize_path(path); @@ -124,25 +130,31 @@ 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() ? proc_current()->name : "Unknown", path); */ - if (!count) - return 0; + if (!path || !memory_valid(path)) + return -EFAULT; - if (offset > count || !buf) - return -1; + if (!buf || !memory_valid(buf)) + return -EFAULT; - while (*path == ' ') - path++; + if (offset > count) + return -EINVAL; struct mount_info *m = vfs_find_mount_info(path); - if (!(m && m->dev && m->dev->vfs && m->dev->vfs->read && m->dev->vfs->perm)) - return -1; + if (!m || !m->dev || !m->dev->vfs) + return -ENOENT; + + if (!m->dev->vfs->read || !m->dev->vfs->perm) + return -EINVAL; u32 len = strlen(m->path); if (len > 1) path += len; if (!m->dev->vfs->perm(path, VFS_READ, m->dev) && !proc_super()) - return -1; + return -EACCES; + + if (!count) + return 0; return m->dev->vfs->read(path, buf, offset, count, m->dev); } @@ -150,83 +162,95 @@ 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() ? proc_current()->name : "Unknown", path); */ - if (!count) - return 0; + if (!path || !memory_valid(path)) + return -EFAULT; - if (offset > count || !buf) - return -1; + if (!buf || !memory_valid(buf)) + return -EFAULT; - while (*path == ' ') - path++; + if (offset > count) + return -EINVAL; struct mount_info *m = vfs_find_mount_info(path); - if (!(m && m->dev && m->dev->vfs && m->dev->vfs->write && m->dev->vfs->perm)) - return -1; + if (!m || !m->dev || !m->dev->vfs) + return -ENOENT; + + if (!m->dev->vfs->write || !m->dev->vfs->perm) + return -EINVAL; u32 len = strlen(m->path); if (len > 1) path += len; if (!m->dev->vfs->perm(path, VFS_WRITE, m->dev) && !proc_super()) - return -1; + return -EACCES; + + if (!count) + return 0; return m->dev->vfs->write(path, buf, offset, count, m->dev); } s32 vfs_ioctl(const char *path, u32 request, void *arg1, void *arg2, void *arg3) { - while (*path == ' ') - path++; + if (!path || !memory_valid(path)) + return -EFAULT; struct mount_info *m = vfs_find_mount_info(path); - if (!(m && m->dev && m->dev->vfs && m->dev->vfs->ioctl && m->dev->vfs->perm)) - return -1; + if (!m || !m->dev || !m->dev->vfs) + return -ENOENT; + + if (!m->dev->vfs->ioctl || !m->dev->vfs->perm) + return -EINVAL; u32 len = strlen(m->path); if (len > 1) path += len; if (!m->dev->vfs->perm(path, VFS_WRITE, m->dev) && !proc_super()) - return -1; + return -EACCES; return m->dev->vfs->ioctl(path, request, arg1, arg2, arg3, m->dev); } s32 vfs_stat(const char *path, struct stat *buf) { - while (*path == ' ') - path++; + if (!path || !memory_valid(path)) + return -EFAULT; - if (!buf) - return -1; + if (!buf || !memory_valid(buf)) + return -EFAULT; struct mount_info *m = vfs_find_mount_info(path); - if (!(m && m->dev && m->dev->vfs && m->dev->vfs->stat && m->dev->vfs->perm)) - return -1; + if (!m || !m->dev || !m->dev->vfs) + return -ENOENT; + + if (!m->dev->vfs->stat || !m->dev->vfs->perm) + return -EINVAL; u32 len = strlen(m->path); if (len > 1) path += len; - if (!m->dev->vfs->perm(path, VFS_WRITE, m->dev) && !proc_super()) - return -1; + if (!m->dev->vfs->perm(path, VFS_READ, m->dev) && !proc_super()) + return -EACCES; return m->dev->vfs->stat(path, buf, m->dev); } s32 vfs_wait(const char *path, u32 func_ptr) { - while (*path == ' ') - path++; + if (!path || !func_ptr || !memory_valid(path)) + return -EFAULT; struct mount_info *m = vfs_find_mount_info(path); - if (!(m && m->dev && m->dev->vfs)) - return -1; + if (!m || !m->dev || !m->dev->vfs) + return -ENOENT; // Default wait if (!m->dev->vfs->wait) { proc_wait_for(vfs_find_dev(path)->id, PROC_WAIT_DEV, func_ptr); - return 1; + return 0; } u32 len = strlen(m->path); @@ -238,26 +262,34 @@ s32 vfs_wait(const char *path, u32 func_ptr) s32 vfs_poll(const char **files) { - if (!files) - return -1; + if (!files || !memory_valid(files)) + return -EFAULT; - for (const char **p = files; memory_user_valid((u32)*p) && *p && **p; p++) - if (vfs_ready(*p)) + for (const char **p = files; *p && memory_valid(*p) && **p; p++) { + s32 ready = vfs_ready(*p); + if (ready == 1) return p - files; + else if (ready < 0) + return ready; + } - for (const char **p = files; memory_user_valid((u32)*p) && *p && **p; p++) + for (const char **p = files; *p && memory_valid(*p) && **p; p++) vfs_wait(*p, (u32)vfs_poll); return PROC_MAX_WAIT_IDS + 1; } -u8 vfs_ready(const char *path) +s32 vfs_ready(const char *path) { - while (*path == ' ') - path++; + if (!path || !memory_valid(path)) + return -EFAULT; struct mount_info *m = vfs_find_mount_info(path); - assert(m && m->dev && m->dev->vfs && m->dev->vfs->ready); + if (!m || !m->dev || !m->dev->vfs) + return -ENOENT; + + if (!m->dev->vfs->ready) + return -EINVAL; u32 len = strlen(m->path); if (len > 1) @@ -308,8 +340,10 @@ struct device *device_get_by_name(const char *name) static s32 devfs_read(const char *path, void *buf, u32 offset, u32 count, struct device *dev) { struct device *target = device_get_by_name(path + 1); - if (!target || !target->read) - return -1; + if (!target) + return -ENOENT; + if (!target->read) + return -EINVAL; return target->read(buf, offset, count, dev); } @@ -317,26 +351,30 @@ static s32 devfs_ioctl(const char *path, u32 request, void *arg1, void *arg2, vo struct device *dev) { struct device *target = device_get_by_name(path + 1); - if (!target || !target->ioctl) - return -1; + if (!target) + return -ENOENT; + if (!target->ioctl) + return -EINVAL; return target->ioctl(request, arg1, arg2, arg3, dev); } -static u8 devfs_perm(const char *path, enum vfs_perm perm, struct device *dev) +static s32 devfs_perm(const char *path, enum vfs_perm perm, struct device *dev) { - (void)path; - (void)perm; - (void)dev; + UNUSED(path); + UNUSED(perm); + UNUSED(dev); return 1; } -static u8 devfs_ready(const char *path, struct device *dev) +static s32 devfs_ready(const char *path, struct device *dev) { - (void)dev; + UNUSED(dev); struct device *target = device_get_by_name(path + 1); - if (!target || !target->ready) - return 0; + if (!target) + return -ENOENT; + if (!target->ready) + return -EINVAL; return target->ready(); } @@ -367,7 +405,7 @@ void device_install(void) // TODO: Remove malloc from buffer_read (attempt in #56cd63f199) static void *buffer_read(u32 block, struct device *dev) { - void *buf = malloc(BLOCK_SIZE); + void *buf = zalloc(BLOCK_SIZE); dev->read(buf, block * SECTOR_COUNT, SECTOR_COUNT, dev); return buf; } @@ -448,15 +486,15 @@ static u32 read_indirect(u32 indirect, u32 block_num, struct device *dev) static s32 read_inode(struct ext2_inode *in, void *buf, u32 offset, u32 count, struct device *dev) { // TODO: Support read offset - (void)offset; + UNUSED(offset); if (!in || !buf) - return -1; + return -EINVAL; u32 num_blocks = in->blocks / (BLOCK_SIZE / SECTOR_SIZE); if (!num_blocks) - return -1; + return -EINVAL; // TODO: memcpy block chunks until count is copied while (BLOCK_SIZE * num_blocks > count) @@ -538,7 +576,7 @@ static struct ext2_inode *find_inode_by_path(const char *path, struct ext2_inode struct device *dev) { if (path[0] != '/') - return 0; + return NULL; char *path_cp = strdup(path); char *init = path_cp; // For freeing @@ -560,7 +598,7 @@ static struct ext2_inode *find_inode_by_path(const char *path, struct ext2_inode if (current_inode == 0) { free(init); - return 0; + return NULL; } path_cp += i + 1; @@ -569,7 +607,7 @@ static struct ext2_inode *find_inode_by_path(const char *path, struct ext2_inode u32 inode = find_inode(path_cp, current_inode, dev); free(init); if ((signed)inode <= 0) - return 0; + return NULL; return get_inode(inode, in_buf, dev); } @@ -580,17 +618,14 @@ s32 ext2_read(const char *path, void *buf, u32 offset, u32 count, struct device if (find_inode_by_path(path, &in, dev) == &in) return read_inode(&in, buf, offset, count, dev); else - return -1; + return -ENOENT; } s32 ext2_stat(const char *path, struct stat *buf, struct device *dev) { - if (!buf) - return -1; - struct ext2_inode in = { 0 }; if (find_inode_by_path(path, &in, dev) != &in) - return -1; + return -ENOENT; u32 num_blocks = in.blocks / (BLOCK_SIZE / SECTOR_SIZE); u32 sz = BLOCK_SIZE * num_blocks; @@ -601,11 +636,11 @@ s32 ext2_stat(const char *path, struct stat *buf, struct device *dev) return 0; } -u8 ext2_perm(const char *path, enum vfs_perm perm, struct device *dev) +s32 ext2_perm(const char *path, enum vfs_perm perm, struct device *dev) { struct ext2_inode in = { 0 }; if (find_inode_by_path(path, &in, dev) != &in) - return 0; + return -ENOENT; switch (perm) { case VFS_EXEC: @@ -619,9 +654,9 @@ u8 ext2_perm(const char *path, enum vfs_perm perm, struct device *dev) } } -u8 ext2_ready(const char *path, struct device *dev) +s32 ext2_ready(const char *path, struct device *dev) { - (void)path; - (void)dev; + UNUSED(path); + UNUSED(dev); return 1; } diff --git a/kernel/features/load.c b/kernel/features/load.c index 9e6db79..65d76d4 100644 --- a/kernel/features/load.c +++ b/kernel/features/load.c @@ -1,17 +1,27 @@ // MIT License, Copyright (c) 2020 Marvin Borner +#include #include #include #include #include #include +#include + #define PROC_STACK_SIZE 0x4000 -int bin_load(const char *path, struct proc *proc) +s32 bin_load(const char *path, struct proc *proc) { + if (!path || !memory_valid(path) || !proc) + return -EFAULT; + struct stat s = { 0 }; - vfs_stat(path, &s); + memory_bypass_enable(); + s32 stat = vfs_stat(path, &s); + memory_bypass_disable(); + if (stat != 0) + return stat; strcpy(proc->name, path); @@ -22,9 +32,12 @@ int bin_load(const char *path, struct proc *proc) u32 size = PAGE_ALIGN_UP(s.size); u32 data = (u32)memory_alloc(proc->page_dir, size, MEMORY_USER | MEMORY_CLEAR); - if (!vfs_read(proc->name, (void *)data, 0, s.size)) { + memory_bypass_enable(); + s32 read = vfs_read(proc->name, (void *)data, 0, s.size); + memory_bypass_disable(); + if (read <= 0) { memory_switch_dir(prev); - return 1; + return read; } u32 stack = (u32)memory_alloc(proc->page_dir, PROC_STACK_SIZE, MEMORY_USER | MEMORY_CLEAR); diff --git a/kernel/features/mm.c b/kernel/features/mm.c index 875d752..2171598 100644 --- a/kernel/features/mm.c +++ b/kernel/features/mm.c @@ -331,9 +331,7 @@ struct page_dir *virtual_kernel_dir(void) void *memory_alloc(struct page_dir *dir, u32 size, u32 flags) { - assert(PAGE_ALIGNED(size)); - - if (!size) + if (!PAGE_ALIGNED(size) || !size) goto err; struct memory_range prange = physical_alloc(size); @@ -352,8 +350,8 @@ void *memory_alloc(struct page_dir *dir, u32 size, u32 flags) return (void *)vaddr; err: - print("Memory allocation error!\n"); - return 0; + printf("Memory allocation error!\n"); + return NULL; } void *memory_alloc_identity(struct page_dir *dir, u32 flags) @@ -411,10 +409,24 @@ void memory_backup_dir(struct page_dir **backup) *backup = dir; } -// TODO: Check memory validity more often -u8 memory_user_valid(u32 addr) +// TODO: Verify that this isn't a huge security risk +static u8 memory_bypass_validity = 0; +void memory_bypass_enable(void) +{ + memory_bypass_validity = 1; +} + +void memory_bypass_disable(void) +{ + memory_bypass_validity = 0; +} + +u8 memory_valid(const void *addr) { - return addr / PAGE_SIZE / PAGE_COUNT >= PAGE_KERNEL_COUNT; + if (proc_current() && !memory_bypass_validity) + return ((u32)addr) / PAGE_SIZE / PAGE_COUNT >= PAGE_KERNEL_COUNT; + else + return 1; } struct memory_range memory_range_from(u32 base, u32 size) diff --git a/kernel/features/proc.c b/kernel/features/proc.c index b93f7c8..cd0fc8d 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -260,6 +261,8 @@ struct proc *proc_make(enum proc_priv priv) void proc_stack_push(struct proc *proc, u32 data) { + assert(proc && proc->regs.useresp > sizeof(data)); + struct page_dir *prev; memory_backup_dir(&prev); memory_switch_dir(proc->page_dir); @@ -361,7 +364,7 @@ static s32 procfs_read(const char *path, void *buf, u32 offset, u32 count, struc if (pid) { struct proc *p = proc_from_pid(pid); if (!p || path[0] != '/') - return -1; + return -ENOENT; path++; if (!memcmp(path, "pid", 4)) { @@ -377,11 +380,11 @@ static s32 procfs_read(const char *path, void *buf, u32 offset, u32 count, struc return count; } else if (!memcmp(path, "msg", 4)) { if (stack_empty(p->messages)) { - return -1; // This shouldn't happen + return -EIO; // This shouldn't happen } else { struct procfs_message *msg = stack_pop(p->messages); if (!msg) - return -1; + return -EIO; memcpy(buf, msg->data + offset, MIN(count, msg->size)); free(msg->data); free(msg); @@ -391,7 +394,7 @@ static s32 procfs_read(const char *path, void *buf, u32 offset, u32 count, struc path += 3; enum stream_defaults id = procfs_stream(path); if (id == STREAM_UNKNOWN) - return -1; + return -ENOENT; struct stream *stream = &p->streams[id]; memcpy(buf, stream->data + stream->offset_read, count); stream->offset_read += count; @@ -399,7 +402,7 @@ static s32 procfs_read(const char *path, void *buf, u32 offset, u32 count, struc } } - return -1; + return -ENOENT; } static s32 procfs_wait(const char *path, u32 func_ptr, struct device *dev) @@ -410,22 +413,22 @@ static s32 procfs_wait(const char *path, u32 func_ptr, struct device *dev) if (pid) { struct proc *p = proc_from_pid(pid); if (!p || path[0] != '/') - return -1; + return -ENOENT; path++; if (!memcmp(path, "msg", 4)) { proc_wait_for(pid, PROC_WAIT_MSG, func_ptr); - return 1; + return 0; } else { proc_wait_for(dev->id, PROC_WAIT_DEV, func_ptr); - return 1; + return 0; } } - return -1; + return -ENOENT; } -static u8 procfs_perm(const char *path, enum vfs_perm perm, struct device *dev) +static s32 procfs_perm(const char *path, enum vfs_perm perm, struct device *dev) { (void)path; (void)dev; @@ -436,7 +439,7 @@ static u8 procfs_perm(const char *path, enum vfs_perm perm, struct device *dev) return 1; } -static u8 procfs_ready(const char *path, struct device *dev) +static s32 procfs_ready(const char *path, struct device *dev) { (void)dev; @@ -446,7 +449,7 @@ static u8 procfs_ready(const char *path, struct device *dev) if (pid) { struct proc *p = proc_from_pid(pid); if (!p || path[0] != '/') - return -1; + return -ENOENT; path++; if (!memcmp(path, "msg", 4)) { @@ -455,7 +458,7 @@ static u8 procfs_ready(const char *path, struct device *dev) path += 3; enum stream_defaults id = procfs_stream(path); if (id == STREAM_UNKNOWN) - return -1; + return -ENOENT; struct stream *stream = &p->streams[id]; return stream->data[stream->offset_read] != 0; } @@ -490,26 +493,26 @@ void proc_init(void) dev->type = DEV_CHAR; dev->vfs = vfs; device_add(dev); - vfs_mount(dev, "/proc/"); + assert(vfs_mount(dev, "/proc/") == 0); // Idle proc struct proc *kernel_proc = proc_make(PROC_PRIV_NONE); - bin_load("/bin/idle", kernel_proc); + assert(bin_load("/bin/idle", kernel_proc) == 0); kernel_proc->state = PROC_SLEEPING; idle_proc = list_add(proc_list, kernel_proc); // Init proc (root) struct node *new = list_add(proc_list, proc_make(PROC_PRIV_ROOT)); - bin_load("/bin/init", new->data); + assert(bin_load("/bin/init", new->data) == 0); current = new; proc_stack_push(new->data, 0); _eip = ((struct proc *)new->data)->regs.eip; _esp = ((struct proc *)new->data)->regs.useresp; - printf("Jumping to userspace!\n"); memory_switch_dir(((struct proc *)new->data)->page_dir); + printf("Jumping to userspace!\n"); // You're waiting for a train. A train that will take you far away... proc_jump_userspace(); diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c index 68bcbaa..b0b37ac 100644 --- a/kernel/features/syscall.c +++ b/kernel/features/syscall.c @@ -1,6 +1,7 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include +#include #include #include #include @@ -24,6 +25,7 @@ static void syscall_handler(struct regs *r) switch (num) { case SYS_LOOP: { loop(); + panic("Fell out of the looping!\n"); break; } case SYS_ALLOC: { @@ -43,8 +45,9 @@ static void syscall_handler(struct regs *r) if (vfs_ready((char *)r->ebx)) { r->eax = (u32)vfs_read((char *)r->ebx, (void *)r->ecx, r->edx, r->esi); } else { - if (vfs_wait((char *)r->ebx, (u32)vfs_read) < 0) - r->eax = -1; + s32 wait = vfs_wait((char *)r->ebx, (u32)vfs_read); + if (wait != 0) + r->eax = wait; else proc_yield(r); } @@ -61,20 +64,19 @@ static void syscall_handler(struct regs *r) } case SYS_POLL: { s32 ret = vfs_poll((const char **)r->ebx); + r->eax = ret; if (ret == PROC_MAX_WAIT_IDS + 1) proc_yield(r); - else - r->eax = ret; break; } case SYS_EXEC: { char *path = (char *)r->ebx; struct proc *proc = proc_make(PROC_PRIV_NONE); r->eax = (u32)bin_load(path, proc); + if (r->eax != 0) + proc_exit(proc, -r->eax); // TODO: Reimplement argc,argv proc_stack_push(proc, 0); - if (r->eax) - proc_exit(proc, (int)r->eax); proc_yield(r); break; } @@ -83,10 +85,13 @@ static void syscall_handler(struct regs *r) break; } case SYS_BOOT: { // TODO: Move - if (r->ebx != SYS_BOOT_MAGIC || !proc_super()) { - r->eax = -1; + if (r->ebx != SYS_BOOT_MAGIC) { + r->eax = -EINVAL; break; } + if (!proc_super()) { + r->eax = -EACCES; + } switch (r->ecx) { case SYS_BOOT_REBOOT: print("Rebooting...\n"); @@ -102,7 +107,7 @@ static void syscall_handler(struct regs *r) __asm__ volatile("ud2"); break; default: - r->eax = -1; + r->eax = -EINVAL; } break; } @@ -114,6 +119,13 @@ static void syscall_handler(struct regs *r) r->eax = timer_get(); break; } + // TODO: Reimplement network functions using VFS + case SYS_NET_OPEN: + case SYS_NET_CLOSE: + case SYS_NET_CONNECT: + case SYS_NET_SEND: + case SYS_NET_RECEIVE: +#if 0 case SYS_NET_OPEN: { r->eax = (int)net_open(r->ebx); break; @@ -146,6 +158,7 @@ static void syscall_handler(struct regs *r) r->eax = net_receive((void *)r->ebx, (void *)r->ecx, r->edx); break; } +#endif default: { printf("Unknown syscall %d!\n", num); break; diff --git a/kernel/inc/fb.h b/kernel/inc/fb.h index 3e7b08f..212230b 100644 --- a/kernel/inc/fb.h +++ b/kernel/inc/fb.h @@ -1,7 +1,7 @@ // MIT License, Copyright (c) 2021 Marvin Borner -#ifndef FB -#define FB +#ifndef FB_H +#define FB_H #include diff --git a/kernel/inc/fs.h b/kernel/inc/fs.h index cd97b99..fd5c470 100644 --- a/kernel/inc/fs.h +++ b/kernel/inc/fs.h @@ -21,7 +21,7 @@ struct device { s32 (*read)(void *buf, u32 offset, u32 count, struct device *dev); s32 (*write)(void *buf, u32 offset, u32 count, struct device *dev); s32 (*ioctl)(u32 request, void *arg1, void *arg2, void *arg3, struct device *dev); - u8 (*ready)(void); + s32 (*ready)(void); }; void device_install(void); @@ -45,8 +45,8 @@ struct vfs { struct device *dev); s32 (*stat)(const char *path, struct stat *buf, struct device *dev); s32 (*wait)(const char *path, u32 func_ptr, struct device *dev); - u8 (*perm)(const char *path, enum vfs_perm perm, struct device *dev); - u8 (*ready)(const char *path, struct device *dev); + s32 (*ready)(const char *path, struct device *dev); + s32 (*perm)(const char *path, enum vfs_perm perm, struct device *dev); }; struct mount_info { @@ -67,7 +67,7 @@ s32 vfs_ioctl(const char *path, u32 request, void *arg1, void *arg2, void *arg3) s32 vfs_stat(const char *path, struct stat *buf); s32 vfs_wait(const char *path, u32 func_ptr); s32 vfs_poll(const char **files); -u8 vfs_ready(const char *path); +s32 vfs_ready(const char *path); struct device *device_get_by_name(const char *name); struct device *device_get_by_id(u32 id); @@ -176,7 +176,7 @@ struct ext2_file { s32 ext2_read(const char *path, void *buf, u32 offset, u32 count, struct device *dev); s32 ext2_stat(const char *path, struct stat *buf, struct device *dev); -u8 ext2_perm(const char *path, enum vfs_perm perm, struct device *dev); -u8 ext2_ready(const char *path, struct device *dev); +s32 ext2_perm(const char *path, enum vfs_perm perm, struct device *dev); +s32 ext2_ready(const char *path, struct device *dev); #endif diff --git a/kernel/inc/load.h b/kernel/inc/load.h index f493e84..bd3b10d 100644 --- a/kernel/inc/load.h +++ b/kernel/inc/load.h @@ -3,8 +3,9 @@ #ifndef LOAD_H #define LOAD_H +#include #include -int bin_load(const char *path, struct proc *proc); +s32 bin_load(const char *path, struct proc *proc); #endif diff --git a/kernel/inc/mm.h b/kernel/inc/mm.h index fa2ebd1..98dcf46 100644 --- a/kernel/inc/mm.h +++ b/kernel/inc/mm.h @@ -101,7 +101,11 @@ void memory_map_identity(struct page_dir *dir, struct memory_range prange, u32 f void memory_free(struct page_dir *dir, struct memory_range vrange); void memory_switch_dir(struct page_dir *dir); void memory_backup_dir(struct page_dir **backup); -u8 memory_user_valid(u32 addr); + +// Bypass should almost never be used +void memory_bypass_enable(void); +void memory_bypass_disable(void); +u8 memory_valid(const void *addr); void memory_install(struct mem_info *mem_info, struct vid_info *vid_info); -- cgit v1.2.3