Skip to content

Commit 289b0f8

Browse files
committed
fixup! Add scratch region
Pass the scratch region to HyperlightVm::new, allowing it to set up the scratch region when the sandbox is created for the first time, before a snapshot restore method is called. This turns out to be slightly more convenient. Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
1 parent 428b94c commit 289b0f8

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/hyperlight_host/src/hypervisor/hyperlight_vm.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ pub enum CreateHyperlightVmError {
275275
SendDbgMsg(#[from] SendDbgMsgError),
276276
#[error("VM operation error: {0}")]
277277
Vm(#[from] VmError),
278+
#[error("Set scratch error: {0}")]
279+
UpdateScratch(#[from] UpdateScratchError),
278280
}
279281

280282
/// Errors that can occur during debug exit handling
@@ -334,6 +336,7 @@ impl HyperlightVm {
334336
#[allow(clippy::too_many_arguments)]
335337
pub(crate) fn new(
336338
mem_regions: Vec<MemoryRegion>,
339+
scratch_mem: GuestSharedMemory,
337340
_pml4_addr: u64,
338341
entrypoint: u64,
339342
rsp: u64,
@@ -436,6 +439,8 @@ impl HyperlightVm {
436439
rt_cfg,
437440
};
438441

442+
ret.update_scratch_mapping(scratch_mem)?;
443+
439444
// Send the interrupt handle to the GDB thread if debugging is enabled
440445
// This is used to allow the GDB thread to stop the vCPU
441446
#[cfg(gdb)]

src/hyperlight_host/src/hypervisor/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ pub(crate) mod tests {
525525
let rt_cfg: SandboxRuntimeConfig = Default::default();
526526
let sandbox =
527527
UninitializedSandbox::new(GuestBinary::FilePath(filename.clone()), Some(config))?;
528-
let (mut mem_mgr, mut gshm) = sandbox.mgr.build();
528+
let (mut mem_mgr, gshm) = sandbox.mgr.build();
529529
let mut vm = set_up_hypervisor_partition(
530-
&mut gshm,
530+
gshm,
531531
&config,
532532
#[cfg(any(crashdump, gdb))]
533533
&rt_cfg,

src/hyperlight_host/src/sandbox/uninitialized_evolve.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ use crate::{MultiUseSandbox, Result, UninitializedSandbox, new_error};
3939

4040
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
4141
pub(super) fn evolve_impl_multi_use(u_sbox: UninitializedSandbox) -> Result<MultiUseSandbox> {
42-
let (mut hshm, mut gshm) = u_sbox.mgr.build();
42+
let (mut hshm, gshm) = u_sbox.mgr.build();
4343
let mut vm = set_up_hypervisor_partition(
44-
&mut gshm,
44+
gshm,
4545
&u_sbox.config,
4646
#[cfg(any(crashdump, gdb))]
4747
&u_sbox.rt_cfg,
@@ -53,7 +53,7 @@ pub(super) fn evolve_impl_multi_use(u_sbox: UninitializedSandbox) -> Result<Mult
5353
rng.random::<u64>()
5454
};
5555
let peb_addr = {
56-
let peb_u64 = u64::try_from(gshm.layout.peb_address)?;
56+
let peb_u64 = u64::try_from(hshm.layout.peb_address)?;
5757
RawPtr::from(peb_u64)
5858
};
5959

@@ -98,7 +98,7 @@ pub(super) fn evolve_impl_multi_use(u_sbox: UninitializedSandbox) -> Result<Mult
9898
}
9999

100100
pub(crate) fn set_up_hypervisor_partition(
101-
mgr: &mut SandboxMemoryManager<GuestSharedMemory>,
101+
mgr: SandboxMemoryManager<GuestSharedMemory>,
102102
#[cfg_attr(target_os = "windows", allow(unused_variables))] config: &SandboxConfiguration,
103103
#[cfg(any(crashdump, gdb))] rt_cfg: &SandboxRuntimeConfig,
104104
_load_info: LoadInfo,
@@ -153,6 +153,7 @@ pub(crate) fn set_up_hypervisor_partition(
153153

154154
Ok(HyperlightVm::new(
155155
regions,
156+
mgr.scratch_mem,
156157
pml4_ptr.absolute()?,
157158
entrypoint_ptr.absolute()?,
158159
rsp_ptr.absolute()?,

0 commit comments

Comments
 (0)