1use super::*;
2use crate::args_stack::{I32Convertible, RetDecode, StackedArgs};
3use crate::tls::{TlsClientConfig, TlsServerConfig};
4use std::borrow::Cow;
5
6#[sidevm_macro::ocall]
8pub trait OcallFuncs {
9 #[ocall(id = 101)]
11 fn close(resource_id: i32) -> Result<()>;
12
13 #[ocall(id = 102, encode_output)]
15 fn poll(waker_id: i32, resource_id: i32) -> Result<Vec<u8>>;
16
17 #[ocall(id = 103)]
19 fn poll_read(waker_id: i32, resource_id: i32, data: &mut [u8]) -> Result<u32>;
20
21 #[ocall(id = 104)]
23 fn poll_write(waker_id: i32, resource_id: i32, data: &[u8]) -> Result<u32>;
24
25 #[ocall(id = 105)]
27 fn poll_shutdown(waker_id: i32, resource_id: i32) -> Result<()>;
28
29 #[ocall(id = 106)]
31 fn poll_res(waker_id: i32, resource_id: i32) -> Result<i32>;
32
33 #[ocall(id = 109)]
35 fn mark_task_ready(task_id: i32) -> Result<()>;
36
37 #[ocall(id = 110)]
39 fn next_ready_task() -> Result<i32>;
40
41 #[ocall(id = 111)]
43 fn enable_ocall_trace(enable: bool) -> Result<()>;
44
45 #[ocall(id = 112, encode_output)]
47 fn awake_wakers() -> Result<Vec<i32>>;
48
49 #[ocall(id = 113)]
51 fn getrandom(buf: &mut [u8]) -> Result<()>;
52
53 #[ocall(id = 201)]
55 fn create_timer(timeout: i32) -> Result<i32>;
56
57 #[ocall(id = 202)]
59 fn oneshot_send(resource_id: i32, data: &[u8]) -> Result<()>;
60
61 #[ocall(id = 203)]
63 fn gas_remaining() -> Result<u8>;
64
65 #[ocall(id = 210, encode_input)]
70 fn tcp_listen(addr: Cow<str>, tls_config: Option<TlsServerConfig>) -> Result<i32>;
71
72 #[ocall(id = 211, encode_output)]
74 fn tcp_accept(waker_id: i32, resource_id: i32) -> Result<(i32, String)>;
75
76 #[ocall(id = 212)]
78 fn tcp_accept_no_addr(waker_id: i32, resource_id: i32) -> Result<i32>;
79
80 #[ocall(id = 213)]
82 fn tcp_connect(host: &str, port: u16) -> Result<i32>;
83
84 #[ocall(id = 214, encode_input)]
86 fn tcp_connect_tls(host: String, port: u16, config: TlsClientConfig) -> Result<i32>;
87
88 #[ocall(id = 220)]
90 fn log(level: log::Level, message: &str) -> Result<()>;
91
92 #[ocall(id = 230, encode_output)]
94 fn local_cache_get(key: &[u8]) -> Result<Option<Vec<u8>>>;
95
96 #[ocall(id = 231)]
98 fn local_cache_set(key: &[u8], value: &[u8]) -> Result<()>;
99
100 #[ocall(id = 232)]
102 fn local_cache_set_expiration(key: &[u8], expire_after_secs: u64) -> Result<()>;
103
104 #[ocall(id = 233, encode_output)]
108 fn local_cache_remove(key: &[u8]) -> Result<Option<Vec<u8>>>;
109
110 #[ocall(id = 240, encode_output)]
112 fn create_input_channel(ch: InputChannel) -> Result<i32>;
113}
114
115#[repr(u8)]
116#[derive(Clone, Copy, Debug, PartialEq, Eq)]
117pub enum InputChannel {
118 SystemMessage = 1,
120 GeneralMessage = 2,
122 Query = 3,
124}
125
126impl I32Convertible for InputChannel {
127 fn to_i32(&self) -> i32 {
128 *self as i32
129 }
130 fn from_i32(i: i32) -> Result<Self> {
131 match i {
132 1 => Ok(InputChannel::SystemMessage),
133 2 => Ok(InputChannel::GeneralMessage),
134 3 => Ok(InputChannel::Query),
135 _ => Err(OcallError::InvalidParameter),
136 }
137 }
138}