1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
pub use holochain_wasmer_common::allocation;
pub use holochain_wasmer_common::bytes;
pub use holochain_wasmer_common::error::Error;
pub use holochain_wasmer_common::*;
extern "C" {
fn __import_allocation(guest_allocation_ptr: AllocationPtr, host_allocation_ptr: AllocationPtr);
fn __import_bytes(host_allocation_ptr: AllocationPtr, guest_bytes_ptr: Ptr);
}
pub fn map_bytes(host_allocation_ptr: Ptr) -> AllocationPtr {
let tmp_allocation_ptr = allocation::allocate(allocation::ALLOCATION_BYTES_ITEMS as Len);
unsafe {
__import_allocation(tmp_allocation_ptr, host_allocation_ptr);
};
let [_, len] = allocation::from_allocation_ptr(tmp_allocation_ptr);
allocation::deallocate(tmp_allocation_ptr, len);
let guest_bytes_ptr = allocation::allocate(len);
unsafe {
__import_bytes(host_allocation_ptr, guest_bytes_ptr);
};
allocation::to_allocation_ptr([guest_bytes_ptr, len])
}
#[macro_export]
macro_rules! host_call {
($func_name:ident, $input:ident) => {
host_string_from_host_allocation_ptr(unsafe {
$func_name(allocation::to_allocation_ptr([
$input.as_ptr() as Ptr,
$input.len() as Len,
]))
})
};
}