Implement a first version of shared heap feature (#3789)

ps. https://github.com/bytecodealliance/wasm-micro-runtime/issues/3546
This commit is contained in:
WenLY1
2024-09-14 10:51:42 +08:00
committed by GitHub
parent 27b69176c1
commit 92852f3719
15 changed files with 826 additions and 22 deletions

View File

@ -135,6 +135,9 @@ typedef struct wasm_section_t {
struct WASMExecEnv;
typedef struct WASMExecEnv *wasm_exec_env_t;
struct WASMSharedHeap;
typedef struct WASMSharedHeap *wasm_shared_heap_t;
/* Package Type */
typedef enum {
Wasm_Module_Bytecode = 0,
@ -320,6 +323,12 @@ typedef enum {
WASM_LOG_LEVEL_VERBOSE = 4
} log_level_t;
#if WASM_ENABLE_SHARED_HEAP != 0
typedef struct SharedHeapInitArgs {
uint32 size;
} SharedHeapInitArgs;
#endif
/**
* Initialize the WASM runtime environment, and also initialize
* the memory allocator with system allocator, which calls os_malloc
@ -2110,6 +2119,52 @@ wasm_runtime_detect_native_stack_overflow_size(wasm_exec_env_t exec_env,
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_is_underlying_binary_freeable(const wasm_module_t module);
#if WASM_ENABLE_SHARED_HEAP != 0
/**
* Create a shared heap
* @param init_args the initialization arguments
* @param error_buf buffer to output the error info if failed
* @param error_buf_size the size of the error buffer
*/
WASM_RUNTIME_API_EXTERN wasm_shared_heap_t
wasm_runtime_create_shared_heap(SharedHeapInitArgs *init_args, char *error_buf,
uint32 error_buf_size);
/**
* Attach a shared heap to a module instance
* @param module_inst the module instance
* @param shared_heap the shared heap
*/
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_attach_shared_heap(wasm_module_inst_t module_inst,
wasm_shared_heap_t shared_heap);
/**
* Detach a shared heap from a module instance
* @param module_inst the module instance
*/
WASM_RUNTIME_API_EXTERN void
wasm_runtime_detach_shared_heap(wasm_module_inst_t module_inst);
/**
* Allocate memory from a shared heap
* @param module_inst the module instance
* @param size required memory size
* @param p_native_addr native address of allocated memory
*/
WASM_RUNTIME_API_EXTERN uint64
wasm_runtime_shared_heap_malloc(wasm_module_inst_t module_inst, uint64 size,
void **p_native_addr);
/**
* Free the memory allocated from shared heap
* @param module_inst the module instance
* @param ptr the offset in wasm app
*/
WASM_RUNTIME_API_EXTERN void
wasm_runtime_shared_heap_free(wasm_module_inst_t module_inst, uint64 ptr);
#endif
#ifdef __cplusplus
}
#endif