Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ jobs:
if: matrix.arch == 'x86_64'
- run: cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} ${{ matrix.rs_flags }} --package rusty_demo --no-default-features --smp 4 firecracker --sudo
if: matrix.arch == 'x86_64'
- run: cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} ${{ matrix.rs_flags }} --package rusty_demo --features fs uhyve --sudo
- run: cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} ${{ matrix.rs_flags }} --package rusty_demo --features fs,hermit/uhyve uhyve --sudo
if: matrix.arch == 'x86_64'
- run: cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} ${{ matrix.rs_flags }} --package rusty_demo --features fs --smp 4 uhyve --sudo
- run: cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} ${{ matrix.rs_flags }} --package rusty_demo --features fs,hermit/uhyve --smp 4 uhyve --sudo
if: matrix.arch == 'x86_64'
- run: cargo clean
working-directory: .
Expand Down
13 changes: 11 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ default = [
"pci",
"smp",
"tcp",
"uhyve",
"virtio-fs",
"virtio-net",
"virtio-vsock",
Expand Down Expand Up @@ -78,10 +79,18 @@ mman = []
## [hermit-c]: https://github.com/hermit-os/hermit-c
newlib = []

#! ### Platform Features

## Enables [Uhyve] support.
##
## Uhyve is a Hermit-specific _virtual machine monitor_ (VMM).
##
## [Uhyve]: https://github.com/hermit-os/uhyve
uhyve = ["dep:uhyve-interface"]

#! ### Hardware Features
#!
#! [microvm]: https://www.qemu.org/docs/master/system/i386/microvm.html
#! [Uhyve]: https://github.com/hermit-os/uhyve

## Enables _Advanced Configuration and Power Interface_ ([ACPI]) support.
##
Expand Down Expand Up @@ -329,7 +338,7 @@ talc = { version = "5" }
thiserror = { version = "2", default-features = false }
time = { version = "0.3", default-features = false }
volatile = "0.6"
uhyve-interface = "0.1.4"
uhyve-interface = { version = "0.1.4", optional = true }

[dependencies.smoltcp]
version = "0.13"
Expand Down
1 change: 1 addition & 0 deletions src/arch/aarch64/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ pub fn seed_entropy() -> Option<[u8; 32]> {
}

/// The halt function stops the processor until the next interrupt arrives
#[allow(dead_code)]
pub fn halt() {
aarch64_cpu::asm::wfi();
}
Expand Down
1 change: 1 addition & 0 deletions src/arch/riscv64/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ pub fn lsb(value: u64) -> Option<u32> {
}

/// The halt function stops the processor until the next interrupt arrives
#[allow(dead_code)]
pub fn halt() {
riscv::asm::wfi();
}
Expand Down
65 changes: 10 additions & 55 deletions src/console.rs → src/console/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(dead_code)]
#[cfg(feature = "uhyve")]
mod uhyve;

use core::{fmt, mem};

Expand All @@ -11,14 +12,12 @@ use crate::arch::SerialDevice;
use crate::drivers::console::VirtioUART;
use crate::errno::Errno;
use crate::executor::WakerRegistration;
#[cfg(not(target_arch = "riscv64"))]
use crate::uhyve::serial_buf_hypercall;

const SERIAL_BUFFER_SIZE: usize = 256;

pub(crate) enum IoDevice {
#[cfg(not(target_arch = "riscv64"))]
Uhyve(UhyveSerial),
#[cfg(feature = "uhyve")]
Uhyve(uhyve::UhyveSerial),
Uart(SerialDevice),
#[cfg(feature = "virtio-console")]
Virtio(VirtioUART),
Expand All @@ -31,7 +30,7 @@ impl ErrorType for IoDevice {
impl Read for IoDevice {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
match self {
#[cfg(not(target_arch = "riscv64"))]
#[cfg(feature = "uhyve")]
IoDevice::Uhyve(s) => s.read(buf),
IoDevice::Uart(s) => s.read(buf),
#[cfg(feature = "virtio-console")]
Expand All @@ -43,7 +42,7 @@ impl Read for IoDevice {
impl ReadReady for IoDevice {
fn read_ready(&mut self) -> Result<bool, Self::Error> {
match self {
#[cfg(not(target_arch = "riscv64"))]
#[cfg(feature = "uhyve")]
IoDevice::Uhyve(s) => s.read_ready(),
IoDevice::Uart(s) => s.read_ready(),
#[cfg(feature = "virtio-console")]
Expand All @@ -55,7 +54,7 @@ impl ReadReady for IoDevice {
impl Write for IoDevice {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
match self {
#[cfg(not(target_arch = "riscv64"))]
#[cfg(feature = "uhyve")]
IoDevice::Uhyve(s) => s.write_all(buf)?,
IoDevice::Uart(s) => s.write_all(buf)?,
#[cfg(feature = "virtio-console")]
Expand All @@ -77,48 +76,6 @@ impl Write for IoDevice {
}
}

#[cfg(not(target_arch = "riscv64"))]
pub(crate) struct UhyveSerial;

#[cfg(not(target_arch = "riscv64"))]
impl UhyveSerial {
pub const fn new() -> Self {
Self {}
}
}

#[cfg(not(target_arch = "riscv64"))]
impl ErrorType for UhyveSerial {
type Error = Errno;
}

#[cfg(not(target_arch = "riscv64"))]
impl Read for UhyveSerial {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
let _ = buf;
Ok(0)
}
}

#[cfg(not(target_arch = "riscv64"))]
impl ReadReady for UhyveSerial {
fn read_ready(&mut self) -> Result<bool, Self::Error> {
Ok(false)
}
}

#[cfg(not(target_arch = "riscv64"))]
impl Write for UhyveSerial {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
serial_buf_hypercall(buf);
Ok(buf.len())
}

fn flush(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}

pub(crate) struct Console {
device: IoDevice,
buffer: Vec<u8, SERIAL_BUFFER_SIZE>,
Expand Down Expand Up @@ -197,13 +154,11 @@ pub(crate) static CONSOLE_WAKER: InterruptTicketMutex<WakerRegistration> =
pub(crate) static CONSOLE: Lazy<InterruptTicketMutex<Console>> = Lazy::new(|| {
crate::CoreLocal::install();

#[cfg(not(target_arch = "riscv64"))]
#[cfg(feature = "uhyve")]
if crate::env::is_uhyve() {
InterruptTicketMutex::new(Console::new(IoDevice::Uhyve(UhyveSerial::new())))
} else {
InterruptTicketMutex::new(Console::new(IoDevice::Uart(SerialDevice::new())))
return InterruptTicketMutex::new(Console::new(IoDevice::Uhyve(uhyve::UhyveSerial::new())));
}
#[cfg(target_arch = "riscv64")]

InterruptTicketMutex::new(Console::new(IoDevice::Uart(SerialDevice::new())))
});

Expand Down
40 changes: 40 additions & 0 deletions src/console/uhyve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use embedded_io::{ErrorType, Read, ReadReady, Write};

use crate::errno::Errno;
use crate::uhyve::serial_buf_hypercall;

pub(crate) struct UhyveSerial;

impl UhyveSerial {
pub const fn new() -> Self {
Self {}
}
}

impl ErrorType for UhyveSerial {
type Error = Errno;
}

impl Read for UhyveSerial {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
let _ = buf;
Ok(0)
}
}

impl ReadReady for UhyveSerial {
fn read_ready(&mut self) -> Result<bool, Self::Error> {
Ok(false)
}
}

impl Write for UhyveSerial {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
serial_buf_hypercall(buf);
Ok(buf.len())
}

fn flush(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}
37 changes: 25 additions & 12 deletions src/fd/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,29 @@ use crate::fd::socket::tcp;
use crate::fd::socket::udp;
#[cfg(feature = "virtio-vsock")]
use crate::fd::socket::vsock;
use crate::fd::stdio::{
GenericStderr, GenericStdin, GenericStdout, UhyveStderr, UhyveStdin, UhyveStdout,
};
use crate::fd::stdio::{ConsoleStderr, ConsoleStdin, ConsoleStdout};
#[cfg(feature = "uhyve")]
use crate::fd::stdio::{UhyveStderr, UhyveStdin, UhyveStdout};
use crate::fd::{AccessPermission, ObjectInterface, PollEvent, StatusFlags};
#[cfg(any(feature = "net", feature = "virtio-vsock"))]
use crate::fd::{Endpoint, ListenEndpoint, SocketOption};
use crate::fs::mem::{MemDirectoryInterface, RamFileInterface, RomFileInterface};
#[cfg(feature = "uhyve")]
use crate::fs::uhyve::UhyveFileHandle;
#[cfg(feature = "virtio-fs")]
use crate::fs::virtio_fs::{VirtioFsDirectoryHandle, VirtioFsFileHandle};
use crate::fs::{DirectoryReader, FileAttr, SeekWhence};
use crate::io;

pub(crate) enum Fd {
GenericStdin(GenericStdin),
GenericStdout(GenericStdout),
GenericStderr(GenericStderr),
ConsoleStdin(ConsoleStdin),
ConsoleStdout(ConsoleStdout),
ConsoleStderr(ConsoleStderr),
#[cfg(feature = "uhyve")]
UhyveStdin(UhyveStdin),
#[cfg(feature = "uhyve")]
UhyveStdout(UhyveStdout),
#[cfg(feature = "uhyve")]
UhyveStderr(UhyveStderr),
EventFd(EventFd),
#[cfg(feature = "tcp")]
Expand All @@ -48,6 +52,7 @@ pub(crate) enum Fd {
RamFileInterface(RamFileInterface),
MemDirectoryInterface(MemDirectoryInterface),
DirectoryReader(DirectoryReader),
#[cfg(feature = "uhyve")]
UhyveFileHandle(UhyveFileHandle),
}

Expand All @@ -70,11 +75,14 @@ macro_rules! fd_from {
}

fd_from! {
GenericStdin(GenericStdin),
GenericStdout(GenericStdout),
GenericStderr(GenericStderr),
ConsoleStdin(ConsoleStdin),
ConsoleStdout(ConsoleStdout),
ConsoleStderr(ConsoleStderr),
#[cfg(feature = "uhyve")]
UhyveStdin(UhyveStdin),
#[cfg(feature = "uhyve")]
UhyveStdout(UhyveStdout),
#[cfg(feature = "uhyve")]
UhyveStderr(UhyveStderr),
EventFd(EventFd),
#[cfg(feature = "tcp")]
Expand All @@ -93,17 +101,21 @@ fd_from! {
RamFileInterface(RamFileInterface),
MemDirectoryInterface(MemDirectoryInterface),
DirectoryReader(DirectoryReader),
#[cfg(feature = "uhyve")]
UhyveFileHandle(UhyveFileHandle),
}

impl ObjectInterface for Fd {
delegate! {
to match self {
Self::GenericStdin(fd) => fd,
Self::GenericStdout(fd) => fd,
Self::GenericStderr(fd) => fd,
Self::ConsoleStdin(fd) => fd,
Self::ConsoleStdout(fd) => fd,
Self::ConsoleStderr(fd) => fd,
#[cfg(feature = "uhyve")]
Self::UhyveStdin(fd) => fd,
#[cfg(feature = "uhyve")]
Self::UhyveStdout(fd) => fd,
#[cfg(feature = "uhyve")]
Self::UhyveStderr(fd) => fd,
Self::EventFd(fd) => fd,
#[cfg(feature = "tcp")]
Expand All @@ -122,6 +134,7 @@ impl ObjectInterface for Fd {
Self::RamFileInterface(fd) => fd,
Self::MemDirectoryInterface(fd) => fd,
Self::DirectoryReader(fd) => fd,
#[cfg(feature = "uhyve")]
Self::UhyveFileHandle(fd) => fd,
} {
async fn poll(&self, event: PollEvent) -> io::Result<PollEvent>;
Expand Down
Loading
Loading