diff --git a/kernel/src/ELF.cpp b/kernel/src/ELF.cpp index c9fe522f..df28d389 100644 --- a/kernel/src/ELF.cpp +++ b/kernel/src/ELF.cpp @@ -89,7 +89,8 @@ namespace ELFLoader program_header.p_offset, program_header.p_vaddr, program_header.p_filesz, program_header.p_memsz); - check(is_aligned(program_header.p_vaddr)); + u64 base_vaddr = align_down(program_header.p_vaddr); + u64 vaddr_diff = program_header.p_vaddr - base_vaddr; /*expect(!can_write_and_execute_segment(program_header.p_flags), "Segment is both writable and executable");*/ @@ -99,8 +100,8 @@ namespace ELFLoader flags &= ~MMU::NoExecute; // Allocate physical memory for the segment - TRY(MemoryManager::alloc_at(program_header.p_vaddr, - get_blocks_from_size(program_header.p_memsz, ARCH_PAGE_SIZE), flags)); + TRY(MemoryManager::alloc_at( + base_vaddr, get_blocks_from_size(program_header.p_memsz + vaddr_diff, ARCH_PAGE_SIZE), flags)); // Load the file section of the segment stream.read_contents(elf_entry, (void*)program_header.p_vaddr, program_header.p_offset,