diff --git a/src/hypercall.rs b/src/hypercall.rs index 05d5eaaee..47921ec64 100644 --- a/src/hypercall.rs +++ b/src/hypercall.rs @@ -1,13 +1,15 @@ use std::{ ffi::{OsStr, OsString}, - io, - io::Write, + io::{self, Error, ErrorKind, Write}, os::unix::ffi::OsStrExt, }; use uhyve_interface::{parameters::*, GuestPhysAddr, Hypercall, HypercallAddress, MAX_ARGC_ENVC}; -use crate::mem::MmapMemory; +use crate::{ + mem::{MemoryError, MmapMemory}, + virt_to_phys, +}; /// `addr` is the address of the hypercall parameter in the guest's memory space. `data` is the /// parameter that was send to that address by the guest. @@ -99,7 +101,8 @@ pub fn read(mem: &MmapMemory, sysread: &mut ReadPrams) { unsafe { let bytes_read = libc::read( sysread.fd, - mem.host_address(sysread.buf).unwrap() as *mut libc::c_void, + mem.host_address(virt_to_phys(sysread.buf, mem).unwrap()) + .unwrap() as *mut libc::c_void, sysread.len, ); if bytes_read >= 0 { @@ -115,12 +118,9 @@ pub fn write(mem: &MmapMemory, syswrite: &WriteParams) -> io::Result<()> { let mut bytes_written: usize = 0; while bytes_written != syswrite.len { unsafe { - use std::io::{Error, ErrorKind}; - - use crate::mem::MemoryError; let step = libc::write( syswrite.fd, - mem.host_address(syswrite.buf + bytes_written) + mem.host_address(virt_to_phys(syswrite.buf + bytes_written as u64, mem).unwrap()) .map_err(|e| match e { MemoryError::BoundsViolation => { unreachable!("Bounds violation after host_address function") diff --git a/uhyve-interface/src/parameters.rs b/uhyve-interface/src/parameters.rs index 1d279b684..2f3887fed 100644 --- a/uhyve-interface/src/parameters.rs +++ b/uhyve-interface/src/parameters.rs @@ -2,7 +2,7 @@ use std::path::Path; -use crate::{GuestPhysAddr, MAX_ARGC_ENVC}; +use crate::{GuestPhysAddr, GuestVirtAddr, MAX_ARGC_ENVC}; /// Parameters for a [`Cmdsize`](crate::Hypercall::Cmdsize) hypercall which provides the lengths of the items in the argument end environment vector. #[repr(C, packed)] @@ -84,7 +84,7 @@ pub struct WriteParams { /// File descriptor of the file. pub fd: i32, /// Buffer to be written into the file. - pub buf: GuestPhysAddr, + pub buf: GuestVirtAddr, /// Number of bytes in the buffer to be written. pub len: usize, } @@ -96,7 +96,7 @@ pub struct ReadPrams { /// File descriptor of the file. pub fd: i32, /// Buffer to read the file into. - pub buf: GuestPhysAddr, + pub buf: GuestVirtAddr, /// Number of bytes to read into the buffer. pub len: usize, /// Number of bytes read on success. `-1` on failure.