Skip to content

feat: pass file mapping info via PEB with label support#1322

Open
simongdavies wants to merge 1 commit intohyperlight-dev:mainfrom
simongdavies:add-file-mapping-ga
Open

feat: pass file mapping info via PEB with label support#1322
simongdavies wants to merge 1 commit intohyperlight-dev:mainfrom
simongdavies:add-file-mapping-ga

Conversation

@simongdavies
Copy link
Contributor

Add FileMappingInfo struct (guest_addr, size, label) and file_mappings field to HyperlightPEB so file mapping metadata is communicated to the guest through the PEB. Space for MAX_FILE_MAPPINGS (32) entries is statically reserved after the PEB struct to avoid dynamic layout changes.

  • Add label parameter to map_file_cow (optional, defaults to filename)
  • Add shared memory overlap validation (full mapped range)
  • Add inter-mapping overlap detection
  • Add write_file_mapping_entry on SandboxMemoryManager
  • Add MAX_FILE_MAPPINGS limit enforcement at registration time
  • Update PEB region sizing in get_memory_regions and layout tests

Add FileMappingInfo struct (guest_addr, size, label) and file_mappings
field to HyperlightPEB so file mapping metadata is communicated to the
guest through the PEB. Space for MAX_FILE_MAPPINGS (32) entries is
statically reserved after the PEB struct to avoid dynamic layout changes.

- Add label parameter to map_file_cow (optional, defaults to filename)
- Add shared memory overlap validation (full mapped range)
- Add inter-mapping overlap detection
- Add write_file_mapping_entry on SandboxMemoryManager
- Add MAX_FILE_MAPPINGS limit enforcement at registration time
- Update PEB region sizing in get_memory_regions and layout tests

Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
@simongdavies simongdavies added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Mar 18, 2026
@ppenna ppenna added this to HL-NVX Mar 18, 2026
@ppenna ppenna moved this to In Progress in HL-NVX Mar 18, 2026
@danbugs danbugs requested a review from Copilot March 19, 2026 00:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the Hyperlight host↔guest ABI by adding file-mapping metadata (guest address, size, label) to the PEB, enabling guests to discover host-mapped files and their identities. It reserves space for a fixed-size FileMappingInfo array immediately after the PEB to keep the layout stable.

Changes:

  • Add FileMappingInfo + MAX_FILE_MAPPINGS and extend HyperlightPEB with a file_mappings descriptor.
  • Add optional label support to map_file_cow, validate mapping overlaps, and enforce the max mapping count.
  • Update memory layout sizing to reserve space for the PEB + mappings array, and write mapping entries into the PEB at map time / evolve time.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/hyperlight_host/src/sandbox/uninitialized_evolve.rs Writes file mapping metadata into the PEB during evolve for deferred mappings.
src/hyperlight_host/src/sandbox/uninitialized.rs Adds label parameter + limit/overlap validation for deferred file mappings.
src/hyperlight_host/src/sandbox/initialized_multi_use.rs Adds label parameter, validates overlaps, writes mapping metadata into the PEB, updates tests for new signature.
src/hyperlight_host/src/sandbox/file_mapping.rs Stores a fixed-size C-string label in prepared mappings and validates/truncates labels.
src/hyperlight_host/src/mem/mgr.rs Adds write_file_mapping_entry to write FileMappingInfo entries into the PEB’s reserved array.
src/hyperlight_host/src/mem/layout.rs Reserves space after the PEB for MAX_FILE_MAPPINGS entries and wires up PEB offsets/pointers.
src/hyperlight_host/examples/crashdump/main.rs Updates map_file_cow calls for the new label parameter.
src/hyperlight_common/src/mem.rs Adds shared ABI types/constants and extends HyperlightPEB with file_mappings.

You can also share your feedback on Copilot code review. Take the survey.

let new_end = mapping_end;
for existing in &self.pending_file_mappings {
let ex_start = existing.guest_base;
let ex_end = ex_start + existing.size as u64;
Comment on lines +393 to +398
// Write the entry into the next available slot.
let entry_offset = self.layout.get_file_mappings_array_offset()
+ current_count * std::mem::size_of::<FileMappingInfo>();
self.shared_mem.write::<u64>(entry_offset, guest_addr)?;
self.shared_mem.write::<u64>(entry_offset + 8, size)?;
self.shared_mem.copy_from_slice(label, entry_offset + 16)?;
Comment on lines +632 to +637
// Record the mapping metadata in the PEB so the guest can
// discover it. Must happen before mark_consumed() so that if
// this fails, Drop still cleans up the host resources.
self.mem_mgr
.write_file_mapping_entry(prepared.guest_base, size, &prepared.label)?;

// this fails, Drop still cleans up the host resources.
self.mem_mgr
.write_file_mapping_entry(prepared.guest_base, size, &prepared.label)?;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If write_file_mapping_entry fails here, prepared hasn't been consumed yet so its Drop frees the host-side file resources — but the VM already holds a mapping from map_region above, leaving it with a dangling backing. The evolve path in uninitialized_evolve.rs avoids this by calling mark_consumed() immediately after map_region, then write_file_mapping_entry. Consider matching that order here.

danbugs added a commit to nanvix/hyperlight that referenced this pull request Mar 19, 2026
Cherry-pick of hyperlight-dev#1322.

Add FileMappingInfo struct (guest_addr, size, label) and file_mappings
field to HyperlightPEB so file mapping metadata is communicated to the
guest through the PEB. Space for MAX_FILE_MAPPINGS (32) entries is
statically reserved after the PEB struct to avoid dynamic layout changes.

- Add label parameter to map_file_cow (optional, defaults to filename)
- Add shared memory overlap validation (full mapped range)
- Add inter-mapping overlap detection
- Add write_file_mapping_entry on SandboxMemoryManager
- Add MAX_FILE_MAPPINGS limit enforcement at registration time
- Update PEB region sizing in get_memory_regions and layout tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

4 participants