Skip to content

Commit

Permalink
Fixed incorrect type of the data buffers in the two file system hyper…
Browse files Browse the repository at this point in the history
…calls.

Note: I did not increase the interface version, as there are no kernels out there that have used the incorrect type and uhyve has always treated it the way it is now.
  • Loading branch information
jounathaen committed Feb 19, 2024
1 parent 962dac7 commit b41f35d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/hypercall.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions uhyve-interface/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
}
Expand All @@ -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.
Expand Down

0 comments on commit b41f35d

Please sign in to comment.