Skip to content

Commit

Permalink
Fixed incorrect serial write call: This sends a single byte not a who…
Browse files Browse the repository at this point in the history
…le buffer
  • Loading branch information
jounathaen committed Jan 11, 2023
1 parent 14bd171 commit 3541810
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/linux/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl VirtualCPU for UhyveCPU {
Hypercall::FileRead(sysread) => self.read(sysread),
Hypercall::FileWrite(syswrite) => self.write(syswrite)?,
Hypercall::FileUnlink(sysunlink) => self.unlink(sysunlink),
Hypercall::SerialWrite(buf) => self.uart(buf)?,
Hypercall::SerialWriteByte(buf) => self.uart(&[buf])?,
_ => panic!("Got unknown hypercall {:?}", hypercall),
};
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/macos/aarch64/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl VirtualCPU for UhyveCPU {
if let Some(hypercall) = self.address_to_hypercall(addr, data_addr as usize)
{
match hypercall {
Hypercall::SerialWrite(_buf) => {
Hypercall::SerialWriteByte(_char) => {
let x8 = (self.vcpu.read_register(Register::X8)? & 0xFF) as u8;

self.uart(&[x8]).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/macos/x86_64/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ impl VirtualCPU for UhyveCPU {
self.write(syswrite).unwrap()
}
Hypercall::FileUnlink(sysunlink) => self.unlink(sysunlink),
Hypercall::SerialWrite(_buf) => {
Hypercall::SerialWriteByte(_char) => {
// TODO Not sure why this call works different on macos...
let al = (self.vcpu.read_register(&Register::RAX)? & 0xFF) as u8;
self.uart(&[al]).unwrap();
Expand Down
35 changes: 13 additions & 22 deletions src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,60 +71,51 @@ pub trait VirtualCPU {

fn args(&self) -> &[OsString];

/// addr is the address of the hypercall parameter in the guest's memory space.
fn address_to_hypercall(&self, addr: u16, data_addr: usize) -> Option<Hypercall<'_>> {
/// `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.
fn address_to_hypercall(&self, addr: u16, data: usize) -> Option<Hypercall<'_>> {
if let Ok(hypercall_port) = HypercallAddress::try_from(addr) {
Some(match hypercall_port {
HypercallAddress::FileClose => {
let sysclose =
unsafe { &mut *(self.host_address(data_addr) as *mut CloseParams) };
let sysclose = unsafe { &mut *(self.host_address(data) as *mut CloseParams) };
Hypercall::FileClose(sysclose)
}
HypercallAddress::FileLseek => {
let syslseek =
unsafe { &mut *(self.host_address(data_addr) as *mut LseekParams) };
let syslseek = unsafe { &mut *(self.host_address(data) as *mut LseekParams) };
Hypercall::FileLseek(syslseek)
}
HypercallAddress::FileOpen => {
let sysopen =
unsafe { &mut *(self.host_address(data_addr) as *mut OpenParams) };
let sysopen = unsafe { &mut *(self.host_address(data) as *mut OpenParams) };
Hypercall::FileOpen(sysopen)
}
HypercallAddress::FileRead => {
let sysread = unsafe { &mut *(self.host_address(data_addr) as *mut ReadPrams) };
let sysread = unsafe { &mut *(self.host_address(data) as *mut ReadPrams) };
Hypercall::FileRead(sysread)
}
HypercallAddress::FileWrite => {
let syswrite =
unsafe { &*(self.host_address(data_addr) as *const WriteParams) };
let syswrite = unsafe { &*(self.host_address(data) as *const WriteParams) };
Hypercall::FileWrite(syswrite)
}
HypercallAddress::FileUnlink => {
let sysunlink =
unsafe { &mut *(self.host_address(data_addr) as *mut UnlinkParams) };
let sysunlink = unsafe { &mut *(self.host_address(data) as *mut UnlinkParams) };
Hypercall::FileUnlink(sysunlink)
}
HypercallAddress::Exit => {
let sysexit = unsafe { &*(self.host_address(data_addr) as *const ExitParams) };
let sysexit = unsafe { &*(self.host_address(data) as *const ExitParams) };
Hypercall::Exit(sysexit)
}
//HypercallPorts::Netwrite => {}
//HypercallPorts::Netread => {}
//HypercallPorts::Netstat => {}
HypercallAddress::Cmdsize => {
let syssize =
unsafe { &mut *(self.host_address(data_addr) as *mut CmdsizeParams) };
let syssize = unsafe { &mut *(self.host_address(data) as *mut CmdsizeParams) };
Hypercall::Cmdsize(syssize)
}
HypercallAddress::Cmdval => {
let syscmdval =
unsafe { &*(self.host_address(data_addr) as *const CmdvalParams) };
let syscmdval = unsafe { &*(self.host_address(data) as *const CmdvalParams) };
Hypercall::Cmdval(syscmdval)
}
HypercallAddress::Uart => {
let buf = unsafe { &*(self.host_address(data_addr) as *const &[u8]) };
Hypercall::SerialWrite(buf)
}
HypercallAddress::Uart => Hypercall::SerialWriteByte(data as u8),
_ => unimplemented!(),
})
} else {
Expand Down
6 changes: 3 additions & 3 deletions uhyve-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl From<Hypercall<'_>> for HypercallAddress {
Hypercall::FileRead(_) => Self::FileRead,
Hypercall::FileWrite(_) => Self::FileWrite,
Hypercall::FileUnlink(_) => Self::FileUnlink,
Hypercall::SerialWrite(_) => Self::Uart,
Hypercall::SerialWriteByte(_) => Self::Uart,
}
}
}
Expand All @@ -93,8 +93,8 @@ pub enum Hypercall<'a> {
FileRead(&'a mut ReadPrams),
FileWrite(&'a WriteParams),
FileUnlink(&'a mut UnlinkParams),
/// Write a buffer to the terminal.
SerialWrite(&'a [u8]),
/// Write a char to the terminal.
SerialWriteByte(u8),
}
impl<'a> Hypercall<'a> {
/// Get a hypercall's port address.
Expand Down

0 comments on commit 3541810

Please sign in to comment.