1 use crate::{handle_result, wasm_memorytype_t, wasmtime_error_t};
2 use std::cell::UnsafeCell;
3 use wasmtime::SharedMemory;
4
5 type wasmtime_sharedmemory_t = SharedMemory;
6
7 wasmtime_c_api_macros::declare_own!(wasmtime_sharedmemory_t);
8
9 #[unsafe(no_mangle)]
10 #[cfg(feature = "threads")]
wasmtime_sharedmemory_new( engine: &crate::wasm_engine_t, ty: &wasm_memorytype_t, ret: &mut *mut wasmtime_sharedmemory_t, ) -> Option<Box<wasmtime_error_t>>11 pub extern "C" fn wasmtime_sharedmemory_new(
12 engine: &crate::wasm_engine_t,
13 ty: &wasm_memorytype_t,
14 ret: &mut *mut wasmtime_sharedmemory_t,
15 ) -> Option<Box<wasmtime_error_t>> {
16 handle_result(
17 SharedMemory::new(&engine.engine, ty.ty().ty.clone()),
18 |mem| *ret = Box::<wasmtime_sharedmemory_t>::into_raw(Box::new(mem)),
19 )
20 }
21
22 #[unsafe(no_mangle)]
wasmtime_sharedmemory_clone( mem: &wasmtime_sharedmemory_t, ) -> Box<wasmtime_sharedmemory_t>23 pub extern "C" fn wasmtime_sharedmemory_clone(
24 mem: &wasmtime_sharedmemory_t,
25 ) -> Box<wasmtime_sharedmemory_t> {
26 Box::new(mem.clone())
27 }
28
29 #[unsafe(no_mangle)]
wasmtime_sharedmemory_type( mem: &wasmtime_sharedmemory_t, ) -> Box<wasm_memorytype_t>30 pub extern "C" fn wasmtime_sharedmemory_type(
31 mem: &wasmtime_sharedmemory_t,
32 ) -> Box<wasm_memorytype_t> {
33 Box::new(wasm_memorytype_t::new(mem.ty()))
34 }
35
36 #[unsafe(no_mangle)]
wasmtime_sharedmemory_data( mem: &wasmtime_sharedmemory_t, ) -> *const UnsafeCell<u8>37 pub extern "C" fn wasmtime_sharedmemory_data(
38 mem: &wasmtime_sharedmemory_t,
39 ) -> *const UnsafeCell<u8> {
40 mem.data().as_ptr()
41 }
42
43 #[unsafe(no_mangle)]
wasmtime_sharedmemory_data_size(mem: &wasmtime_sharedmemory_t) -> usize44 pub extern "C" fn wasmtime_sharedmemory_data_size(mem: &wasmtime_sharedmemory_t) -> usize {
45 mem.data().len()
46 }
47
48 #[unsafe(no_mangle)]
wasmtime_sharedmemory_size(mem: &wasmtime_sharedmemory_t) -> u6449 pub extern "C" fn wasmtime_sharedmemory_size(mem: &wasmtime_sharedmemory_t) -> u64 {
50 mem.size()
51 }
52
53 #[unsafe(no_mangle)]
wasmtime_sharedmemory_grow( mem: &wasmtime_sharedmemory_t, delta: u64, prev_size: &mut u64, ) -> Option<Box<wasmtime_error_t>>54 pub extern "C" fn wasmtime_sharedmemory_grow(
55 mem: &wasmtime_sharedmemory_t,
56 delta: u64,
57 prev_size: &mut u64,
58 ) -> Option<Box<wasmtime_error_t>> {
59 handle_result(mem.grow(delta), |prev| *prev_size = prev)
60 }
61