Refactor APIs and data structures as preliminary work for Memory64 (#3209)
# Change the data type representing linear memory address from u32 to u64
## APIs signature changes
- (Export)wasm_runtime_module_malloc
- wasm_module_malloc
- wasm_module_malloc_internal
- aot_module_malloc
- aot_module_malloc_internal
- wasm_runtime_module_realloc
- wasm_module_realloc
- wasm_module_realloc_internal
- aot_module_realloc
- aot_module_realloc_internal
- (Export)wasm_runtime_module_free
- wasm_module_free
- wasm_module_free_internal
- aot_module_malloc
- aot_module_free_internal
- (Export)wasm_runtime_module_dup_data
- wasm_module_dup_data
- aot_module_dup_data
- (Export)wasm_runtime_validate_app_addr
- (Export)wasm_runtime_validate_app_str_addr
- (Export)wasm_runtime_validate_native_addr
- (Export)wasm_runtime_addr_app_to_native
- (Export)wasm_runtime_addr_native_to_app
- (Export)wasm_runtime_get_app_addr_range
- aot_set_aux_stack
- aot_get_aux_stack
- wasm_set_aux_stack
- wasm_get_aux_stack
- aot_check_app_addr_and_convert, wasm_check_app_addr_and_convert
and jit_check_app_addr_and_convert
- wasm_exec_env_set_aux_stack
- wasm_exec_env_get_aux_stack
- wasm_cluster_create_thread
- wasm_cluster_allocate_aux_stack
- wasm_cluster_free_aux_stack
## Data structure changes
- WASMModule and AOTModule
- field aux_data_end, aux_heap_base and aux_stack_bottom
- WASMExecEnv
- field aux_stack_boundary and aux_stack_bottom
- AOTCompData
- field aux_data_end, aux_heap_base and aux_stack_bottom
- WASMMemoryInstance(AOTMemoryInstance)
- field memory_data_size and change __padding to is_memory64
- WASMModuleInstMemConsumption
- field total_size and memories_size
- WASMDebugExecutionMemory
- field start_offset and current_pos
- WASMCluster
- field stack_tops
## Components that are affected by the APIs and data structure changes
- libc-builtin
- libc-emcc
- libc-uvwasi
- libc-wasi
- Python and Go Language Embedding
- Interpreter Debug engine
- Multi-thread: lib-pthread, wasi-threads and thread manager
This commit is contained in:
@ -134,7 +134,7 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
|
||||
}
|
||||
#endif /* end of BUILD_TARGET_RISCV64_LP64D || BUILD_TARGET_RISCV64_LP64 */
|
||||
|
||||
/* memory has't been mapped or was mapped failed previously */
|
||||
/* memory hasn't been mapped or was mapped failed previously */
|
||||
if (addr == MAP_FAILED) {
|
||||
/* try 5 times */
|
||||
for (i = 0; i < 5; i++) {
|
||||
|
||||
@ -44,6 +44,7 @@ extern "C" {
|
||||
* #endif
|
||||
*/
|
||||
|
||||
typedef uint64 bh_atomic_64_t;
|
||||
typedef uint32 bh_atomic_32_t;
|
||||
typedef uint16 bh_atomic_16_t;
|
||||
|
||||
@ -52,6 +53,10 @@ typedef uint16 bh_atomic_16_t;
|
||||
* If left undefined, it will be automatically defined
|
||||
* according to the platform.
|
||||
*/
|
||||
#ifdef WASM_UINT64_IS_ATOMIC
|
||||
#define BH_ATOMIC_64_IS_ATOMIC WASM_UINT64_IS_ATOMIC
|
||||
#endif /* WASM_UINT64_IS_ATOMIC */
|
||||
|
||||
#ifdef WASM_UINT32_IS_ATOMIC
|
||||
#define BH_ATOMIC_32_IS_ATOMIC WASM_UINT32_IS_ATOMIC
|
||||
#endif /* WASM_UINT32_IS_ATOMIC */
|
||||
@ -71,6 +76,9 @@ typedef uint16 bh_atomic_16_t;
|
||||
#endif
|
||||
|
||||
#if defined(CLANG_GCC_HAS_ATOMIC_BUILTIN)
|
||||
#ifndef BH_ATOMIC_64_IS_ATOMIC
|
||||
#define BH_ATOMIC_64_IS_ATOMIC 1
|
||||
#endif
|
||||
#ifndef BH_ATOMIC_32_IS_ATOMIC
|
||||
#define BH_ATOMIC_32_IS_ATOMIC 1
|
||||
#endif
|
||||
@ -78,6 +86,9 @@ typedef uint16 bh_atomic_16_t;
|
||||
#define BH_ATOMIC_16_IS_ATOMIC 1
|
||||
#endif
|
||||
#else
|
||||
#ifndef BH_ATOMIC_64_IS_ATOMIC
|
||||
#define BH_ATOMIC_64_IS_ATOMIC 0
|
||||
#endif
|
||||
#ifndef BH_ATOMIC_32_IS_ATOMIC
|
||||
#define BH_ATOMIC_32_IS_ATOMIC 0
|
||||
#endif
|
||||
@ -101,6 +112,72 @@ typedef uint16 bh_atomic_16_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* On some 32-bit platform, disable 64-bit atomic operations, otherwise
|
||||
* undefined reference to `__atomic_load_8' */
|
||||
#ifndef WASM_UINT64_IS_ATOMIC
|
||||
#if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) \
|
||||
&& !defined(__OpenBSD__) && (defined(__riscv) || defined(__arm__)) \
|
||||
&& UINT32_MAX == UINTPTR_MAX
|
||||
#undef BH_ATOMIC_64_IS_ATOMIC
|
||||
#define BH_ATOMIC_64_IS_ATOMIC 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if BH_ATOMIC_64_IS_ATOMIC != 0
|
||||
|
||||
#define BH_ATOMIC_64_LOAD(v) __atomic_load_n(&(v), __ATOMIC_SEQ_CST)
|
||||
#define BH_ATOMIC_64_STORE(v, val) __atomic_store_n(&(v), val, __ATOMIC_SEQ_CST)
|
||||
#define BH_ATOMIC_64_FETCH_OR(v, val) \
|
||||
__atomic_fetch_or(&(v), (val), __ATOMIC_SEQ_CST)
|
||||
#define BH_ATOMIC_64_FETCH_AND(v, val) \
|
||||
__atomic_fetch_and(&(v), (val), __ATOMIC_SEQ_CST)
|
||||
#define BH_ATOMIC_64_FETCH_ADD(v, val) \
|
||||
__atomic_fetch_add(&(v), (val), __ATOMIC_SEQ_CST)
|
||||
#define BH_ATOMIC_64_FETCH_SUB(v, val) \
|
||||
__atomic_fetch_sub(&(v), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#else /* else of BH_ATOMIC_64_IS_ATOMIC != 0 */
|
||||
|
||||
#define BH_ATOMIC_64_LOAD(v) (v)
|
||||
#define BH_ATOMIC_64_STORE(v, val) (v) = val
|
||||
#define BH_ATOMIC_64_FETCH_OR(v, val) nonatomic_64_fetch_or(&(v), val)
|
||||
#define BH_ATOMIC_64_FETCH_AND(v, val) nonatomic_64_fetch_and(&(v), val)
|
||||
#define BH_ATOMIC_64_FETCH_ADD(v, val) nonatomic_64_fetch_add(&(v), val)
|
||||
#define BH_ATOMIC_64_FETCH_SUB(v, val) nonatomic_64_fetch_sub(&(v), val)
|
||||
|
||||
static inline uint64
|
||||
nonatomic_64_fetch_or(bh_atomic_64_t *p, uint64 val)
|
||||
{
|
||||
uint64 old = *p;
|
||||
*p |= val;
|
||||
return old;
|
||||
}
|
||||
|
||||
static inline uint64
|
||||
nonatomic_64_fetch_and(bh_atomic_64_t *p, uint64 val)
|
||||
{
|
||||
uint64 old = *p;
|
||||
*p &= val;
|
||||
return old;
|
||||
}
|
||||
|
||||
static inline uint64
|
||||
nonatomic_64_fetch_add(bh_atomic_64_t *p, uint64 val)
|
||||
{
|
||||
uint64 old = *p;
|
||||
*p += val;
|
||||
return old;
|
||||
}
|
||||
|
||||
static inline uint64
|
||||
nonatomic_64_fetch_sub(bh_atomic_64_t *p, uint64 val)
|
||||
{
|
||||
uint64 old = *p;
|
||||
*p -= val;
|
||||
return old;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BH_ATOMIC_32_IS_ATOMIC != 0
|
||||
|
||||
#define BH_ATOMIC_32_LOAD(v) __atomic_load_n(&(v), __ATOMIC_SEQ_CST)
|
||||
|
||||
Reference in New Issue
Block a user