pub unsafe trait LinearMemory:
Send
+ Sync
+ 'static {
// Required methods
fn byte_size(&self) -> usize;
fn maximum_byte_size(&self) -> Option<usize>;
fn grow_to(&mut self, new_size: usize) -> Result<()>;
fn as_ptr(&self) -> *mut u8;
fn wasm_accessible(&self) -> Range<usize>;
}
runtime
only.Expand description
A linear memory. This trait provides an interface for raw memory buffers which are used by wasmtime, e.g. inside [‘Memory’]. Such buffers are in principle not thread safe. By implementing this trait together with MemoryCreator, one can supply wasmtime with custom allocated host managed memory.
§Safety
The memory should be page aligned and a multiple of page size. To prevent possible silent overflows, the memory should be protected by a guard page. Additionally the safety concerns explained in [‘Memory’], for accessing the memory apply here as well.
Note that this is a relatively new and experimental feature and it is recommended to be familiar with wasmtime runtime code to use it.
Required Methods§
Sourcefn byte_size(&self) -> usize
fn byte_size(&self) -> usize
Returns the number of allocated bytes which are accessible at this time.
Sourcefn maximum_byte_size(&self) -> Option<usize>
fn maximum_byte_size(&self) -> Option<usize>
Returns the maximum number of bytes the memory can grow to.
Returns None
if the memory is unbounded, or Some
if memory cannot
grow beyond a specified limit.
Sourcefn grow_to(&mut self, new_size: usize) -> Result<()>
fn grow_to(&mut self, new_size: usize) -> Result<()>
Grows this memory to have the new_size
, in bytes, specified.
Returns Err
if memory can’t be grown by the specified amount
of bytes. The error may be downcastable to std::io::Error
.
Returns Ok
if memory was grown successfully.
Sourcefn wasm_accessible(&self) -> Range<usize>
fn wasm_accessible(&self) -> Range<usize>
Returns the range of native addresses that WebAssembly can natively access from this linear memory, including guard pages.