| Copyright | (c) 2026 Tushar Adhatrao |
|---|---|
| License | MIT |
| Stability | stable |
| Safe Haskell | None |
| Language | GHC2021 |
WasmEdge.Memory
Description
Provides types and functions for inspecting and manipulating WebAssembly linear memory instances:
MemoryType— describes the page limits of a linear memoryMemoryInstance— a runtime linear memory instance with byte-level read/write
Synopsis
- data MemoryType
- createMemoryType :: Limit -> IO MemoryType
- deleteMemoryType :: MemoryType -> IO ()
- withMemoryType :: Limit -> (MemoryType -> IO a) -> IO a
- getMemoryTypeLimit :: MemoryType -> IO Limit
- data MemoryInstance
- createMemory :: MemoryType -> IO MemoryInstance
- deleteMemory :: MemoryInstance -> IO ()
- withMemory :: MemoryType -> (MemoryInstance -> IO a) -> IO a
- getMemoryType :: MemoryInstance -> IO MemoryType
- getMemoryData :: MemoryInstance -> Word32 -> Word32 -> IO (WasmResult ByteString)
- setMemoryData :: MemoryInstance -> Word32 -> ByteString -> IO (WasmResult ())
- getMemoryPointer :: MemoryInstance -> Word32 -> Word32 -> IO (Ptr Word8)
- getMemoryPointerConst :: MemoryInstance -> Word32 -> Word32 -> IO (Ptr Word8)
- getMemoryPageSize :: MemoryInstance -> IO Word32
- growMemoryPages :: MemoryInstance -> Word32 -> IO (WasmResult ())
- unsafeMemoryPtr :: MemoryInstance -> IO (Ptr MemoryInstanceTag)
- borrowMemory :: Ptr MemoryInstanceTag -> IO MemoryInstance
- unsafeMemoryTypePtr :: MemoryType -> IO (Ptr MemoryTypeTag)
- borrowMemoryType :: Ptr MemoryTypeTag -> IO MemoryType
- disarmMemory :: MemoryInstance -> IO ()
Memory type
data MemoryType #
A WebAssembly linear memory type, specifying min/max page limits.
createMemoryType :: Limit -> IO MemoryType #
Create a MemoryType with the given Limit.
1 page = 64 KiB (65,536 bytes).
deleteMemoryType :: MemoryType -> IO () #
Delete a MemoryType.
withMemoryType :: Limit -> (MemoryType -> IO a) -> IO a #
Scoped MemoryType.
getMemoryTypeLimit :: MemoryType -> IO Limit #
Get the Limit of a MemoryType.
Memory instance
data MemoryInstance #
A runtime WebAssembly linear memory instance.
createMemory :: MemoryType -> IO MemoryInstance #
Create a MemoryInstance from a MemoryType.
deleteMemory :: MemoryInstance -> IO () #
Delete a MemoryInstance.
withMemory :: MemoryType -> (MemoryInstance -> IO a) -> IO a #
Scoped MemoryInstance.
getMemoryType :: MemoryInstance -> IO MemoryType #
Get the MemoryType of a MemoryInstance.
getMemoryData :: MemoryInstance -> Word32 -> Word32 -> IO (WasmResult ByteString) #
Read length bytes from linear memory starting at offset.
setMemoryData :: MemoryInstance -> Word32 -> ByteString -> IO (WasmResult ()) #
Write a ByteString into linear memory starting at offset.
getMemoryPointer :: MemoryInstance -> Word32 -> Word32 -> IO (Ptr Word8) #
Get a direct pointer to linear memory at offset for length bytes.
The pointer is valid only as long as the memory is not grown and the instance is alive.
getMemoryPointerConst :: MemoryInstance -> Word32 -> Word32 -> IO (Ptr Word8) #
Const variant of getMemoryPointer.
getMemoryPageSize :: MemoryInstance -> IO Word32 #
Get the current size in pages (1 page = 64 KiB).
growMemoryPages :: MemoryInstance -> Word32 -> IO (WasmResult ()) #
Grow linear memory by pageCount pages.
Internal / borrowed pointers
unsafeMemoryPtr :: MemoryInstance -> IO (Ptr MemoryInstanceTag) #
Extract the raw pointer of a MemoryInstance.
borrowMemory :: Ptr MemoryInstanceTag -> IO MemoryInstance #
Create a borrowed MemoryInstance from a raw pointer (does not finalize).
unsafeMemoryTypePtr :: MemoryType -> IO (Ptr MemoryTypeTag) #
Extract the raw pointer of a MemoryType.
borrowMemoryType :: Ptr MemoryTypeTag -> IO MemoryType #
Create a borrowed MemoryType from a raw pointer (does not finalize).
disarmMemory :: MemoryInstance -> IO () #
Disarm finalizer when ownership is transferred to a module instance.