aboutsummaryrefslogtreecommitdiff
path: root/kernel/features/load.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/features/load.c')
-rw-r--r--kernel/features/load.c21
1 files changed, 17 insertions, 4 deletions
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 <errno.h>
#include <fs.h>
#include <load.h>
#include <mem.h>
#include <mm.h>
#include <str.h>
+#include <print.h>
+
#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);