Skip to content

Refactor SandboxMemoryLayout#1455

Merged
ludfjig merged 1 commit into
hyperlight-dev:mainfrom
ludfjig:layout_refactor
May 14, 2026
Merged

Refactor SandboxMemoryLayout#1455
ludfjig merged 1 commit into
hyperlight-dev:mainfrom
ludfjig:layout_refactor

Conversation

@ludfjig
Copy link
Copy Markdown
Contributor

@ludfjig ludfjig commented May 14, 2026

This PR removes derived fields from SandboxMemoryLayout, with the primary goal to help simplify future snapshot serialization and prevent a whole category of bugs. Note that the added bytemuck crate dep is already a transitive dep of hyperlight-common, so I'm not adding anything new. I filed #1454 to fix this, but not in scope for this PR

@ludfjig ludfjig added the kind/refactor For PRs that restructure or remove code without adding new functionality. label May 14, 2026
@ludfjig ludfjig requested a review from Copilot May 14, 2026 19:35
Copy link
Copy Markdown
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 refactors SandboxMemoryLayout to remove derived/stored offset fields and instead compute layout addresses/offsets on demand, with the goal of simplifying snapshot serialization and reducing layout-related bugs.

Changes:

  • Replace stored layout-derived fields (PEB offsets, heap/init offsets, etc.) with accessor methods and store only configuration-derived sizes.
  • Switch PEB initialization to build a HyperlightPEB struct and serialize it via bytemuck rather than manually writing individual u64 fields.
  • Add bytemuck::Pod/Zeroable derives for GuestMemoryRegion/HyperlightPEB and add a unit test validating round-trip byte serialization.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/hyperlight_host/src/sandbox/uninitialized_evolve.rs Update PEB address access to the new peb_address() accessor.
src/hyperlight_host/src/mem/mgr.rs Use new SandboxMemoryLayout size fields (input_data_size/output_data_size) instead of pulling from config.
src/hyperlight_host/src/mem/layout.rs Remove derived fields and compute offsets via methods; refactor PEB writing to struct + bytemuck serialization.
src/hyperlight_host/src/hypervisor/hyperlight_vm/x86_64.rs Update test to use peb_address() accessor.
src/hyperlight_host/Cargo.toml Add bytemuck dependency for host-side PEB serialization.
src/hyperlight_common/src/mem.rs Mark PEB-related structs as Pod/Zeroable and add serialization round-trip unit test.
Cargo.lock Lockfile update to include bytemuck in the dependency graph.

Comment thread src/hyperlight_host/src/mem/layout.rs Outdated
Signed-off-by: Ludvig Liljenberg <[email protected]>
@ludfjig ludfjig force-pushed the layout_refactor branch from da862bc to acc92f2 Compare May 14, 2026 19:55
@ludfjig ludfjig marked this pull request as ready for review May 14, 2026 19:59
Copy link
Copy Markdown
Contributor

@jprendes jprendes left a comment

Choose a reason for hiding this comment

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

LGTM
Very clean refactor, thanks!

@ludfjig ludfjig merged commit 7b16d5b into hyperlight-dev:main May 14, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor For PRs that restructure or remove code without adding new functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants