diff options
author | Marvin Borner | 2021-04-06 22:20:58 +0200 |
---|---|---|
committer | Marvin Borner | 2021-04-06 22:35:13 +0200 |
commit | 64ec8aa157e5d5d09372def37cbab00628e1e5f5 (patch) | |
tree | 13d0c864780a62506d40266fa6f2ab9571cbd216 /kernel/features/load.c | |
parent | 9326d3970fe6eedbcb042ac68aca3074aacef32f (diff) |
Made exec syscall relative using app name
My plan is to implement a mobile-OS-like sandboxing using manifests
and permission middlewares. Let's see if I can manage to do this
without sacrificing too much performance.
I'm also wondering whether I should implement open/close syscalls
which would result in a cleaner block/unblock mechanism. I need to
think. Hmmm.. Naa
Diffstat (limited to 'kernel/features/load.c')
-rw-r--r-- | kernel/features/load.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/kernel/features/load.c b/kernel/features/load.c index d87bb94..91954b1 100644 --- a/kernel/features/load.c +++ b/kernel/features/load.c @@ -9,11 +9,19 @@ #include <random.h> #include <str.h> -res elf_load(const char *path, struct proc *proc) +res elf_load(const char *name, struct proc *proc) { - if (!memory_valid(path)) + if (!memory_valid(name)) return -EFAULT; + stac(); + char path[64] = { "/apps/" }; + strlcat(path, name, sizeof(path)); + strlcpy(proc->dir, path, sizeof(proc->dir)); + strlcat(path, "/exec", sizeof(path)); + strlcpy(proc->name, name, sizeof(proc->name)); + clac(); + struct stat s = { 0 }; memory_bypass_enable(); res stat = vfs_stat(path, &s); @@ -32,10 +40,6 @@ res elf_load(const char *path, struct proc *proc) if (read != sizeof(header)) return -ENOEXEC; - stac(); - strlcpy(proc->name, path, sizeof(proc->name)); - clac(); - // Valid? u8 *magic = header.ident; u8 valid_magic = magic[ELF_IDENT_MAG0] == ELF_MAG0 && magic[ELF_IDENT_MAG1] == ELF_MAG1 && @@ -86,8 +90,8 @@ res elf_load(const char *path, struct proc *proc) virtual_map(proc->page_dir, prange, vrange.base, MEMORY_CLEAR | MEMORY_USER); memory_bypass_enable(); - if ((u32)vfs_read(proc->name, (void *)((u32)program.vaddr + rand_off), - program.offset, program.filesz) != program.filesz) { + if ((u32)vfs_read(path, (void *)((u32)program.vaddr + rand_off), program.offset, + program.filesz) != program.filesz) { memory_bypass_disable(); memory_switch_dir(prev); return -ENOEXEC; |