Track ELF segments and the vDSO page as Linux maps them

Closed
XA
9d ago
+122-13

Intent: /proc/self/maps and VmSize describe the guest the way Linux does: ELF segments are tracked at page granularity, the vDSO page has a [vdso] record, and [shim] and [shim-data] are left out of VmSize.

Failure fixed: on main,

  • a PT_LOAD segment is tracked from p_vaddr to p_vaddr + p_memsz, so /proc/self/maps prints an unaligned file offset (0x7f880 where Linux prints 0x7f000);
  • the vDSO page is mapped but has no region record, so /proc/self/maps has no [vdso] line and the mmap allocator does not see the page as taken;
  • VmSize counts [shim] and [shim-data], which a Linux process does not have: it reads 2879 kB for a static binary whose guest mappings total 828 kB.

This PR: guest_region_add_elf_segment tracks a segment the way elf_map maps it, from the page holding p_vaddr to the page past its end with the offset moved back by the same amount, on both the bootstrap and the execve path. A page two segments share goes to the later one, as the later MAP_FIXED takes it in Linux. The vDSO page is tracked as [vdso], r-x.

Depends on: none. The RLIMIT_AS and RLIMIT_DATA follow-up to #445 sums the same region totals, so it builds on this.

Review focus:

  • guest_region_add_elf_segment (src/core/guest.c): the lead-page arithmetic on start, gpa_base and offset.
  • guest_region_in_process_vm (src/core/guest.h): which regions count toward VmSize.

Verified on b1fbd5c, rebased onto b5e3fe8: make check-format and make check pass; make test-matrix-elfuse-aarch64 gives 300 passed, 0 failed, 10 skipped; make test-matrix-qemu-aarch64 gives 278 passed, 0 failed, 32 skipped; test-procfs checks the aligned offsets, the [vdso] line and VmSize against the listed mappings.


Summary by cubic

Tracks ELF segments and the vDSO page the way Linux does, so /proc/self/maps shows page-aligned offsets, lists [vdso], and VmSize matches the guest mappings.

  • PT_LOAD segments are now tracked from the page holding p_vaddr to the page past its end, with the file offset moved back by the same amount, on both the bootstrap and execve paths. A page two segments share goes to the later one.
  • VmSize sums only regions a Linux process would have, leaving out [shim] and [shim-data], which previously inflated it from 828 kB to 2879 kB for a static binary.
  • The vDSO page is tracked as [vdso], r-x, on both paths, so the mmap allocator sees it as taken.