kona_common/traits/
basic.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//! Defines the [BasicKernelInterface] trait, which describes the functionality of several system
//! calls inside of the FPVM kernel.

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

/// The [BasicKernelInterface] trait describes the functionality of several core system calls inside
/// of the FPVM 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.
///
/// 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.
pub trait BasicKernelInterface {
    /// Write the given buffer to the given file descriptor.
    fn write(fd: FileDescriptor, buf: &[u8]) -> IOResult<usize>;

    /// Read from the given file descriptor into the passed buffer.
    fn read(fd: FileDescriptor, buf: &mut [u8]) -> IOResult<usize>;

    /// Exit the process with the given exit code. The implementation of this function
    /// should always panic after invoking the `EXIT` syscall.
    fn exit(code: usize) -> !;
}