Browse Source

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.
Daniel Bertalan 4 years ago
parent
commit
d30dbf47f5
1 changed files with 4 additions and 1 deletions
  1. 4 1
      Kernel/Syscalls/execve.cpp

+ 4 - 1
Kernel/Syscalls/execve.cpp

@@ -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;