Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(common): Rename IO modules #812

Merged
merged 3 commits into from
Nov 14, 2024
Merged
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
7 changes: 3 additions & 4 deletions crates/common/src/io.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
//! This module contains the `ClientIO` struct, which is used to perform various IO operations
//! inside of the FPVM kernel within a `client` program.
//! This module contains the `ClientIO` struct, which is a system call interface for the kernel.

use crate::{errors::IOResult, BasicKernelInterface, FileDescriptor};
use cfg_if::cfg_if;

cfg_if! {
if #[cfg(target_arch = "mips")] {
#[doc = "Concrete implementation of the [BasicKernelInterface] trait for the `MIPS32rel1` target architecture."]
pub(crate) type ClientIO = crate::cannon::io::CannonIO;
pub(crate) type ClientIO = crate::mips32::io::Mips32IO;
} else if #[cfg(target_arch = "riscv64")] {
#[doc = "Concrete implementation of the [BasicKernelInterface] trait for the `riscv64` target architecture."]
pub(crate) type ClientIO = crate::asterisc::io::AsteriscIO;
pub(crate) type ClientIO = crate::riscv64::io::RiscV64IO;
} else if #[cfg(target_os = "zkvm")] {
#[doc = "Concrete implementation of the [BasicKernelInterface] trait for the `SP1` target architecture."]
pub(crate) type ClientIO = crate::zkvm::io::ZkvmIO;
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ pub use executor::block_on;
pub(crate) mod linux;

#[cfg(target_arch = "mips")]
pub(crate) mod cannon;
pub(crate) mod mips32;

#[cfg(target_arch = "riscv64")]
pub(crate) mod asterisc;
pub(crate) mod riscv64;

#[cfg(target_os = "zkvm")]
pub(crate) mod zkvm;
4 changes: 2 additions & 2 deletions crates/common/src/malloc.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! This module contains an implementation of a basic memory allocator for client programs in
//! running on top of various FPVMs.
//! running on an embedded device.
//!
//! The allocator is a linked list allocator based on the `dlmalloc` algorithm, which is a
//! well-known and widely used allocator software such as OS Kernels.

/// The global allocator for the program in FPVM environments.
/// The global allocator for the program in embedded environments.
#[cfg(any(target_arch = "mips", target_arch = "riscv64"))]
pub mod global_allocator {
use linked_list_allocator::LockedHeap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{cannon::syscall, errors::IOResult, BasicKernelInterface, FileDescriptor};
use crate::{errors::IOResult, mips32::syscall, BasicKernelInterface, FileDescriptor};

/// Concrete implementation of the [BasicKernelInterface] trait for the `MIPS32rel1` target
/// architecture. Exposes a safe interface for performing IO operations within the FPVM kernel.
/// architecture. Exposes a safe interface for performing IO operations within the kernel.
#[derive(Debug)]
pub(crate) struct CannonIO;
pub(crate) struct Mips32IO;

/// Relevant system call numbers for the `MIPS32rel1` target architecture.
///
Expand All @@ -23,7 +23,7 @@ pub(crate) enum SyscallNumber {
Write = 4004,
}

impl BasicKernelInterface for CannonIO {
impl BasicKernelInterface for Mips32IO {
fn write(fd: FileDescriptor, buf: &[u8]) -> IOResult<usize> {
unsafe {
crate::linux::from_ret(syscall::syscall3(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use crate::{asterisc::syscall, errors::IOResult, BasicKernelInterface, FileDescriptor};
use crate::{errors::IOResult, riscv64::syscall, BasicKernelInterface, FileDescriptor};

/// Concrete implementation of the [`KernelIO`] trait for the `riscv64` target architecture.
#[derive(Debug)]
pub(crate) struct AsteriscIO;
pub(crate) struct RiscV64IO;

/// Relevant system call numbers for the `riscv64` target architecture.
///
/// See https://jborza.com/post/2021-05-11-riscv-linux-syscalls/
///
/// **Note**: This is not an exhaustive list of system calls available to the `client` program,
/// only the ones necessary for the [BasicKernelInterface] trait implementation. If an extension
/// trait for the [BasicKernelInterface] trait is created for the `asterisc` kernel, this list
/// trait for the [BasicKernelInterface] trait is created for the linux kernel, this list
/// should be extended accordingly.
#[repr(usize)]
pub(crate) enum SyscallNumber {
Expand All @@ -22,7 +22,7 @@ pub(crate) enum SyscallNumber {
Write = 64,
}

impl BasicKernelInterface for AsteriscIO {
impl BasicKernelInterface for RiscV64IO {
fn write(fd: FileDescriptor, buf: &[u8]) -> IOResult<usize> {
unsafe {
crate::linux::from_ret(syscall::syscall3(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! This module contains raw syscall bindings for the `riscv64gc` target architecture, as well as a
//! high-level implementation of the [crate::BasicKernelInterface] trait for the `asterisc` kernel.
//! high-level implementation of the [crate::BasicKernelInterface] trait for the kernel.

pub(crate) mod io;
mod syscall;
9 changes: 5 additions & 4 deletions crates/common/src/traits/basic.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//! Defines the [BasicKernelInterface] trait, which describes the functionality of several system
//! calls inside of the FPVM kernel.
//! calls inside of the kernel.

use crate::{errors::IOResult, FileDescriptor};

/// The [BasicKernelInterface] trait describes the functionality of several core system calls inside
/// of the FPVM kernel.
/// of the kernel.
///
/// Commonly, FPVMs delegate IO operations to custom file descriptors in the `client` program. It is
/// a safe wrapper around the raw system calls available to the `client` program.
/// Commonly, embedded proving environments delegate IO operations to custom file descriptors.
/// This trait is a safe wrapper around the raw system calls available to the `client` program
/// for host<->client communication.
///
/// In cases where the set of system calls defined in this trait need to be extended, an additional
/// trait should be created that extends this trait.
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! architecture-specific type that provides the concrete implementation of the
//! kernel interfaces. The `client` program then uses these traits to perform operations
//! without needing to know the underlying implementation, which allows the same `client`
//! program to be compiled and ran on different target FPVM architectures.
//! program to be compiled and ran on different target architectures.

mod basic;
pub use basic::BasicKernelInterface;
Loading