From 79e6de325ff3f52368567d388ce7f937e25e51b4 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sat, 22 Apr 2023 19:03:30 +0300 Subject: [PATCH] Kernel: Process can now load 32 bit elf files on i386 We are page faulting on process exit but I'm investigating the reason. --- kernel/kernel/Process.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index fc9a777a..14425fd9 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -46,17 +46,22 @@ namespace Kernel BAN::ErrorOr Process::create_userspace(BAN::StringView path) { auto* elf = TRY(LibELF::ELF::load_from_file(path)); - + if (!elf->is_native()) + { + derrorln("ELF has invalid architecture"); + return BAN::Error::from_errno(EINVAL); + } + auto* process = create_process(); MUST(process->m_working_directory.push_back('/')); MUST(process->init_stdio()); process->m_mmu = new MMU(); ASSERT(process->m_mmu); - auto& elf_file_header = elf->file_header64(); + auto& elf_file_header = elf->file_header_native(); for (size_t i = 0; i < elf_file_header.e_phnum; i++) { - auto& elf_program_header = elf->program_header64(i); + auto& elf_program_header = elf->program_header_native(i); switch (elf_program_header.p_type) { @@ -105,7 +110,10 @@ namespace Kernel { ASSERT(m_threads.empty()); if (m_mmu) + { + MMU::get().load(); delete m_mmu; + } for (auto paddr : m_allocated_pages) Memory::Heap::get().release_page(paddr); }