Skip to content
Draft
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ thiserror = { version = "2", default-features = false }
time = { version = "0.3", default-features = false }
volatile = "0.6"
zerocopy = { version = "0.8", default-features = false }
uhyve-interface = "0.1.3"
uhyve-interface = "0.2.0"

[dependencies.smoltcp]
version = "0.12"
Expand Down
5 changes: 3 additions & 2 deletions src/fd/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use core::task::Poll;

use async_trait::async_trait;
use embedded_io::{Read, ReadReady, Write};
use uhyve_interface::parameters::WriteParams;
use uhyve_interface::{GuestVirtAddr, Hypercall};
use uhyve_interface::GuestVirtAddr;
use uhyve_interface::v2::Hypercall;
use uhyve_interface::v2::parameters::WriteParams;

use crate::console::{CONSOLE, CONSOLE_WAKER};
use crate::fd::{
Expand Down
5 changes: 3 additions & 2 deletions src/fs/uhyve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ use async_lock::Mutex;
use async_trait::async_trait;
use embedded_io::{ErrorType, Read, Write};
use memory_addresses::VirtAddr;
use uhyve_interface::parameters::{
use uhyve_interface::v2::Hypercall;
use uhyve_interface::v2::parameters::{
CloseParams, LseekParams, OpenParams, ReadParams, UnlinkParams, WriteParams,
};
use uhyve_interface::{GuestPhysAddr, GuestVirtAddr, Hypercall};
use uhyve_interface::{GuestPhysAddr, GuestVirtAddr};

use crate::arch::mm::paging;
use crate::errno::Errno;
Expand Down
27 changes: 11 additions & 16 deletions src/syscalls/interfaces/uhyve.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use core::ptr;

use memory_addresses::VirtAddr;
use uhyve_interface::parameters::{ExitParams, SerialWriteBufferParams};
use uhyve_interface::{Hypercall, HypercallAddress};
use memory_addresses::{PhysAddr, VirtAddr};
use uhyve_interface::v2::parameters::{ExitParams, SerialWriteBufferParams};
use uhyve_interface::v2::{Hypercall, HypercallAddress};

use crate::arch;
use crate::arch::mm::paging::{self, virtual_to_physical};
use crate::syscalls::interfaces::SyscallInterface;

/// perform a SerialWriteBuffer hypercall with `buf` as payload.
/// perform a SerialWriteBuffer hypercall with `buf` as payload
#[inline]
#[cfg_attr(target_arch = "riscv64", expect(dead_code))]
pub(crate) fn serial_buf_hypercall(buf: &[u8]) {
Expand All @@ -31,9 +31,7 @@ fn data_addr<T>(data: &T) -> u64 {
#[inline]
fn hypercall_data(hypercall: &Hypercall<'_>) -> u64 {
match hypercall {
Hypercall::Cmdsize(data) => data_addr(*data),
Hypercall::Cmdval(data) => data_addr(*data),
Hypercall::Exit(data) => data_addr(*data),
Hypercall::Exit(exit_code) => u64::try_from(*exit_code).unwrap(),
Hypercall::FileClose(data) => data_addr(*data),
Hypercall::FileLseek(data) => data_addr(*data),
Hypercall::FileOpen(data) => data_addr(*data),
Expand All @@ -50,24 +48,21 @@ fn hypercall_data(hypercall: &Hypercall<'_>) -> u64 {
#[inline]
#[allow(unused_variables)] // until riscv64 is implemented
pub(crate) fn uhyve_hypercall(hypercall: Hypercall<'_>) {
let ptr = HypercallAddress::from(&hypercall) as u16;
let mut ptr = HypercallAddress::from(&hypercall) as u64;
let data = hypercall_data(&hypercall);

#[cfg(target_arch = "x86_64")]
unsafe {
use x86_64::instructions::port::Port;

let data =
u32::try_from(data).expect("Hypercall data must lie in the first 4GiB of memory");
Port::new(ptr).write(data);
{
let ptr = ptr as *mut u64;
unsafe { ptr.write_volatile(data) };
}

#[cfg(target_arch = "aarch64")]
unsafe {
use core::arch::asm;
asm!(
"str x8, [{ptr}]",
ptr = in(reg) u64::from(ptr),
ptr = in(reg) ptr,
in("x8") data,
options(nostack),
);
Expand All @@ -82,7 +77,7 @@ pub struct Uhyve;
impl SyscallInterface for Uhyve {
fn shutdown(&self, error_code: i32) -> ! {
let sysexit = ExitParams { arg: error_code };
uhyve_hypercall(Hypercall::Exit(&sysexit));
uhyve_hypercall(Hypercall::Exit(error_code));

loop {
arch::processor::halt();
Expand Down
Loading