Skip to content

Remove Ptr, RawPtr, GuestPtr, Offset, AddressSpace, GuestAddressSpace #767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/hyperlight_host/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use thiserror::Error;
#[cfg(target_os = "windows")]
use crate::hypervisor::wrappers::HandleWrapper;
use crate::mem::memory_region::MemoryRegionFlags;
use crate::mem::ptr::RawPtr;

/// The error type for Hyperlight operations
#[derive(Error, Debug)]
Expand Down Expand Up @@ -196,10 +195,6 @@ pub enum HyperlightError {
#[error("Failure processing PE File {0:?}")]
PEFileProcessingFailure(#[from] goblin::error::Error),

/// Raw pointer is less than base address
#[error("Raw pointer ({0:?}) was less than the base address ({1})")]
RawPointerLessThanBaseAddress(RawPtr, u64),

/// RefCell borrow failed
#[error("RefCell borrow failed")]
RefCellBorrowFailed(#[from] BorrowError),
Expand Down
33 changes: 16 additions & 17 deletions src/hyperlight_host/src/hypervisor/hyperv_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ use super::{HyperlightExit, Hypervisor, InterruptHandle, LinuxInterruptHandle, V
use crate::HyperlightError;
use crate::hypervisor::get_memory_access_violation;
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
use crate::mem::ptr::{GuestPtr, RawPtr};
use crate::mem::shared_mem::HostSharedMemory;
use crate::sandbox::SandboxConfiguration;
#[cfg(feature = "trace_guest")]
Expand Down Expand Up @@ -313,7 +312,7 @@ pub(crate) struct HypervLinuxDriver {
page_size: usize,
vm_fd: VmFd,
vcpu_fd: VcpuFd,
orig_rsp: GuestPtr,
orig_rsp: u64,
entrypoint: u64,
interrupt_handle: Arc<LinuxInterruptHandle>,
mem_mgr: Option<MemMgrWrapper<HostSharedMemory>>,
Expand Down Expand Up @@ -347,9 +346,9 @@ impl HypervLinuxDriver {
#[instrument(skip_all, parent = Span::current(), level = "Trace")]
pub(crate) fn new(
mem_regions: Vec<MemoryRegion>,
entrypoint_ptr: GuestPtr,
rsp_ptr: GuestPtr,
pml4_ptr: GuestPtr,
entrypoint_ptr: u64,
rsp_ptr: u64,
pml4_ptr: u64,
config: &SandboxConfiguration,
#[cfg(gdb)] gdb_conn: Option<DebugCommChannel<DebugResponse, DebugMsg>>,
#[cfg(crashdump)] rt_cfg: SandboxRuntimeConfig,
Expand Down Expand Up @@ -380,7 +379,7 @@ impl HypervLinuxDriver {
#[cfg(gdb)]
let (debug, gdb_conn) = if let Some(gdb_conn) = gdb_conn {
let mut debug = MshvDebug::new();
debug.add_hw_breakpoint(&vcpu_fd, entrypoint_ptr.absolute()?)?;
debug.add_hw_breakpoint(&vcpu_fd, entrypoint_ptr)?;

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

Self::setup_initial_sregs(&mut vcpu_fd, pml4_ptr.absolute()?)?;
Self::setup_initial_sregs(&mut vcpu_fd, pml4_ptr)?;

let interrupt_handle = Arc::new(LinuxInterruptHandle {
running: AtomicU64::new(0),
Expand Down Expand Up @@ -453,7 +452,7 @@ impl HypervLinuxDriver {
vcpu_fd,
sandbox_regions: mem_regions,
mmap_regions: Vec::new(),
entrypoint: entrypoint_ptr.absolute()?,
entrypoint: entrypoint_ptr,
orig_rsp: rsp_ptr,
interrupt_handle: interrupt_handle.clone(),
mem_mgr: None,
Expand Down Expand Up @@ -585,7 +584,7 @@ impl Hypervisor for HypervLinuxDriver {
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
fn initialise(
&mut self,
peb_addr: RawPtr,
peb_addr: u64,
seed: u64,
page_size: u32,
mem_mgr: MemMgrWrapper<HostSharedMemory>,
Expand All @@ -604,11 +603,11 @@ impl Hypervisor for HypervLinuxDriver {

let regs = StandardRegisters {
rip: self.entrypoint,
rsp: self.orig_rsp.absolute()?,
rsp: self.orig_rsp,
rflags: 2, //bit 1 of rlags is required to be set

// function args
rdi: peb_addr.into(),
rdi: peb_addr,
rsi: seed,
rdx: page_size.into(),
rcx: max_guest_log_level,
Expand Down Expand Up @@ -662,13 +661,13 @@ impl Hypervisor for HypervLinuxDriver {
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
fn dispatch_call_from_host(
&mut self,
dispatch_func_addr: RawPtr,
dispatch_func_addr: u64,
#[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper,
) -> Result<()> {
// Reset general purpose registers, then set RIP and RSP
let regs = StandardRegisters {
rip: dispatch_func_addr.into(),
rsp: self.orig_rsp.absolute()?,
rip: dispatch_func_addr,
rsp: self.orig_rsp,
rflags: 2, //bit 1 of rlags is required to be set
..Default::default()
};
Expand Down Expand Up @@ -1245,9 +1244,9 @@ mod tests {
}
const MEM_SIZE: usize = 0x3000;
let gm = shared_mem_with_code(CODE.as_slice(), MEM_SIZE, 0).unwrap();
let rsp_ptr = GuestPtr::try_from(0).unwrap();
let pml4_ptr = GuestPtr::try_from(0).unwrap();
let entrypoint_ptr = GuestPtr::try_from(0).unwrap();
let rsp_ptr = 0;
let pml4_ptr = 0;
let entrypoint_ptr = 0;
let mut regions = MemoryRegionVecBuilder::new(0, gm.base_addr());
regions.push_page_aligned(
MEM_SIZE,
Expand Down
17 changes: 8 additions & 9 deletions src/hyperlight_host/src/hypervisor/hyperv_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ use crate::hypervisor::fpu::FP_CONTROL_WORD_DEFAULT;
use crate::hypervisor::get_memory_access_violation;
use crate::hypervisor::wrappers::WHvGeneralRegisters;
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
use crate::mem::ptr::{GuestPtr, RawPtr};
use crate::mem::shared_mem::HostSharedMemory;
#[cfg(feature = "trace_guest")]
use crate::sandbox::TraceInfo;
Expand Down Expand Up @@ -281,7 +280,7 @@ pub(crate) struct HypervWindowsDriver {
processor: VMProcessor,
_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
entrypoint: u64,
orig_rsp: GuestPtr,
orig_rsp: u64,
interrupt_handle: Arc<WindowsInterruptHandle>,
mem_mgr: Option<MemMgrWrapper<HostSharedMemory>>,
host_funcs: Option<Arc<Mutex<FunctionRegistry>>>,
Expand Down Expand Up @@ -361,7 +360,7 @@ impl HypervWindowsDriver {
processor: proc,
_surrogate_process: surrogate_process,
entrypoint,
orig_rsp: GuestPtr::try_from(RawPtr::from(rsp))?,
orig_rsp: rsp,
sandbox_regions: mem_regions,
mmap_regions: Vec::new(),
interrupt_handle: interrupt_handle.clone(),
Expand Down Expand Up @@ -600,7 +599,7 @@ impl Hypervisor for HypervWindowsDriver {
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
fn initialise(
&mut self,
peb_address: RawPtr,
peb_address: u64,
seed: u64,
page_size: u32,
mem_mgr: MemMgrWrapper<HostSharedMemory>,
Expand All @@ -618,10 +617,10 @@ impl Hypervisor for HypervWindowsDriver {

let regs = WHvGeneralRegisters {
rip: self.entrypoint,
rsp: self.orig_rsp.absolute()?,
rsp: self.orig_rsp,

// function args
rdi: peb_address.into(),
rdi: peb_address,
rsi: seed,
rdx: page_size.into(),
rcx: max_guest_log_level,
Expand Down Expand Up @@ -655,13 +654,13 @@ impl Hypervisor for HypervWindowsDriver {
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
fn dispatch_call_from_host(
&mut self,
dispatch_func_addr: RawPtr,
dispatch_func_addr: u64,
#[cfg(gdb)] dbg_mem_access_hdl: DbgMemAccessHandlerWrapper,
) -> Result<()> {
// Reset general purpose registers, then set RIP and RSP
let regs = WHvGeneralRegisters {
rip: dispatch_func_addr.into(),
rsp: self.orig_rsp.absolute()?,
rip: dispatch_func_addr,
rsp: self.orig_rsp,
rflags: 1 << 1, // eflags bit index 1 is reserved and always needs to be 1
..Default::default()
};
Expand Down
20 changes: 8 additions & 12 deletions src/hyperlight_host/src/hypervisor/kvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

use std::convert::TryFrom;
use std::fmt::Debug;
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -44,7 +43,6 @@ use super::{HyperlightExit, Hypervisor, InterruptHandle, LinuxInterruptHandle, V
use crate::HyperlightError;
use crate::hypervisor::get_memory_access_violation;
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
use crate::mem::ptr::{GuestPtr, RawPtr};
use crate::mem::shared_mem::HostSharedMemory;
use crate::sandbox::SandboxConfiguration;
#[cfg(feature = "trace_guest")]
Expand Down Expand Up @@ -294,7 +292,7 @@ pub(crate) struct KVMDriver {
page_size: usize,
vcpu_fd: VcpuFd,
entrypoint: u64,
orig_rsp: GuestPtr,
orig_rsp: u64,
interrupt_handle: Arc<LinuxInterruptHandle>,
mem_mgr: Option<MemMgrWrapper<HostSharedMemory>>,
host_funcs: Option<Arc<Mutex<FunctionRegistry>>>,
Expand Down Expand Up @@ -356,8 +354,6 @@ impl KVMDriver {
(None, None)
};

let rsp_gp = GuestPtr::try_from(RawPtr::from(rsp))?;

let interrupt_handle = Arc::new(LinuxInterruptHandle {
running: AtomicU64::new(0),
cancel_requested: AtomicBool::new(false),
Expand Down Expand Up @@ -389,7 +385,7 @@ impl KVMDriver {
page_size: 0,
vcpu_fd,
entrypoint,
orig_rsp: rsp_gp,
orig_rsp: rsp,
next_slot: mem_regions.len() as u32,
sandbox_regions: mem_regions,
mmap_regions: Vec::new(),
Expand Down Expand Up @@ -473,7 +469,7 @@ impl Hypervisor for KVMDriver {
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
fn initialise(
&mut self,
peb_addr: RawPtr,
peb_addr: u64,
seed: u64,
page_size: u32,
mem_mgr: MemMgrWrapper<HostSharedMemory>,
Expand All @@ -492,10 +488,10 @@ impl Hypervisor for KVMDriver {

let regs = kvm_regs {
rip: self.entrypoint,
rsp: self.orig_rsp.absolute()?,
rsp: self.orig_rsp,

// function args
rdi: peb_addr.into(),
rdi: peb_addr,
rsi: seed,
rdx: page_size.into(),
rcx: max_guest_log_level,
Expand Down Expand Up @@ -573,13 +569,13 @@ impl Hypervisor for KVMDriver {
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
fn dispatch_call_from_host(
&mut self,
dispatch_func_addr: RawPtr,
dispatch_func_addr: u64,
#[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper,
) -> Result<()> {
// Reset general purpose registers, then set RIP and RSP
let regs = kvm_regs {
rip: dispatch_func_addr.into(),
rsp: self.orig_rsp.absolute()?,
rip: dispatch_func_addr,
rsp: self.orig_rsp,
..Default::default()
};
self.vcpu_fd.set_regs(&regs)?;
Expand Down
8 changes: 3 additions & 5 deletions src/hyperlight_host/src/hypervisor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ use gdb::VcpuStopReason;

#[cfg(gdb)]
use self::handlers::{DbgMemAccessHandlerCaller, DbgMemAccessHandlerWrapper};
use crate::mem::ptr::RawPtr;
use crate::mem::shared_mem::HostSharedMemory;
use crate::sandbox::host_funcs::FunctionRegistry;
use crate::sandbox::mem_access::handle_mem_access;
Expand Down Expand Up @@ -142,7 +141,7 @@ pub(crate) trait Hypervisor: Debug + Send {
#[allow(clippy::too_many_arguments)]
fn initialise(
&mut self,
peb_addr: RawPtr,
peb_addr: u64,
seed: u64,
page_size: u32,
mem_mgr: MemMgrWrapper<HostSharedMemory>,
Expand Down Expand Up @@ -174,7 +173,7 @@ pub(crate) trait Hypervisor: Debug + Send {
/// Returns `Ok` if the call succeeded, and an `Err` if it failed
fn dispatch_call_from_host(
&mut self,
dispatch_func_addr: RawPtr,
dispatch_func_addr: u64,
#[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper,
) -> Result<()>;

Expand Down Expand Up @@ -542,7 +541,6 @@ pub(crate) mod tests {
return Ok(());
}

use crate::mem::ptr::RawPtr;
use crate::sandbox::host_funcs::FunctionRegistry;
#[cfg(gdb)]
use crate::sandbox::mem_access::dbg_mem_access_handler_wrapper;
Expand All @@ -564,7 +562,7 @@ pub(crate) mod tests {
)?;

// Set up required parameters for initialise
let peb_addr = RawPtr::from(0x1000u64); // Dummy PEB address
let peb_addr = 0x1000u64; // Dummy PEB address
let seed = 12345u64; // Random seed
let page_size = 4096u32; // Standard page size
let host_funcs = Arc::new(Mutex::new(FunctionRegistry::default()));
Expand Down
5 changes: 2 additions & 3 deletions src/hyperlight_host/src/mem/exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use std::sync::Arc;
use std::vec::Vec;

use super::elf::ElfInfo;
use super::ptr_offset::Offset;
use crate::Result;

// This is used extremely infrequently, so being unusually large for PE
Expand Down Expand Up @@ -94,9 +93,9 @@ impl ExeInfo {
ExeInfo::Elf(_) => DEFAULT_ELF_HEAP_RESERVE,
}
}
pub fn entrypoint(&self) -> Offset {
pub fn entrypoint(&self) -> u64 {
match self {
ExeInfo::Elf(elf) => Offset::from(elf.entrypoint_va()),
ExeInfo::Elf(elf) => elf.entrypoint_va(),
}
}
pub fn loaded_size(&self) -> usize {
Expand Down
Loading
Loading