Kernel: Invalid physical addresses from heap are specified now by 0
This commit is contained in:
parent
ab8aac7dcf
commit
9c07add00f
|
@ -15,9 +15,6 @@ namespace Kernel
|
||||||
|
|
||||||
class PhysicalRange
|
class PhysicalRange
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
static constexpr paddr_t invalid = ~paddr_t(0);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PhysicalRange(paddr_t, size_t);
|
PhysicalRange(paddr_t, size_t);
|
||||||
paddr_t reserve_page();
|
paddr_t reserve_page();
|
||||||
|
|
|
@ -55,7 +55,7 @@ namespace Kernel
|
||||||
paddr_t PhysicalRange::reserve_page()
|
paddr_t PhysicalRange::reserve_page()
|
||||||
{
|
{
|
||||||
if (m_free_list == nullptr)
|
if (m_free_list == nullptr)
|
||||||
return invalid;
|
return 0;
|
||||||
|
|
||||||
node* page = m_free_list;
|
node* page = m_free_list;
|
||||||
ASSERT(page->next == nullptr);
|
ASSERT(page->next == nullptr);
|
||||||
|
@ -161,7 +161,7 @@ namespace Kernel
|
||||||
paddr_t Heap::take_free_page()
|
paddr_t Heap::take_free_page()
|
||||||
{
|
{
|
||||||
for (auto& range : m_physical_ranges)
|
for (auto& range : m_physical_ranges)
|
||||||
if (paddr_t page = range.reserve_page(); page != PhysicalRange::invalid)
|
if (paddr_t page = range.reserve_page())
|
||||||
return page;
|
return page;
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,14 +75,14 @@ namespace Kernel
|
||||||
uint8_t flags = MMU::Flags::UserSupervisor | MMU::Flags::Present;
|
uint8_t flags = MMU::Flags::UserSupervisor | MMU::Flags::Present;
|
||||||
if (elf_program_header.p_flags & LibELF::PF_W)
|
if (elf_program_header.p_flags & LibELF::PF_W)
|
||||||
flags |= MMU::Flags::ReadWrite;
|
flags |= MMU::Flags::ReadWrite;
|
||||||
size_t page_start = elf_program_header.p_vaddr / 4096;
|
size_t page_start = elf_program_header.p_vaddr / PAGE_SIZE;
|
||||||
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, PAGE_SIZE);
|
||||||
MUST(process->m_allocated_pages.reserve(page_end - page_start + 1));
|
MUST(process->m_allocated_pages.reserve(page_end - page_start + 1));
|
||||||
for (size_t page = page_start; page <= page_end; page++)
|
for (size_t page = page_start; page <= page_end; page++)
|
||||||
{
|
{
|
||||||
auto paddr = Heap::get().take_free_page();
|
auto paddr = 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, flags);
|
process->m_mmu->map_page_at(paddr, page * PAGE_SIZE, 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);
|
||||||
|
|
Loading…
Reference in New Issue