borderless_abi/
lib.rs

1//! Definition of the wasm interface
2//!
3//! This library does not implement the interface by itself.
4
5#![no_std]
6extern "C" {
7    pub fn print(ptr: u64, len: u64, level: u32);
8
9    // --- Register functions
10    pub fn read_register(register_id: u64, wasm_ptr: u64);
11    pub fn write_register(register_id: u64, wasm_ptr: u64, wasm_ptr_len: u64);
12    pub fn register_len(register_id: u64) -> u64;
13
14    // --- Control flow
15    pub fn panic() -> !;
16    pub fn panic_utf8(len: u64, ptr: u64) -> !;
17
18    // --- Storage API ( Basic )
19    pub fn storage_write(base_key: u64, sub_key: u64, value_ptr: u64, value_len: u64);
20    pub fn storage_read(base_key: u64, sub_key: u64, register_id: u64);
21    pub fn storage_remove(base_key: u64, sub_key: u64);
22    pub fn storage_cursor(base_key: u64) -> u64;
23    pub fn storage_has_key(base_key: u64, sub_key: u64) -> u64;
24
25    // --- Storage API ( Advanced )
26    pub fn storage_gen_sub_key() -> u64; // WARNING: Introduces side-effects ! Use with caution
27    pub fn storage_next_subkey(base_key: u64, from_sub_key: u64) -> u64;
28    pub fn storage_query_subkey_range(base_key: u64, sub_key_start: u64, sub_key_end: u64) -> u64;
29
30    // Profiling
31    pub fn tic(); // matlab style
32    pub fn toc() -> u64; // << TODO: Let's not do that, but instead print out the result, so we don't create side-effects
33
34    // Testing
35    pub fn rand(min: u64, max: u64) -> u64;
36
37    // --- SW-Agent API
38
39    // Sends a http-request to some remote entity and returns the result
40    //
41    // NOTE: We use registers here instead of pointers to make our live easier,
42    // because we essentially return multiple values from this function with unknown size.
43    pub fn send_http_rq(
44        register_rq_head: u64,
45        register_rq_body: u64,
46        register_rs_head: u64,
47        register_rs_body: u64,
48        register_failure: u64,
49    ) -> u64;
50
51    // Returns the current timestamp as milliseconds since epoch
52    pub fn timestamp() -> i64;
53
54    // Send a message via websocket
55    pub fn send_ws_msg(msg_ptr: u64, msg_len: u64) -> u64;
56}
57
58#[derive(Debug)]
59#[repr(u32)]
60pub enum LogLevel {
61    Trace = 0,
62    Debug = 1,
63    Info = 2,
64    Warn = 3,
65    Error = 4,
66}