Skip to content

Commit bf07797

Browse files
committed
Rename entrypoint field to next_action
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent a214b54 commit bf07797

8 files changed

Lines changed: 48 additions & 47 deletions

File tree

src/hyperlight_host/src/hypervisor/hyperlight_vm/aarch64.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl HyperlightVm {
5151
snapshot_mem: SnapshotSharedMemory<GuestSharedMemory>,
5252
scratch_mem: GuestSharedMemory,
5353
root_pt_addr: u64,
54-
entrypoint: NextAction,
54+
next_action: NextAction,
5555
rsp_gva: u64,
5656
page_size: usize,
5757
config: &SandboxConfiguration,
@@ -84,7 +84,7 @@ impl HyperlightVm {
8484
let vm_can_reset_vcpu = vm.can_reset_vcpu();
8585
let mut ret = Self {
8686
vm,
87-
entrypoint,
87+
next_action,
8888
rsp_gva,
8989
interrupt_handle,
9090
page_size,
@@ -119,7 +119,7 @@ impl HyperlightVm {
119119
std::sync::Mutex<SandboxMemoryManager<HostSharedMemory>>,
120120
>,
121121
) -> Result<(), InitializeError> {
122-
let NextAction::Initialise(initialise) = self.entrypoint else {
122+
let NextAction::Initialise(initialise) = self.next_action else {
123123
return Ok(());
124124
};
125125
let mut x: [u64; 31] = [0; 31];
@@ -149,7 +149,7 @@ impl HyperlightVm {
149149
return Err(InitializeError::InvalidStackPointer(regs.sp));
150150
}
151151
self.rsp_gva = regs.sp;
152-
self.entrypoint = NextAction::Call(regs.x[0]);
152+
self.next_action = NextAction::Call(regs.x[0]);
153153

154154
Ok(())
155155
}
@@ -162,7 +162,7 @@ impl HyperlightVm {
162162
std::sync::Mutex<SandboxMemoryManager<HostSharedMemory>>,
163163
>,
164164
) -> Result<(), DispatchGuestCallError> {
165-
let NextAction::Call(dispatch_func_addr) = self.entrypoint else {
165+
let NextAction::Call(dispatch_func_addr) = self.next_action else {
166166
return Err(DispatchGuestCallError::Uninitialized);
167167
};
168168
let mut regs = CommonRegisters {

src/hyperlight_host/src/hypervisor/hyperlight_vm/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ pub(crate) struct HyperlightVm {
372372
#[cfg(not(gdb))]
373373
pub(super) vm: Box<dyn VirtualMachine>,
374374
pub(super) page_size: usize,
375-
pub(super) entrypoint: NextAction, // only present if this vm has not yet been initialised
375+
pub(super) next_action: NextAction, // `Initialise` before the guest has run, `Call` afterwards
376376
pub(super) rsp_gva: u64,
377377
pub(super) interrupt_handle: Arc<dyn InterruptHandleImpl>,
378378

@@ -565,14 +565,14 @@ impl HyperlightVm {
565565
self.rsp_gva = gva;
566566
}
567567

568-
/// Get the current entrypoint action
569-
pub(crate) fn get_entrypoint(&self) -> NextAction {
570-
self.entrypoint
568+
/// Get the next action to perform when the sandbox resumes
569+
pub(crate) fn get_next_action(&self) -> NextAction {
570+
self.next_action
571571
}
572572

573-
/// Set the current entrypoint action
574-
pub(crate) fn set_entrypoint(&mut self, entrypoint: NextAction) {
575-
self.entrypoint = entrypoint
573+
/// Set the next action to perform when the sandbox resumes
574+
pub(crate) fn set_next_action(&mut self, next_action: NextAction) {
575+
self.next_action = next_action
576576
}
577577

578578
pub(crate) fn interrupt_handle(&self) -> Arc<dyn InterruptHandle> {

src/hyperlight_host/src/hypervisor/hyperlight_vm/x86_64.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl HyperlightVm {
7777
snapshot_mem: SnapshotSharedMemory<GuestSharedMemory>,
7878
scratch_mem: GuestSharedMemory,
7979
_root_pt_addr: u64,
80-
entrypoint: NextAction,
80+
next_action: NextAction,
8181
rsp_gva: u64,
8282
page_size: usize,
8383
#[cfg_attr(target_os = "windows", allow(unused_variables))] config: &SandboxConfiguration,
@@ -141,7 +141,7 @@ impl HyperlightVm {
141141
#[cfg_attr(not(gdb), allow(unused_mut))]
142142
let mut ret = Self {
143143
vm,
144-
entrypoint,
144+
next_action,
145145
rsp_gva,
146146
interrupt_handle,
147147
page_size,
@@ -183,7 +183,7 @@ impl HyperlightVm {
183183
// `one_shot_entry_bp` so it does not interfere with later
184184
// user-installed breakpoints at the same address.
185185
ret.vm.set_debug(true).map_err(VmError::Debug)?;
186-
let entry_addr = match entrypoint {
186+
let entry_addr = match next_action {
187187
NextAction::Initialise(addr) | NextAction::Call(addr) => Some(addr),
188188
#[cfg(test)]
189189
NextAction::None => None,
@@ -212,7 +212,7 @@ impl HyperlightVm {
212212
guest_max_log_level: Option<LevelFilter>,
213213
#[cfg(gdb)] dbg_mem_access_fn: Arc<Mutex<SandboxMemoryManager<HostSharedMemory>>>,
214214
) -> std::result::Result<(), InitializeError> {
215-
let NextAction::Initialise(initialise) = self.entrypoint else {
215+
let NextAction::Initialise(initialise) = self.next_action else {
216216
return Ok(());
217217
};
218218

@@ -251,7 +251,7 @@ impl HyperlightVm {
251251
return Err(InitializeError::InvalidStackPointer(regs.rsp));
252252
}
253253
self.rsp_gva = regs.rsp;
254-
self.entrypoint = NextAction::Call(regs.rax);
254+
self.next_action = NextAction::Call(regs.rax);
255255

256256
Ok(())
257257
}
@@ -284,7 +284,7 @@ impl HyperlightVm {
284284
host_funcs: &Arc<Mutex<FunctionRegistry>>,
285285
#[cfg(gdb)] dbg_mem_access_fn: Arc<Mutex<SandboxMemoryManager<HostSharedMemory>>>,
286286
) -> std::result::Result<(), DispatchGuestCallError> {
287-
let NextAction::Call(dispatch_func_addr) = self.entrypoint else {
287+
let NextAction::Call(dispatch_func_addr) = self.next_action else {
288288
return Err(DispatchGuestCallError::Uninitialized);
289289
};
290290
let mut rflags = 1 << 1; // RFLAGS.1 is RES1
@@ -567,7 +567,7 @@ impl HyperlightVm {
567567
// Use the stored entry point address from the runtime config.
568568
// This is the original entry point (load_addr + ELF entry offset)
569569
// which GDB needs for AT_ENTRY to compute the PIE load offset.
570-
// We cannot use self.entrypoint here because it transitions from
570+
// We cannot use self.next_action here because it transitions from
571571
// Initialise(addr) to Call(dispatch_addr) after guest init.
572572
let initialise = self.rt_cfg.entry_point.unwrap_or_else(|| {
573573
tracing::warn!(
@@ -2060,7 +2060,7 @@ mod tests {
20602060

20612061
// Re-run from entrypoint (flag=1 means guest skips dirty phase, just does FXSAVE)
20622062
// Use stack_top - 8 to match initialise()'s behavior (simulates call pushing return addr)
2063-
let NextAction::Call(rip) = ctx.ctx.vm.entrypoint else {
2063+
let NextAction::Call(rip) = ctx.ctx.vm.next_action else {
20642064
panic!("entrypoint should be call");
20652065
};
20662066
let regs = CommonRegisters {

src/hyperlight_host/src/mem/mgr.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ pub(crate) struct SandboxMemoryManager<S: SharedMemory> {
140140
pub(crate) scratch_mem: S,
141141
/// The memory layout of the underlying shared memory
142142
pub(crate) layout: SandboxMemoryLayout,
143-
/// Offset for the execution entrypoint from `load_addr`
144-
pub(crate) entrypoint: NextAction,
143+
/// The next action to perform when this sandbox resumes:
144+
/// `Initialise` before the guest has run, `Call` afterwards.
145+
pub(crate) next_action: NextAction,
145146
/// Buffer for accumulating guest abort messages
146147
pub(crate) abort_buffer: Vec<u8>,
147148
/// Generation counter: how many snapshots have been taken from
@@ -275,13 +276,13 @@ where
275276
layout: SandboxMemoryLayout,
276277
shared_mem: SnapshotSharedMemory<S>,
277278
scratch_mem: S,
278-
entrypoint: NextAction,
279+
next_action: NextAction,
279280
) -> Self {
280281
Self {
281282
layout,
282283
shared_mem,
283284
scratch_mem,
284-
entrypoint,
285+
next_action,
285286
abort_buffer: Vec::new(),
286287
snapshot_count: 0,
287288
}
@@ -300,7 +301,7 @@ where
300301
root_pt_gpas: &[u64],
301302
rsp_gva: u64,
302303
sregs: CommonSpecialRegisters,
303-
entrypoint: NextAction,
304+
next_action: NextAction,
304305
host_functions: HostFunctionDetails,
305306
) -> Result<Snapshot> {
306307
self.snapshot_count += 1;
@@ -313,7 +314,7 @@ where
313314
root_pt_gpas,
314315
rsp_gva,
315316
sregs,
316-
entrypoint,
317+
next_action,
317318
self.snapshot_count,
318319
host_functions,
319320
)
@@ -325,8 +326,8 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
325326
let layout = *s.layout();
326327
let shared_mem = s.memory().to_mgr_snapshot_mem()?;
327328
let scratch_mem = ExclusiveSharedMemory::new(s.layout().get_scratch_size())?;
328-
let entrypoint = s.entrypoint();
329-
let mut mgr = Self::new(layout, shared_mem, scratch_mem, entrypoint);
329+
let next_action = s.next_action();
330+
let mut mgr = Self::new(layout, shared_mem, scratch_mem, next_action);
330331
// Inherit the snapshot's generation number for the same
331332
// reason `restore_snapshot` does: the guest-visible counter
332333
// reflects "which snapshot is the sandbox currently a clone
@@ -357,15 +358,15 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
357358
shared_mem: hshm,
358359
scratch_mem: hscratch,
359360
layout: self.layout,
360-
entrypoint: self.entrypoint,
361+
next_action: self.next_action,
361362
abort_buffer: self.abort_buffer,
362363
snapshot_count: self.snapshot_count,
363364
};
364365
let guest_mgr = SandboxMemoryManager {
365366
shared_mem: gshm,
366367
scratch_mem: gscratch,
367368
layout: self.layout,
368-
entrypoint: self.entrypoint,
369+
next_action: self.next_action,
369370
abort_buffer: Vec::new(), // Guest doesn't need abort buffer
370371
snapshot_count: self.snapshot_count,
371372
};

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl MultiUseSandbox {
294294
// If the snapshot was taken from an already-initialized guest
295295
// (NextAction::Call), apply the captured special registers so
296296
// the guest resumes in the correct CPU state.
297-
if matches!(snapshot.entrypoint(), super::snapshot::NextAction::Call(_)) {
297+
if matches!(snapshot.next_action(), super::snapshot::NextAction::Call(_)) {
298298
let sregs = snapshot.sregs().ok_or_else(|| {
299299
crate::new_error!("snapshot with NextAction::Call must have captured sregs")
300300
})?;
@@ -385,7 +385,7 @@ impl MultiUseSandbox {
385385
.vm
386386
.get_snapshot_sregs()
387387
.map_err(|e| HyperlightError::HyperlightVmError(e.into()))?;
388-
let entrypoint = self.vm.get_entrypoint();
388+
let next_action = self.vm.get_next_action();
389389
let host_functions = (&*self.host_funcs.try_lock().map_err(|e| {
390390
crate::new_error!("Error locking host_funcs at {}:{}: {}", file!(), line!(), e)
391391
})?)
@@ -396,7 +396,7 @@ impl MultiUseSandbox {
396396
&root_pt_gpas,
397397
stack_top_gpa,
398398
sregs,
399-
entrypoint,
399+
next_action,
400400
host_functions,
401401
)?;
402402
let snapshot = Arc::new(memory_snapshot);
@@ -544,7 +544,7 @@ impl MultiUseSandbox {
544544
})?;
545545

546546
self.vm.set_stack_top(snapshot.stack_top_gva());
547-
self.vm.set_entrypoint(snapshot.entrypoint());
547+
self.vm.set_next_action(snapshot.next_action());
548548

549549
let current_regions: Vec<MemoryRegion> = self.vm.get_mapped_regions().cloned().collect();
550550
for region in &current_regions {

src/hyperlight_host/src/sandbox/snapshot/file/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ impl Snapshot {
549549
}
550550

551551
fn build_config(&self) -> crate::Result<OciSnapshotConfig> {
552-
let (entrypoint_addr, sregs) = match (self.entrypoint, self.sregs.as_ref()) {
552+
let (entrypoint_addr, sregs) = match (self.next_action, self.sregs.as_ref()) {
553553
(NextAction::Call(addr), Some(sregs)) => (addr, sregs),
554554
(NextAction::Call(_), None) => {
555555
return Err(crate::new_error!(
@@ -847,8 +847,8 @@ impl Snapshot {
847847
));
848848
}
849849

850-
// 8. Build entrypoint + sregs back from the config.
851-
let entrypoint = NextAction::Call(cfg.entrypoint_addr);
850+
// 8. Build the next action + sregs back from the config.
851+
let next_action = NextAction::Call(cfg.entrypoint_addr);
852852

853853
// 9. Reconstitute host_functions metadata.
854854
let snapshot_generation = cfg.snapshot_generation;
@@ -871,7 +871,7 @@ impl Snapshot {
871871
load_info: crate::mem::exe::LoadInfo::dummy(),
872872
stack_top_gva: cfg.stack_top_gva,
873873
sregs: Some(cfg.sregs),
874-
entrypoint,
874+
next_action,
875875
snapshot_generation,
876876
host_functions,
877877
})

src/hyperlight_host/src/sandbox/snapshot/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub struct Snapshot {
9393
sregs: Option<CommonSpecialRegisters>,
9494

9595
/// The next action that should be performed on this snapshot
96-
entrypoint: NextAction,
96+
next_action: NextAction,
9797

9898
/// The generation number assigned to this snapshot when it was
9999
/// taken — i.e. "this is the Nth snapshot taken from the sandbox's
@@ -381,7 +381,7 @@ impl Snapshot {
381381
load_info,
382382
stack_top_gva: exn_stack_top_gva,
383383
sregs: None,
384-
entrypoint: NextAction::Initialise(load_addr + entrypoint_va - base_va),
384+
next_action: NextAction::Initialise(load_addr + entrypoint_va - base_va),
385385
snapshot_generation: 0,
386386
host_functions: HostFunctionDetails {
387387
host_functions: None,
@@ -407,7 +407,7 @@ impl Snapshot {
407407
root_pt_gpas: &[u64],
408408
stack_top_gva: u64,
409409
sregs: CommonSpecialRegisters,
410-
entrypoint: NextAction,
410+
next_action: NextAction,
411411
snapshot_generation: u64,
412412
host_functions: HostFunctionDetails,
413413
) -> Result<Self> {
@@ -560,7 +560,7 @@ impl Snapshot {
560560
load_info,
561561
stack_top_gva,
562562
sregs: Some(sregs),
563-
entrypoint,
563+
next_action,
564564
snapshot_generation,
565565
host_functions,
566566
})
@@ -603,8 +603,8 @@ impl Snapshot {
603603
self.sregs.as_ref()
604604
}
605605

606-
pub(crate) fn entrypoint(&self) -> NextAction {
607-
self.entrypoint
606+
pub(crate) fn next_action(&self) -> NextAction {
607+
self.next_action
608608
}
609609

610610
/// Validate that `provided` is a superset of the host functions

src/hyperlight_host/src/sandbox/uninitialized_evolve.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ pub(crate) fn set_up_hypervisor_partition(
151151
let trace_info = MemTraceInfo::new(_load_info.info)?;
152152

153153
// Store the original entry point address in the runtime config for core dumps.
154-
// This is needed because `entrypoint` transitions from `Initialise(addr)` to
154+
// This is needed because `next_action` transitions from `Initialise(addr)` to
155155
// `Call(dispatch_addr)` after guest initialisation, losing the original value
156156
// that GDB needs to compute the PIE binary's load offset.
157157
#[cfg(crashdump)]
158158
let rt_cfg = {
159159
let mut rt_cfg = rt_cfg;
160-
if let crate::sandbox::snapshot::NextAction::Initialise(addr) = mgr.entrypoint {
160+
if let crate::sandbox::snapshot::NextAction::Initialise(addr) = mgr.next_action {
161161
rt_cfg.entry_point = Some(addr);
162162
}
163163
rt_cfg
@@ -167,7 +167,7 @@ pub(crate) fn set_up_hypervisor_partition(
167167
mgr.shared_mem,
168168
mgr.scratch_mem,
169169
mgr.layout.get_pt_base_gpa(),
170-
mgr.entrypoint,
170+
mgr.next_action,
171171
stack_top_gva,
172172
page_size,
173173
config,

0 commit comments

Comments
 (0)