diff --git a/kernel/src/memory/VMM.cpp b/kernel/src/memory/VMM.cpp index 73679674..94192275 100644 --- a/kernel/src/memory/VMM.cpp +++ b/kernel/src/memory/VMM.cpp @@ -47,7 +47,7 @@ void VMM::exit_syscall_context() void VMM::apply_address_space() { - asm volatile("mov %0, %%cr3" : : "r"(current_pml4)); + write_cr3(current_pml4); } bool VMM::is_using_kernel_address_space() diff --git a/kernel/src/sys/elf/ELFLoader.cpp b/kernel/src/sys/elf/ELFLoader.cpp index 858ecc32..647f1586 100644 --- a/kernel/src/sys/elf/ELFLoader.cpp +++ b/kernel/src/sys/elf/ELFLoader.cpp @@ -95,6 +95,7 @@ ELFImage* ELFLoader::load_elf_from_vfs(VFS::Node* node) pages, MAP_READ_WRITE) + (phdr.p_vaddr % PAGE_SIZE)); + if (VMM::is_using_kernel_address_space()) { VMM::switch_to_previous_user_address_space(); } VMM::apply_address_space(); VFS::read(node, phdr.p_offset, phdr.p_filesz, (char*)buffer); diff --git a/kernel/src/sys/exec.cpp b/kernel/src/sys/exec.cpp index c160b804..a157d6e4 100644 --- a/kernel/src/sys/exec.cpp +++ b/kernel/src/sys/exec.cpp @@ -12,12 +12,12 @@ #include "sys/elf/ELFLoader.h" #include "thread/Scheduler.h" -void sys_exec(Context* context, const char*) +void sys_exec(Context* context, const char* pathname) { - context->rax = -ENOSYS; // FIXME: Make exec() work under separate address spaces. - return; + /*context->rax = -ENOSYS; // FIXME: Make exec() work under separate address spaces. + return;*/ - /*char* kpathname = Syscall::strdup_from_user(pathname); + char* kpathname = Syscall::strdup_from_user(pathname); if (!kpathname) { context->rax = -EFAULT; @@ -75,10 +75,7 @@ void sys_exec(Context* context, const char*) // At this point, pretty much nothing can fail. - VMM::switch_back_to_kernel_address_space(); - VMM::apply_address_space(); - - task->address_space.reset(); + // task->address_space.reset(); // VMM::switch_to_user_address_space(task->address_space); @@ -99,5 +96,5 @@ void sys_exec(Context* context, const char*) kfree(kpathname); - return;*/ + return; } \ No newline at end of file diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index 1dd03f89..5ec334bd 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -57,7 +57,6 @@ void Scheduler::init() // the other registers will be saved next task switch frequency = 1000 / PIT::frequency(); - kdbgln("frequency: %ld", frequency); } void Scheduler::add_kernel_task(void (*task)(void))