forked from Bananymous/banan-os
Kernel: More proper paging in Elf loading
This commit is contained in:
parent
8a5608df91
commit
82a1a29260
|
@ -64,6 +64,9 @@ namespace Kernel
|
||||||
break;
|
break;
|
||||||
case LibELF::PT_LOAD:
|
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_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);
|
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));
|
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();
|
auto paddr = Memory::Heap::get().take_free_page();
|
||||||
MUST(process->m_allocated_pages.push_back(paddr));
|
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();
|
process->m_mmu->load();
|
||||||
memcpy((void*)elf_program_header.p_vaddr, elf->data() + elf_program_header.p_offset, elf_program_header.p_filesz);
|
memcpy((void*)elf_program_header.p_vaddr, elf->data() + elf_program_header.p_offset, elf_program_header.p_filesz);
|
||||||
|
|
|
@ -74,7 +74,7 @@ namespace Kernel
|
||||||
|
|
||||||
Thread::~Thread()
|
Thread::~Thread()
|
||||||
{
|
{
|
||||||
dprintln("thread {} exit", tid());
|
dprintln("thread {} ({}) exit", tid(), m_process->pid());
|
||||||
kfree(m_stack_base);
|
kfree(m_stack_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue