corevm_guest/
c.rs

1//! C API.
2
3#[polkavm_derive::polkavm_import]
4extern "C" {
5	/// Get the current amount of gas.
6	#[polkavm_import(index = 0)]
7	pub fn gas() -> u64;
8
9	/// Allocate memory block of the specified size.
10	///
11	/// - The size is rounded up to the next multiple of page size.
12	/// - The returned address is aligned at a page boundary.
13	///
14	/// Returns the address of the allocated memory region or `0` if the allocation was
15	/// unsuccessful.
16	#[polkavm_import(index = 1)]
17	pub fn alloc(size: u64) -> u64;
18
19	/// Deallocate the memory block of the specified size starting at `address`.
20	///
21	/// Deallocates *all* the pages that overlap the memory block.
22	#[polkavm_import(index = 2)]
23	pub fn free(address: u64, size: u64);
24
25	/// Append the data from `address..address + len` to the _console_ output stream.
26	///
27	/// The data is text encoded as UTF-8.
28	///
29	/// The `stream` can be `1` for standard output and `2` for standard error.
30	#[polkavm_import(index = 3)]
31	pub fn yield_console_data(stream: u64, address: u64, len: u64);
32
33	/// Append a video frame from `address..address + len` to the _video_ output stream.
34	///
35	/// Frame number specifies sequential number of the video frame.
36	///
37	/// The format of the frame is defined by [`video_mode`](crate::video_mode).
38	#[polkavm_import(index = 4)]
39	pub fn yield_video_frame(frame_number: u64, address: u64, len: u64);
40
41	/// Set video monitor output mode.
42	///
43	/// Parameters:
44	/// - `width` is frame width,
45	/// - `height` is frame height,
46	/// - `refresh_rate` is monitor refresh rate measured as the number of frames per second,
47	/// - `format` is frame encoding format; see [`VideoFrameFormat`](crate::VideoFrameFormat) for
48	///   the list of supported formats.
49	///
50	/// By default video output is disabled.
51	#[polkavm_import(index = 5)]
52	pub fn video_mode(width: u64, height: u64, refresh_rate: u64, format: u64);
53}