1use super::*;
2use crate::args_stack::{I32Convertible, RetDecode, StackedArgs};
3use crate::tls::{TlsClientConfig, TlsServerConfig};
4use std::borrow::Cow;
5
6#[wapo_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 = 210, encode_input)]
66 fn tcp_listen(addr: Cow<str>, tls_config: Option<TlsServerConfig>) -> Result<i32>;
67
68 #[ocall(id = 211, encode_output)]
70 fn tcp_accept(waker_id: i32, resource_id: i32) -> Result<(i32, String)>;
71
72 #[ocall(id = 212)]
74 fn tcp_accept_no_addr(waker_id: i32, resource_id: i32) -> Result<i32>;
75
76 #[ocall(id = 213)]
78 fn tcp_connect(host: &str, port: u16) -> Result<i32>;
79
80 #[ocall(id = 214, encode_input)]
82 fn tcp_connect_tls(host: String, port: u16, config: TlsClientConfig) -> Result<i32>;
83
84 #[ocall(id = 220)]
86 fn log(level: log::Level, message: &str) -> Result<()>;
87
88 #[ocall(id = 240, encode_output)]
90 fn create_input_channel(ch: InputChannel) -> Result<i32>;
91
92 #[ocall(id = 242, encode_output)]
94 fn vmid() -> Result<[u8; 32]>;
95
96 #[ocall(id = 243)]
98 fn emit_program_output(output: &[u8]) -> Result<()>;
99}
100
101#[repr(u8)]
102#[derive(Clone, Copy, Debug, PartialEq, Eq)]
103pub enum InputChannel {
104 Query = 3,
106 HttpRequest = 4,
108}
109
110impl I32Convertible for InputChannel {
111 fn to_i32(&self) -> i32 {
112 *self as i32
113 }
114 fn from_i32(i: i32) -> Result<Self> {
115 match i {
116 3 => Ok(InputChannel::Query),
117 4 => Ok(InputChannel::HttpRequest),
118 _ => Err(OcallError::InvalidParameter),
119 }
120 }
121}