Skip to content

Commit 79a8cdc

Browse files
committed
refactor: move get_memory_access_violation out from trait
- Accept iterator instead of slice - Move function from trait to module level. Necessary to maintain object safety of Hypervisor trait Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 6264bb0 commit 79a8cdc

File tree

1 file changed

+24
-27
lines changed
  • src/hyperlight_host/src/hypervisor

1 file changed

+24
-27
lines changed

src/hyperlight_host/src/hypervisor/mod.rs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -186,33 +186,6 @@ pub(crate) trait Hypervisor: Debug + Sync + Send {
186186
/// Run the vCPU
187187
fn run(&mut self) -> Result<HyperlightExit>;
188188

189-
/// Returns a Some(HyperlightExit::AccessViolation(..)) if the given gpa doesn't have
190-
/// access its corresponding region. Returns None otherwise, or if the region is not found.
191-
fn get_memory_access_violation(
192-
&self,
193-
gpa: usize,
194-
mem_regions: &[MemoryRegion],
195-
access_info: MemoryRegionFlags,
196-
) -> Option<HyperlightExit> {
197-
// find the region containing the given gpa
198-
let region = mem_regions
199-
.iter()
200-
.find(|region| region.guest_region.contains(&gpa));
201-
202-
if let Some(region) = region {
203-
if !region.flags.contains(access_info)
204-
|| region.flags.contains(MemoryRegionFlags::STACK_GUARD)
205-
{
206-
return Some(HyperlightExit::AccessViolation(
207-
gpa as u64,
208-
access_info,
209-
region.flags,
210-
));
211-
}
212-
}
213-
None
214-
}
215-
216189
/// Get InterruptHandle to underlying VM
217190
fn interrupt_handle(&self) -> Arc<dyn InterruptHandle>;
218191

@@ -281,6 +254,30 @@ pub(crate) trait Hypervisor: Debug + Sync + Send {
281254
fn trace_info_as_mut(&mut self) -> &mut TraceInfo;
282255
}
283256

257+
/// Returns a Some(HyperlightExit::AccessViolation(..)) if the given gpa doesn't have
258+
/// access its corresponding region. Returns None otherwise, or if the region is not found.
259+
pub(crate) fn get_memory_access_violation<'a>(
260+
gpa: usize,
261+
mut mem_regions: impl Iterator<Item = &'a MemoryRegion>,
262+
access_info: MemoryRegionFlags,
263+
) -> Option<HyperlightExit> {
264+
// find the region containing the given gpa
265+
let region = mem_regions.find(|region| region.guest_region.contains(&gpa));
266+
267+
if let Some(region) = region {
268+
if !region.flags.contains(access_info)
269+
|| region.flags.contains(MemoryRegionFlags::STACK_GUARD)
270+
{
271+
return Some(HyperlightExit::AccessViolation(
272+
gpa as u64,
273+
access_info,
274+
region.flags,
275+
));
276+
}
277+
}
278+
None
279+
}
280+
284281
/// A virtual CPU that can be run until an exit occurs
285282
pub struct VirtualCPU {}
286283

0 commit comments

Comments
 (0)