corevm-guest 0.1.16

API/SDK for CoreVM guest programs
Documentation
//! C API.

#[polkavm_derive::polkavm_import]
extern "C" {
	/// Get the current amount of gas.
	#[polkavm_import(index = 0)]
	pub fn gas() -> u64;

	/// Allocate memory block of the specified size.
	///
	/// - The size is rounded up to the next multiple of page size.
	/// - The returned address is aligned at a page boundary.
	///
	/// Returns the address of the allocated memory region or `0` if the allocation was
	/// unsuccessful.
	#[polkavm_import(index = 1)]
	pub fn alloc(size: u64) -> u64;

	/// Deallocate the memory block of the specified size starting at `address`.
	///
	/// Deallocates *all* the pages that overlap the memory block.
	#[polkavm_import(index = 2)]
	pub fn free(address: u64, size: u64);

	/// Append the data from `address..address + len` to the _console_ output stream.
	///
	/// The data is text encoded as UTF-8.
	///
	/// The `stream` can be `1` for standard output and `2` for standard error.
	#[polkavm_import(index = 3)]
	pub fn yield_console_data(stream: u64, address: u64, len: u64);

	/// Append a video frame from `address..address + len` to the _video_ output stream.
	///
	/// Frame number specifies sequential number of the video frame.
	///
	/// The format of the frame is defined by [`video_mode`](crate::video_mode).
	#[polkavm_import(index = 4)]
	pub fn yield_video_frame(frame_number: u64, address: u64, len: u64);

	/// Set video monitor output mode.
	///
	/// Parameters:
	/// - `width` is frame width,
	/// - `height` is frame height,
	/// - `refresh_rate` is monitor refresh rate measured as the number of frames per second,
	/// - `format` is frame encoding format; see [`VideoFrameFormat`](crate::VideoFrameFormat) for
	///   the list of supported formats.
	///
	/// By default video output is disabled.
	#[polkavm_import(index = 5)]
	pub fn video_mode(width: u64, height: u64, refresh_rate: u64, format: u64);
}