@@ -336,6 +336,7 @@ typedef enum {
336336
337337typedef struct SharedHeapInitArgs {
338338 uint32_t size ;
339+ void * pre_allocated_addr ;
339340} SharedHeapInitArgs ;
340341
341342/**
@@ -2258,7 +2259,37 @@ WASM_RUNTIME_API_EXTERN wasm_shared_heap_t
22582259wasm_runtime_create_shared_heap (SharedHeapInitArgs * init_args );
22592260
22602261/**
2261- * Attach a shared heap to a module instance
2262+ * This function links two shared heaps, `head` and `body`, where `head` is a
2263+ * shared heap and `body` can be shared heap chain head, into a single chain.
2264+ * The `head` heap will be the head of the chain, and the `body` heap will be
2265+ * appended to it. At most one shared heap in shared heap chain can be
2266+ * dynamically allocated, the rest have to be the pre-allocated shared heap *
2267+ *
2268+ * @param head The head of the shared heap chain.
2269+ * @param body The body of the shared heap chain to be appended.
2270+ * @return The new head of the shared heap chain. NULL if failed.
2271+ */
2272+ WASM_RUNTIME_API_EXTERN wasm_shared_heap_t
2273+ wasm_runtime_chain_shared_heaps (wasm_shared_heap_t head ,
2274+ wasm_shared_heap_t body );
2275+
2276+ /**
2277+ * This function unchains the shared heaps from the given head. If
2278+ * `entire_chain` is true, it will unchain the entire chain of shared heaps.
2279+ * Otherwise, it will unchain only the first shared heap in the chain.
2280+ *
2281+ * @param head The head of the shared heap chain.
2282+ * @param entire_chain A boolean flag indicating whether to unchain the entire
2283+ * chain.
2284+ * @return The new head of the shared heap chain. Or the last shared heap in the
2285+ * chain if `entire_chain` is true.
2286+ */
2287+ wasm_shared_heap_t
2288+ wasm_runtime_unchain_shared_heaps (wasm_shared_heap_t head , bool entire_chain );
2289+
2290+ /**
2291+ * Attach a shared heap, it can be the head of shared heap chain, in that case,
2292+ * attach the shared heap chain, to a module instance
22622293 *
22632294 * @param module_inst the module instance
22642295 * @param shared_heap the shared heap
@@ -2277,7 +2308,8 @@ WASM_RUNTIME_API_EXTERN void
22772308wasm_runtime_detach_shared_heap (wasm_module_inst_t module_inst );
22782309
22792310/**
2280- * Allocate memory from a shared heap
2311+ * Allocate memory from a shared heap, or the non-preallocated shared heap from
2312+ * the shared heap chain
22812313 *
22822314 * @param module_inst the module instance
22832315 * @param size required memory size
@@ -2294,7 +2326,8 @@ wasm_runtime_shared_heap_malloc(wasm_module_inst_t module_inst, uint64_t size,
22942326 void * * p_native_addr );
22952327
22962328/**
2297- * Free the memory allocated from shared heap
2329+ * Free the memory allocated from shared heap, or the non-preallocated shared
2330+ * heap from the shared heap chain
22982331 *
22992332 * @param module_inst the module instance
23002333 * @param ptr the offset in wasm app
0 commit comments