1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 19:15:09 +00:00

Kernel: Map non-page-aligned text segments correctly

`.text` segments with non-aligned offsets had their lengths applied to
the first page's base address. This meant that in some cases the last
PAGE_SIZE - 1 bytes weren't mapped. Previously, it did not cause any
problems as the GNU ld insists on aligning everything; but that's not
the case with the LLVM toolchain.
This commit is contained in:
Daniel Bertalan 2021-07-07 20:38:54 +02:00 committed by Gunnar Beutner
parent ae8c4618b7
commit d30dbf47f5

View file

@ -387,7 +387,10 @@ static KResultOr<LoadResult> load_elf_object(NonnullOwnPtr<Space> new_space, Fil
prot |= PROT_WRITE;
if (program_header.is_executable())
prot |= PROT_EXEC;
auto range = new_space->allocate_range(program_header.vaddr().offset(load_offset), program_header.size_in_memory());
auto range_base = VirtualAddress { page_round_down(program_header.vaddr().offset(load_offset).get()) };
auto range_end = VirtualAddress { page_round_up(program_header.vaddr().offset(load_offset).offset(program_header.size_in_memory()).get()) };
auto range = new_space->allocate_range(range_base, range_end.get() - range_base.get());
if (!range.has_value()) {
ph_load_result = ENOMEM;
return IterationDecision::Break;