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

@ -0,0 +1,8 @@
# Copyright (C) 2024 Xiaomi Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set (LIB_SHARED_HEAP ${CMAKE_CURRENT_LIST_DIR})
add_definitions (-DWASM_ENABLE_SHARED_HEAP=1)
include_directories(${LIB_SHARED_HEAP_DIR})
file (GLOB source_all ${LIB_SHARED_HEAP}/*.c)
set (LIB_SHARED_HEAP_SOURCE ${source_all})

View File

@ -0,0 +1,55 @@
/*
* Copyright (C) 2024 Xiaomi Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "bh_common.h"
#include "bh_log.h"
#include "wasm_export.h"
#include "../interpreter/wasm.h"
#include "../common/wasm_runtime_common.h"
/* clang-format off */
#define validate_native_addr(addr, size) \
wasm_runtime_validate_native_addr(module_inst, addr, size)
#define module_shared_malloc(size, p_native_addr) \
wasm_runtime_shared_heap_malloc(module_inst, size, p_native_addr)
#define module_shared_free(offset) \
wasm_runtime_shared_heap_free(module_inst, offset)
/* clang-format on */
static uint32
shared_malloc_wrapper(wasm_exec_env_t exec_env, uint32 size)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
return (uint32)module_shared_malloc((uint64)size, NULL);
}
static void
shared_free_wrapper(wasm_exec_env_t exec_env, void *ptr)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
if (!validate_native_addr(ptr, (uint64)sizeof(uint32)))
return;
module_shared_free(addr_native_to_app(ptr));
}
/* clang-format off */
#define REG_NATIVE_FUNC(func_name, signature) \
{ #func_name, func_name##_wrapper, signature, NULL }
/* clang-format on */
static NativeSymbol native_symbols_shared_heap[] = {
REG_NATIVE_FUNC(shared_malloc, "(i)i"),
REG_NATIVE_FUNC(shared_free, "(*)"),
};
uint32
get_lib_shared_heap_export_apis(NativeSymbol **p_shared_heap_apis)
{
*p_shared_heap_apis = native_symbols_shared_heap;
return sizeof(native_symbols_shared_heap) / sizeof(NativeSymbol);
}