pink-sidevm-env 0.1.4

The low level protocol between sidevm guest and host
Documentation
use super::*;
use crate::args_stack::{I32Convertible, RetDecode, StackedArgs};
use crate::tls::TlsServerConfig;
use std::borrow::Cow;

/// All ocall definitions for pink Sidevm.
#[pink_sidevm_macro::ocall]
pub trait OcallFuncs {
    /// Close given resource by id.
    #[ocall(id = 101)]
    fn close(resource_id: i32) -> Result<()>;

    /// Poll given resource by id and return a dynamic sized data.
    #[ocall(id = 102, encode_output)]
    fn poll(waker_id: i32, resource_id: i32) -> Result<Vec<u8>>;

    /// Poll given resource to read data. Low level support for AsyncRead.
    #[ocall(id = 103)]
    fn poll_read(waker_id: i32, resource_id: i32, data: &mut [u8]) -> Result<u32>;

    /// Poll given resource to write data. Low level support for AsyncWrite.
    #[ocall(id = 104)]
    fn poll_write(waker_id: i32, resource_id: i32, data: &[u8]) -> Result<u32>;

    /// Shutdown a socket
    #[ocall(id = 105)]
    fn poll_shutdown(waker_id: i32, resource_id: i32) -> Result<()>;

    /// Poll given resource to generate a new resource id.
    #[ocall(id = 106)]
    fn poll_res(waker_id: i32, resource_id: i32) -> Result<i32>;

    /// Mark a task as ready for next polling
    #[ocall(id = 109)]
    fn mark_task_ready(task_id: i32) -> Result<()>;

    /// Get the next waken up task id.
    #[ocall(id = 110)]
    fn next_ready_task() -> Result<i32>;

    /// Enable logging for ocalls
    #[ocall(id = 111)]
    fn enable_ocall_trace(enable: bool) -> Result<()>;

    /// Get awake wakers
    #[ocall(id = 112, encode_output)]
    fn awake_wakers() -> Result<Vec<i32>>;

    /// Get random number
    #[ocall(id = 113)]
    fn getrandom(buf: &mut [u8]) -> Result<()>;

    /// Create a timer given a duration of time in milliseconds.
    #[ocall(id = 201)]
    fn create_timer(timeout: i32) -> Result<i32>;

    /// Send data to a oneshot channel.
    #[ocall(id = 202)]
    fn oneshot_send(resource_id: i32, data: &[u8]) -> Result<()>;

    /// Create a TCP socket, bind to given address and listen to incoming connections.
    ///
    /// If `tls_config` is not `None`, then the socket will be TLS encrypted.
    /// Invoke tcp_accept on the returned resource_id to accept incoming connections.
    #[ocall(id = 210, encode_input)]
    fn tcp_listen(addr: Cow<str>, tls_config: Option<TlsServerConfig>) -> Result<i32>;

    /// Accept incoming TCP connections.
    #[ocall(id = 211, encode_output)]
    fn tcp_accept(waker_id: i32, resource_id: i32) -> Result<(i32, String)>;

    /// Accept incoming TCP connections without returning the remote address.
    #[ocall(id = 212)]
    fn tcp_accept_no_addr(waker_id: i32, resource_id: i32) -> Result<i32>;

    /// Initiate a TCP connection to a remote endpoint.
    #[ocall(id = 213)]
    fn tcp_connect(addr: &str) -> Result<i32>;

    /// Print log message.
    #[ocall(id = 220)]
    fn log(level: log::Level, message: &str) -> Result<()>;

    /// Get value from the local cache.
    #[ocall(id = 230, encode_output)]
    fn local_cache_get(key: &[u8]) -> Result<Option<Vec<u8>>>;

    /// Set value to the local cache.
    #[ocall(id = 231)]
    fn local_cache_set(key: &[u8], value: &[u8]) -> Result<()>;

    /// Set expiration time for a key in the local cache.
    #[ocall(id = 232)]
    fn local_cache_set_expiration(key: &[u8], expire_after_secs: u64) -> Result<()>;

    /// Remove a value from the local cache.
    ///
    /// Returns the previous value if it existed.
    #[ocall(id = 233, encode_output)]
    fn local_cache_remove(key: &[u8]) -> Result<Option<Vec<u8>>>;
}