Apparently, it just works now.

This commit is contained in:
apio 2022-10-14 18:00:33 +02:00
parent 97a8a4a4a2
commit e43777bd31
4 changed files with 8 additions and 11 deletions

View File

@ -47,7 +47,7 @@ void VMM::exit_syscall_context()
void VMM::apply_address_space() void VMM::apply_address_space()
{ {
asm volatile("mov %0, %%cr3" : : "r"(current_pml4)); write_cr3(current_pml4);
} }
bool VMM::is_using_kernel_address_space() bool VMM::is_using_kernel_address_space()

View File

@ -95,6 +95,7 @@ ELFImage* ELFLoader::load_elf_from_vfs(VFS::Node* node)
pages, MAP_READ_WRITE) + pages, MAP_READ_WRITE) +
(phdr.p_vaddr % PAGE_SIZE)); (phdr.p_vaddr % PAGE_SIZE));
if (VMM::is_using_kernel_address_space()) { VMM::switch_to_previous_user_address_space(); }
VMM::apply_address_space(); VMM::apply_address_space();
VFS::read(node, phdr.p_offset, phdr.p_filesz, (char*)buffer); VFS::read(node, phdr.p_offset, phdr.p_filesz, (char*)buffer);

View File

@ -12,12 +12,12 @@
#include "sys/elf/ELFLoader.h" #include "sys/elf/ELFLoader.h"
#include "thread/Scheduler.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. /*context->rax = -ENOSYS; // FIXME: Make exec() work under separate address spaces.
return; return;*/
/*char* kpathname = Syscall::strdup_from_user(pathname); char* kpathname = Syscall::strdup_from_user(pathname);
if (!kpathname) if (!kpathname)
{ {
context->rax = -EFAULT; context->rax = -EFAULT;
@ -75,10 +75,7 @@ void sys_exec(Context* context, const char*)
// At this point, pretty much nothing can fail. // At this point, pretty much nothing can fail.
VMM::switch_back_to_kernel_address_space(); // task->address_space.reset();
VMM::apply_address_space();
task->address_space.reset();
// VMM::switch_to_user_address_space(task->address_space); // VMM::switch_to_user_address_space(task->address_space);
@ -99,5 +96,5 @@ void sys_exec(Context* context, const char*)
kfree(kpathname); kfree(kpathname);
return;*/ return;
} }

View File

@ -57,7 +57,6 @@ void Scheduler::init()
// the other registers will be saved next task switch // the other registers will be saved next task switch
frequency = 1000 / PIT::frequency(); frequency = 1000 / PIT::frequency();
kdbgln("frequency: %ld", frequency);
} }
void Scheduler::add_kernel_task(void (*task)(void)) void Scheduler::add_kernel_task(void (*task)(void))