infra icon indicating copy to clipboard operation
infra copied to clipboard

Use `/proc/PID/mem` to access sandbox memory

Open ValentaTomas opened this issue 2 months ago • 4 comments

  • [ ] Test with both versions of used FC
  • [ ] Add explicit handling for NoopMemory or implement more general memory mapping lookup

[!NOTE] Create memfile diffs by reading sandbox memory directly from /proc/PID/mem via a new mapped memory view, with UFFD providing the mapping.

  • Memory diffing:
    • Switch MemoryDiffCreator to read from a generic io.ReaderAt and use a new process memory view instead of a tmp memfile.
    • In Sandbox.Pause, attempt snapshot with /dev/null (fallback to memfile if unsupported), obtain FC PID and UFFD mapping, build memory.View, and pass it to diff writer.
  • UFFD integration:
    • Extend MemoryBackend with Mapping(ctx) and implement in Uffd (exposes mapping) and NoopMemory (returns nil).
    • Refactor userfaultfd.Userfaultfd to use m *memory.Mapping (rename ma), add Mapping() accessor, and update offset lookups.
  • Memory mapping/view module (internal/sandbox/uffd/memory):
    • Add Mapping with GetOffset and GetHostVirtAddr, Region helpers, and View (implements io.ReaderAt over /proc/PID/mem), including specific errors.
    • Add comprehensive tests for mapping (offset/host-virt), view reading across regions/gaps, and UFFD-driven reads/writes/fault behavior.
  • Misc:
    • Make block.Tracker.Has unexported (has) and update tests.
    • Update test utils to return detailed diff errors for byte slices.

Written by Cursor Bugbot for commit 7d148a050ea0c618166fb70b86448f9f1a93ab48. This will update automatically on new commits. Configure here.

ValentaTomas avatar Oct 21 '25 01:10 ValentaTomas

Waiting for https://github.com/e2b-dev/infra/pull/1385 merge.

ValentaTomas avatar Oct 21 '25 01:10 ValentaTomas

@codex review

ValentaTomas avatar Nov 14 '25 03:11 ValentaTomas

cursor review

ValentaTomas avatar Nov 14 '25 03:11 ValentaTomas

Current blocker is the NoopMemory mapping—the actual maps we should be able to get from /proc/PID/maps, but if we want to improve just the non-build pause we can let that one be handled normally.

ValentaTomas avatar Nov 14 '25 03:11 ValentaTomas

It is failing on integration test, because they are not using the custom FC.

ValentaTomas avatar Dec 06 '25 00:12 ValentaTomas