ELFLoader: Consider the offset when calculating how many pages to map
If a section needs to be mapped at 0x50f50 and its size is 0x200, then that address space exceeds one page. But since 0x200 is less than one page, we only map one page. If we count the offset, 0xf50 + 0x200 need two pages. So we can map the right amount of memory.
This commit is contained in:
parent
bbd9f1d187
commit
4768d5fc12
@ -103,7 +103,7 @@ ELFImage* ELFLoader::load_elf_from_address(uintptr_t addr)
|
||||
kerrorln("Address is NULL, this is invalid :(");
|
||||
return 0;
|
||||
}
|
||||
uint64_t pages = Utilities::get_blocks_from_size(PAGE_SIZE, phdr->p_memsz);
|
||||
uint64_t pages = Utilities::get_blocks_from_size(PAGE_SIZE, (phdr->p_vaddr % PAGE_SIZE) + phdr->p_memsz);
|
||||
void* buffer = MemoryManager::get_pages_at(phdr->p_vaddr, pages,
|
||||
phdr->p_flags & 2 ? MAP_READ_WRITE | MAP_USER : MAP_USER);
|
||||
memcpy(buffer, (void*)(addr + phdr->p_offset), phdr->p_filesz);
|
||||
|
Loading…
Reference in New Issue
Block a user