diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/Makefile | 4 | ||||
-rw-r--r-- | kernel/drivers/cpu.c | 2 | ||||
-rw-r--r-- | kernel/features/fs.c | 4 | ||||
-rw-r--r-- | kernel/features/load.c | 20 | ||||
-rw-r--r-- | kernel/features/proc.c | 4 | ||||
-rw-r--r-- | kernel/inc/load.h | 2 | ||||
-rw-r--r-- | kernel/inc/proc.h | 3 |
7 files changed, 22 insertions, 17 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index 1c37168..e28d2d8 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -31,5 +31,5 @@ all: compile @$(AS) $(ASFLAGS) $< -o $@ compile: $(COBJS) - @mkdir -p $(BUILD)/apps/ - @$(LD) -N -z max-page-size=0x1000 -ekernel_main -Tlink.ld -o $(BUILD)/apps/kernel -L$(BUILD) $+ -lk + @mkdir -p $(BUILD)/apps/kernel/ + @$(LD) -N -z max-page-size=0x1000 -ekernel_main -Tlink.ld -o $(BUILD)/apps/kernel/exec -L$(BUILD) $+ -lk diff --git a/kernel/drivers/cpu.c b/kernel/drivers/cpu.c index 86ae2be..f751d33 100644 --- a/kernel/drivers/cpu.c +++ b/kernel/drivers/cpu.c @@ -145,7 +145,7 @@ CLEAR void cpu_enable_features(void) panic("No FPU support!\n"); } - // Enable NX (IA32_EFER.NXE) + // Enable NX (IA32_EFER.NXE) // TODO: Use NX Bit? (only possible in PAE 64 bit paging?) if (cpu_extended_information.edx & CPUID_EXT_INFO_EDX_NX) { __asm__ volatile("movl $0xc0000080, %ecx\n" "rdmsr\n" diff --git a/kernel/features/fs.c b/kernel/features/fs.c index 47e7891..b5bb2a4 100644 --- a/kernel/features/fs.c +++ b/kernel/features/fs.c @@ -565,7 +565,7 @@ static res read_inode(struct ext2_inode *in, void *buf, u32 offset, u32 count, s static u32 find_inode(const char *name, u32 dir_inode, struct device *dev) { - if (!dir_inode) + if ((signed)dir_inode <= 0) return (unsigned)-1; struct ext2_inode i = { 0 }; @@ -624,7 +624,7 @@ static struct ext2_inode *find_inode_by_path(const char *path, struct ext2_inode current_inode = find_inode(path_cp, current_inode, dev); path_cp[i] = '/'; - if (current_inode == 0) { + if ((signed)current_inode <= 0) { free(init); return NULL; } 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; diff --git a/kernel/features/proc.c b/kernel/features/proc.c index f547193..479427c 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -559,7 +559,7 @@ NORETURN void proc_init(void) // Idle proc // TODO: Reimplement hlt privileges in idle proc (SMEP!) struct proc *kernel_proc = proc_make(PROC_PRIV_NONE); - assert(elf_load("/bin/idle", kernel_proc) == EOK); + assert(elf_load("idle", kernel_proc) == EOK); proc_stack_push(kernel_proc, 0); proc_stack_push(kernel_proc, 0); kernel_proc->state = PROC_BLOCKED; @@ -570,7 +570,7 @@ NORETURN void proc_init(void) // Init proc (root) struct proc *init = proc_make(PROC_PRIV_ROOT); - assert(elf_load("/bin/init", init) == EOK); + assert(elf_load("init", init) == EOK); proc_stack_push(init, 0); proc_stack_push(init, 0); current = list_first_data(proc_list_running, init); diff --git a/kernel/inc/load.h b/kernel/inc/load.h index af59cce..9e62369 100644 --- a/kernel/inc/load.h +++ b/kernel/inc/load.h @@ -161,6 +161,6 @@ struct PACKED elf_symbol { u16 shndx; }; -res elf_load(const char *path, struct proc *proc) NONNULL; +res elf_load(const char *name, struct proc *proc) NONNULL; #endif diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h index d20a1b0..dcc2eeb 100644 --- a/kernel/inc/proc.h +++ b/kernel/inc/proc.h @@ -53,7 +53,8 @@ struct stream { struct proc { u32 pid; u32 entry; - char name[32]; + char name[64]; + char dir[64]; struct stream streams[4]; struct page_dir *page_dir; struct regs regs; |