Add definitions of Wasm host functions based on channels
Add definitions and documentation of Wasm host functions based on channels, add type alias ChannelHandle and for StatusCode (the latter being used only for the new definitions).
//! Type, constant and Wasm host function definitions for the Oak-Functions application
//! binary interface (ABI).
+type ChannelHandle = u32;
+type StatusCode = u32;
+
pub mod proto {
include!(concat!(env!("OUT_DIR"), "/oak.functions.abi.rs"));
include!(concat!(env!("OUT_DIR"), "/oak.functions.lookup_data.rs"));
@@ -83,4 +86,43 @@ extern "C" {
inference_ptr_ptr: *mut *mut u8,
inference_len_ptr: *mut usize,
) -> u32;
+
+ /// Allocates a buffer on the callers memory to write a message from the channel with
+ /// `channel_handle`. After a successful call `dest_buf_ptr_ptr` holds the address of the
+ /// buffer and `dest_buf_len_ptr` holds its length. The caller can then read
+ /// the message from `dest_buf_ptr_ptr`.
+ ///
+ /// Returns a status code to indicate success. In particular, returns immediately
+ /// with an appropriate status code, if no message is available on the channel.
+ pub fn channel_read(
+ channel_handle: ChannelHandle,
+ dest_buf_ptr_ptr: *mut *mut u8,
+ dest_buf_len_ptr: *mut usize,
+ ) -> StatusCode;
+
+ /// Writes a message, i.e., `src_buf_len` bytes, from `scr_buf_ptr` into the channel with
+ /// `channel_handle`.
+ ///
+ /// Returns a status code to indicate success.
+ pub fn channel_write(
+ channel_handle: ChannelHandle,
+ src_buf_ptr: *const u8,
+ src_buf_len: usize,
+ ) -> StatusCode;
+
+ /// Waits until at least one of the channels from the channel handles in the buffer at
+ /// `channel_handle_buf_ptr` has a message to read, or
+ /// until the `deadline_ms` expires. After a successful call to `channel_wait`, the buffer at
+ /// `ready_channel_handle_buf_ptr` holds the channel handles with at least one message to read.
+ /// Both, `channel_handle_buf_len` and `ready_channel_handle_buf_len` hold the length of the
+ /// respective buffers in bytes.
+ ///
+ /// Returns a status code to indicate success or deadline expiration.
+ pub fn channel_wait(
+ channel_handle_buf_ptr: *const ChannelHandle,
+ channel_handle_buf_len: usize,
+ ready_channel_handle_buf_ptr: *mut *mut i32,
+ ready_channel_handle_buf_len: *mut usize,
+ deadline_ms: u32,
+ ) -> StatusCode;
}
