shared-memory
Shared memory bindings for WASM modules Enables memory sharing between different WASM module instances
- AssemblyScript
- Zig
- Rust
- TinyGo
- C
- C++
// @ts-ignore
@external("shared_memory", "share_memory")
export declare function shareMemory(wasmAddr: u64, size: u32): i32;
// @ts-ignore
@external("shared_memory", "copy_shared_memory")
export declare function copySharedMemory(fromRef: u64, toWasmAddr: u64, offset: u32, size: u32): i32;
// @ts-ignore
@external("shared_memory", "get_shared_memory_len")
export declare function getSharedMemoryLen(sharedAddr: u64): u32;
// @ts-ignore
@external("shared_memory", "remove_memory_sharing")
export declare function removeMemorySharing(sharedAddr: u64): i32;
pub extern "shared_memory" fn share_memory(wasm_addr: u64, size: u32) i32;
pub extern "shared_memory" fn copy_shared_memory(from_ref: u64, to_wasm_addr: u64, offset: u32, size: u32) i32;
pub extern "shared_memory" fn get_shared_memory_len(shared_addr: u64) u32;
pub extern "shared_memory" fn remove_memory_sharing(shared_addr: u64) i32;
#[link(wasm_import_module = "shared_memory")]
extern "C" {
#[link_name = "share_memory"]
fn unsafe_share_memory(wasm_addr: u64, size: u32) -> i32;
#[link_name = "copy_shared_memory"]
fn unsafe_copy_shared_memory(from_ref: u64, to_wasm_addr: u64, offset: u32, size: u32) -> i32;
#[link_name = "get_shared_memory_len"]
fn unsafe_get_shared_memory_len(shared_addr: u64) -> u32;
#[link_name = "remove_memory_sharing"]
fn unsafe_remove_memory_sharing(shared_addr: u64) -> i32;
}
pub fn share_memory(wasm_addr: u64, size: u32) -> i32 {
unsafe {
return unsafe_share_memory(wasm_addr, size);
}
}
pub fn copy_shared_memory(from_ref: u64, to_wasm_addr: u64, offset: u32, size: u32) -> i32 {
unsafe {
return unsafe_copy_shared_memory(from_ref, to_wasm_addr, offset, size);
}
}
pub fn get_shared_memory_len(shared_addr: u64) -> u32 {
unsafe {
return unsafe_get_shared_memory_len(shared_addr);
}
}
pub fn remove_memory_sharing(shared_addr: u64) -> i32 {
unsafe {
return unsafe_remove_memory_sharing(shared_addr);
}
}
package shared-memory
//go:wasmimport shared_memory share_memory
func ShareMemory(WasmAddr uint64, Size uint32) int32;
//go:wasmimport shared_memory copy_shared_memory
func CopySharedMemory(FromRef uint64, ToWasmAddr uint64, Offset uint32, Size uint32) int32;
//go:wasmimport shared_memory get_shared_memory_len
func GetSharedMemoryLen(SharedAddr uint64) uint32;
//go:wasmimport shared_memory remove_memory_sharing
func RemoveMemorySharing(SharedAddr uint64) int32;
__attribute__((import_module("shared_memory")))
__attribute__((import_name("share_memory")))
extern int share_memory(unsigned long wasm_addr, unsigned int size);
__attribute__((import_module("shared_memory")))
__attribute__((import_name("copy_shared_memory")))
extern int copy_shared_memory(unsigned long from_ref, unsigned long to_wasm_addr, unsigned int offset, unsigned int size);
__attribute__((import_module("shared_memory")))
__attribute__((import_name("get_shared_memory_len")))
extern unsigned int get_shared_memory_len(unsigned long shared_addr);
__attribute__((import_module("shared_memory")))
__attribute__((import_name("remove_memory_sharing")))
extern int remove_memory_sharing(unsigned long shared_addr);
extern "C" {
__attribute__((import_module("shared_memory")))
__attribute__((import_name("share_memory")))
extern int share_memory(unsigned long wasm_addr, unsigned int size);
__attribute__((import_module("shared_memory")))
__attribute__((import_name("copy_shared_memory")))
extern int copy_shared_memory(unsigned long from_ref, unsigned long to_wasm_addr, unsigned int offset, unsigned int size);
__attribute__((import_module("shared_memory")))
__attribute__((import_name("get_shared_memory_len")))
extern unsigned int get_shared_memory_len(unsigned long shared_addr);
__attribute__((import_module("shared_memory")))
__attribute__((import_name("remove_memory_sharing")))
extern int remove_memory_sharing(unsigned long shared_addr);
}