Kernel: More proper paging in Elf loading

This commit is contained in:
Bananymous 2023-04-22 18:17:44 +03:00
parent 8a5608df91
commit 82a1a29260
2 changed files with 5 additions and 2 deletions

View File

@ -64,6 +64,9 @@ namespace Kernel
break;
case LibELF::PT_LOAD:
{
uint8_t flags = MMU::Flags::UserSupervisor | MMU::Flags::Present;
if (elf_program_header.p_flags & LibELF::PF_W)
flags |= MMU::Flags::ReadWrite;
size_t page_start = elf_program_header.p_vaddr / 4096;
size_t page_end = BAN::Math::div_round_up<size_t>(elf_program_header.p_vaddr + elf_program_header.p_memsz, 4096);
MUST(process->m_allocated_pages.reserve(page_end - page_start + 1));
@ -71,7 +74,7 @@ namespace Kernel
{
auto paddr = Memory::Heap::get().take_free_page();
MUST(process->m_allocated_pages.push_back(paddr));
process->m_mmu->map_page_at(paddr, page * 4096, MMU::Flags::UserSupervisor | MMU::Flags::ReadWrite | MMU::Flags::Present);
process->m_mmu->map_page_at(paddr, page * 4096, flags);
}
process->m_mmu->load();
memcpy((void*)elf_program_header.p_vaddr, elf->data() + elf_program_header.p_offset, elf_program_header.p_filesz);

View File

@ -74,7 +74,7 @@ namespace Kernel
Thread::~Thread()
{
dprintln("thread {} exit", tid());
dprintln("thread {} ({}) exit", tid(), m_process->pid());
kfree(m_stack_base);
}