Skip to content

Commit ded7245

Browse files
committed
Remove Ptr, RawPtr, GuestPtr, Offset, AddressSpace, GuestAddressSpace
Certain drivers used RawPtr and others used u64. To unify these in preperation for a refactor, they are replaced them with u64 instead. The removed types were mostly unused and provided minimal benefit over a simple u64. In the future we should think about introducing some type to abstract over phys/virtual addresses etc instead. Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 70a856f commit ded7245

File tree

13 files changed

+72
-754
lines changed

13 files changed

+72
-754
lines changed

src/hyperlight_host/src/error.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use thiserror::Error;
3939
#[cfg(target_os = "windows")]
4040
use crate::hypervisor::wrappers::HandleWrapper;
4141
use crate::mem::memory_region::MemoryRegionFlags;
42-
use crate::mem::ptr::RawPtr;
4342

4443
/// The error type for Hyperlight operations
4544
#[derive(Error, Debug)]
@@ -191,10 +190,6 @@ pub enum HyperlightError {
191190
#[error("Failure processing PE File {0:?}")]
192191
PEFileProcessingFailure(#[from] goblin::error::Error),
193192

194-
/// Raw pointer is less than base address
195-
#[error("Raw pointer ({0:?}) was less than the base address ({1})")]
196-
RawPointerLessThanBaseAddress(RawPtr, u64),
197-
198193
/// RefCell borrow failed
199194
#[error("RefCell borrow failed")]
200195
RefCellBorrowFailed(#[from] BorrowError),

src/hyperlight_host/src/hypervisor/hyperv_linux.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ use super::{HyperlightExit, Hypervisor, InterruptHandle, LinuxInterruptHandle, V
7777
use crate::HyperlightError;
7878
use crate::hypervisor::get_memory_access_violation;
7979
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
80-
use crate::mem::ptr::{GuestPtr, RawPtr};
8180
use crate::mem::shared_mem::HostSharedMemory;
8281
use crate::sandbox::SandboxConfiguration;
8382
#[cfg(feature = "trace_guest")]
@@ -313,7 +312,7 @@ pub(crate) struct HypervLinuxDriver {
313312
page_size: usize,
314313
vm_fd: VmFd,
315314
vcpu_fd: VcpuFd,
316-
orig_rsp: GuestPtr,
315+
orig_rsp: u64,
317316
entrypoint: u64,
318317
interrupt_handle: Arc<LinuxInterruptHandle>,
319318
mem_mgr: Option<MemMgrWrapper<HostSharedMemory>>,
@@ -347,9 +346,9 @@ impl HypervLinuxDriver {
347346
#[instrument(skip_all, parent = Span::current(), level = "Trace")]
348347
pub(crate) fn new(
349348
mem_regions: Vec<MemoryRegion>,
350-
entrypoint_ptr: GuestPtr,
351-
rsp_ptr: GuestPtr,
352-
pml4_ptr: GuestPtr,
349+
entrypoint_ptr: u64,
350+
rsp_ptr: u64,
351+
pml4_ptr: u64,
353352
config: &SandboxConfiguration,
354353
#[cfg(gdb)] gdb_conn: Option<DebugCommChannel<DebugResponse, DebugMsg>>,
355354
#[cfg(crashdump)] rt_cfg: SandboxRuntimeConfig,
@@ -380,7 +379,7 @@ impl HypervLinuxDriver {
380379
#[cfg(gdb)]
381380
let (debug, gdb_conn) = if let Some(gdb_conn) = gdb_conn {
382381
let mut debug = MshvDebug::new();
383-
debug.add_hw_breakpoint(&vcpu_fd, entrypoint_ptr.absolute()?)?;
382+
debug.add_hw_breakpoint(&vcpu_fd, entrypoint_ptr)?;
384383

385384
// The bellow intercepts make the vCPU exit with the Exception Intercept exit code
386385
// Check Table 6-1. Exceptions and Interrupts at Page 6-13 Vol. 1
@@ -419,7 +418,7 @@ impl HypervLinuxDriver {
419418
vm_fd.map_user_memory(mshv_region)
420419
})?;
421420

422-
Self::setup_initial_sregs(&mut vcpu_fd, pml4_ptr.absolute()?)?;
421+
Self::setup_initial_sregs(&mut vcpu_fd, pml4_ptr)?;
423422

424423
let interrupt_handle = Arc::new(LinuxInterruptHandle {
425424
running: AtomicU64::new(0),
@@ -453,7 +452,7 @@ impl HypervLinuxDriver {
453452
vcpu_fd,
454453
sandbox_regions: mem_regions,
455454
mmap_regions: Vec::new(),
456-
entrypoint: entrypoint_ptr.absolute()?,
455+
entrypoint: entrypoint_ptr,
457456
orig_rsp: rsp_ptr,
458457
interrupt_handle: interrupt_handle.clone(),
459458
mem_mgr: None,
@@ -585,7 +584,7 @@ impl Hypervisor for HypervLinuxDriver {
585584
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
586585
fn initialise(
587586
&mut self,
588-
peb_addr: RawPtr,
587+
peb_addr: u64,
589588
seed: u64,
590589
page_size: u32,
591590
mem_mgr: MemMgrWrapper<HostSharedMemory>,
@@ -604,11 +603,11 @@ impl Hypervisor for HypervLinuxDriver {
604603

605604
let regs = StandardRegisters {
606605
rip: self.entrypoint,
607-
rsp: self.orig_rsp.absolute()?,
606+
rsp: self.orig_rsp,
608607
rflags: 2, //bit 1 of rlags is required to be set
609608

610609
// function args
611-
rdi: peb_addr.into(),
610+
rdi: peb_addr,
612611
rsi: seed,
613612
rdx: page_size.into(),
614613
rcx: max_guest_log_level,
@@ -662,13 +661,13 @@ impl Hypervisor for HypervLinuxDriver {
662661
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
663662
fn dispatch_call_from_host(
664663
&mut self,
665-
dispatch_func_addr: RawPtr,
664+
dispatch_func_addr: u64,
666665
#[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper,
667666
) -> Result<()> {
668667
// Reset general purpose registers, then set RIP and RSP
669668
let regs = StandardRegisters {
670-
rip: dispatch_func_addr.into(),
671-
rsp: self.orig_rsp.absolute()?,
669+
rip: dispatch_func_addr,
670+
rsp: self.orig_rsp,
672671
rflags: 2, //bit 1 of rlags is required to be set
673672
..Default::default()
674673
};
@@ -1246,9 +1245,9 @@ mod tests {
12461245
}
12471246
const MEM_SIZE: usize = 0x3000;
12481247
let gm = shared_mem_with_code(CODE.as_slice(), MEM_SIZE, 0).unwrap();
1249-
let rsp_ptr = GuestPtr::try_from(0).unwrap();
1250-
let pml4_ptr = GuestPtr::try_from(0).unwrap();
1251-
let entrypoint_ptr = GuestPtr::try_from(0).unwrap();
1248+
let rsp_ptr = 0;
1249+
let pml4_ptr = 0;
1250+
let entrypoint_ptr = 0;
12521251
let mut regions = MemoryRegionVecBuilder::new(0, gm.base_addr());
12531252
regions.push_page_aligned(
12541253
MEM_SIZE,

src/hyperlight_host/src/hypervisor/hyperv_windows.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ use crate::hypervisor::fpu::FP_CONTROL_WORD_DEFAULT;
6060
use crate::hypervisor::get_memory_access_violation;
6161
use crate::hypervisor::wrappers::WHvGeneralRegisters;
6262
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
63-
use crate::mem::ptr::{GuestPtr, RawPtr};
6463
use crate::mem::shared_mem::HostSharedMemory;
6564
#[cfg(feature = "trace_guest")]
6665
use crate::sandbox::TraceInfo;
@@ -281,7 +280,7 @@ pub(crate) struct HypervWindowsDriver {
281280
processor: VMProcessor,
282281
_surrogate_process: SurrogateProcess, // we need to keep a reference to the SurrogateProcess for the duration of the driver since otherwise it will dropped and the memory mapping will be unmapped and the surrogate process will be returned to the pool
283282
entrypoint: u64,
284-
orig_rsp: GuestPtr,
283+
orig_rsp: u64,
285284
interrupt_handle: Arc<WindowsInterruptHandle>,
286285
mem_mgr: Option<MemMgrWrapper<HostSharedMemory>>,
287286
host_funcs: Option<Arc<Mutex<FunctionRegistry>>>,
@@ -361,7 +360,7 @@ impl HypervWindowsDriver {
361360
processor: proc,
362361
_surrogate_process: surrogate_process,
363362
entrypoint,
364-
orig_rsp: GuestPtr::try_from(RawPtr::from(rsp))?,
363+
orig_rsp: rsp,
365364
sandbox_regions: mem_regions,
366365
mmap_regions: Vec::new(),
367366
interrupt_handle: interrupt_handle.clone(),
@@ -600,7 +599,7 @@ impl Hypervisor for HypervWindowsDriver {
600599
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
601600
fn initialise(
602601
&mut self,
603-
peb_address: RawPtr,
602+
peb_address: u64,
604603
seed: u64,
605604
page_size: u32,
606605
mem_mgr: MemMgrWrapper<HostSharedMemory>,
@@ -618,10 +617,10 @@ impl Hypervisor for HypervWindowsDriver {
618617

619618
let regs = WHvGeneralRegisters {
620619
rip: self.entrypoint,
621-
rsp: self.orig_rsp.absolute()?,
620+
rsp: self.orig_rsp,
622621

623622
// function args
624-
rdi: peb_address.into(),
623+
rdi: peb_address,
625624
rsi: seed,
626625
rdx: page_size.into(),
627626
rcx: max_guest_log_level,
@@ -655,13 +654,13 @@ impl Hypervisor for HypervWindowsDriver {
655654
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
656655
fn dispatch_call_from_host(
657656
&mut self,
658-
dispatch_func_addr: RawPtr,
657+
dispatch_func_addr: u64,
659658
#[cfg(gdb)] dbg_mem_access_hdl: DbgMemAccessHandlerWrapper,
660659
) -> Result<()> {
661660
// Reset general purpose registers, then set RIP and RSP
662661
let regs = WHvGeneralRegisters {
663-
rip: dispatch_func_addr.into(),
664-
rsp: self.orig_rsp.absolute()?,
662+
rip: dispatch_func_addr,
663+
rsp: self.orig_rsp,
665664
rflags: 1 << 1, // eflags bit index 1 is reserved and always needs to be 1
666665
..Default::default()
667666
};

src/hyperlight_host/src/hypervisor/kvm.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
use std::convert::TryFrom;
1817
use std::fmt::Debug;
1918
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
2019
use std::sync::{Arc, Mutex};
@@ -44,7 +43,6 @@ use super::{HyperlightExit, Hypervisor, InterruptHandle, LinuxInterruptHandle, V
4443
use crate::HyperlightError;
4544
use crate::hypervisor::get_memory_access_violation;
4645
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
47-
use crate::mem::ptr::{GuestPtr, RawPtr};
4846
use crate::mem::shared_mem::HostSharedMemory;
4947
use crate::sandbox::SandboxConfiguration;
5048
#[cfg(feature = "trace_guest")]
@@ -294,7 +292,7 @@ pub(crate) struct KVMDriver {
294292
page_size: usize,
295293
vcpu_fd: VcpuFd,
296294
entrypoint: u64,
297-
orig_rsp: GuestPtr,
295+
orig_rsp: u64,
298296
interrupt_handle: Arc<LinuxInterruptHandle>,
299297
mem_mgr: Option<MemMgrWrapper<HostSharedMemory>>,
300298
host_funcs: Option<Arc<Mutex<FunctionRegistry>>>,
@@ -356,8 +354,6 @@ impl KVMDriver {
356354
(None, None)
357355
};
358356

359-
let rsp_gp = GuestPtr::try_from(RawPtr::from(rsp))?;
360-
361357
let interrupt_handle = Arc::new(LinuxInterruptHandle {
362358
running: AtomicU64::new(0),
363359
cancel_requested: AtomicBool::new(false),
@@ -389,7 +385,7 @@ impl KVMDriver {
389385
page_size: 0,
390386
vcpu_fd,
391387
entrypoint,
392-
orig_rsp: rsp_gp,
388+
orig_rsp: rsp,
393389
next_slot: mem_regions.len() as u32,
394390
sandbox_regions: mem_regions,
395391
mmap_regions: Vec::new(),
@@ -473,7 +469,7 @@ impl Hypervisor for KVMDriver {
473469
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
474470
fn initialise(
475471
&mut self,
476-
peb_addr: RawPtr,
472+
peb_addr: u64,
477473
seed: u64,
478474
page_size: u32,
479475
mem_mgr: MemMgrWrapper<HostSharedMemory>,
@@ -492,10 +488,10 @@ impl Hypervisor for KVMDriver {
492488

493489
let regs = kvm_regs {
494490
rip: self.entrypoint,
495-
rsp: self.orig_rsp.absolute()?,
491+
rsp: self.orig_rsp,
496492

497493
// function args
498-
rdi: peb_addr.into(),
494+
rdi: peb_addr,
499495
rsi: seed,
500496
rdx: page_size.into(),
501497
rcx: max_guest_log_level,
@@ -573,13 +569,13 @@ impl Hypervisor for KVMDriver {
573569
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
574570
fn dispatch_call_from_host(
575571
&mut self,
576-
dispatch_func_addr: RawPtr,
572+
dispatch_func_addr: u64,
577573
#[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper,
578574
) -> Result<()> {
579575
// Reset general purpose registers, then set RIP and RSP
580576
let regs = kvm_regs {
581-
rip: dispatch_func_addr.into(),
582-
rsp: self.orig_rsp.absolute()?,
577+
rip: dispatch_func_addr,
578+
rsp: self.orig_rsp,
583579
..Default::default()
584580
};
585581
self.vcpu_fd.set_regs(&regs)?;

src/hyperlight_host/src/hypervisor/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ use gdb::VcpuStopReason;
7373

7474
#[cfg(gdb)]
7575
use self::handlers::{DbgMemAccessHandlerCaller, DbgMemAccessHandlerWrapper};
76-
use crate::mem::ptr::RawPtr;
7776
use crate::mem::shared_mem::HostSharedMemory;
7877
use crate::sandbox::host_funcs::FunctionRegistry;
7978
use crate::sandbox::mem_access::handle_mem_access;
@@ -142,7 +141,7 @@ pub(crate) trait Hypervisor: Debug + Send {
142141
#[allow(clippy::too_many_arguments)]
143142
fn initialise(
144143
&mut self,
145-
peb_addr: RawPtr,
144+
peb_addr: u64,
146145
seed: u64,
147146
page_size: u32,
148147
mem_mgr: MemMgrWrapper<HostSharedMemory>,
@@ -174,7 +173,7 @@ pub(crate) trait Hypervisor: Debug + Send {
174173
/// Returns `Ok` if the call succeeded, and an `Err` if it failed
175174
fn dispatch_call_from_host(
176175
&mut self,
177-
dispatch_func_addr: RawPtr,
176+
dispatch_func_addr: u64,
178177
#[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper,
179178
) -> Result<()>;
180179

@@ -542,7 +541,6 @@ pub(crate) mod tests {
542541
return Ok(());
543542
}
544543

545-
use crate::mem::ptr::RawPtr;
546544
use crate::sandbox::host_funcs::FunctionRegistry;
547545
#[cfg(gdb)]
548546
use crate::sandbox::mem_access::dbg_mem_access_handler_wrapper;
@@ -564,7 +562,7 @@ pub(crate) mod tests {
564562
)?;
565563

566564
// Set up required parameters for initialise
567-
let peb_addr = RawPtr::from(0x1000u64); // Dummy PEB address
565+
let peb_addr = 0x1000u64; // Dummy PEB address
568566
let seed = 12345u64; // Random seed
569567
let page_size = 4096u32; // Standard page size
570568
let host_funcs = Arc::new(Mutex::new(FunctionRegistry::default()));

src/hyperlight_host/src/mem/exe.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use std::sync::Arc;
2121
use std::vec::Vec;
2222

2323
use super::elf::ElfInfo;
24-
use super::ptr_offset::Offset;
2524
use crate::Result;
2625

2726
// This is used extremely infrequently, so being unusually large for PE
@@ -94,9 +93,9 @@ impl ExeInfo {
9493
ExeInfo::Elf(_) => DEFAULT_ELF_HEAP_RESERVE,
9594
}
9695
}
97-
pub fn entrypoint(&self) -> Offset {
96+
pub fn entrypoint(&self) -> u64 {
9897
match self {
99-
ExeInfo::Elf(elf) => Offset::from(elf.entrypoint_va()),
98+
ExeInfo::Elf(elf) => elf.entrypoint_va(),
10099
}
101100
}
102101
pub fn loaded_size(&self) -> usize {

0 commit comments

Comments
 (0)