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:
@ -10,14 +10,15 @@ graph_builder_app_native(wasm_module_inst_t instance,
|
||||
graph_builder_wasm *builder_wasm,
|
||||
graph_builder *builder)
|
||||
{
|
||||
if (!wasm_runtime_validate_app_addr(instance, builder_wasm->buf_offset,
|
||||
builder_wasm->size * sizeof(uint8_t))) {
|
||||
if (!wasm_runtime_validate_app_addr(
|
||||
instance, (uint64)builder_wasm->buf_offset,
|
||||
(uint64)builder_wasm->size * sizeof(uint8_t))) {
|
||||
NN_ERR_PRINTF("builder_wasm->buf_offset is invalid");
|
||||
return invalid_argument;
|
||||
}
|
||||
|
||||
builder->buf = (uint8_t *)wasm_runtime_addr_app_to_native(
|
||||
instance, builder_wasm->buf_offset);
|
||||
instance, (uint64)builder_wasm->buf_offset);
|
||||
builder->size = builder_wasm->size;
|
||||
return success;
|
||||
}
|
||||
@ -27,8 +28,9 @@ graph_builder_array_app_native(wasm_module_inst_t instance,
|
||||
graph_builder_array_wasm *builder_array_wasm,
|
||||
graph_builder_array *builder_array)
|
||||
{
|
||||
if (!wasm_runtime_validate_native_addr(instance, builder_array_wasm,
|
||||
sizeof(graph_builder_array_wasm))) {
|
||||
if (!wasm_runtime_validate_native_addr(
|
||||
instance, builder_array_wasm,
|
||||
(uint64)sizeof(graph_builder_array_wasm))) {
|
||||
NN_ERR_PRINTF("builder_array_wasm is invalid");
|
||||
return invalid_argument;
|
||||
}
|
||||
@ -37,15 +39,15 @@ graph_builder_array_app_native(wasm_module_inst_t instance,
|
||||
builder_array_wasm->size);
|
||||
|
||||
if (!wasm_runtime_validate_app_addr(
|
||||
instance, builder_array_wasm->buf_offset,
|
||||
builder_array_wasm->size * sizeof(graph_builder_wasm))) {
|
||||
instance, (uint64)builder_array_wasm->buf_offset,
|
||||
(uint64)builder_array_wasm->size * sizeof(graph_builder_wasm))) {
|
||||
NN_ERR_PRINTF("builder_array_wasm->buf_offset is invalid");
|
||||
return invalid_argument;
|
||||
}
|
||||
|
||||
graph_builder_wasm *builder_wasm =
|
||||
(graph_builder_wasm *)wasm_runtime_addr_app_to_native(
|
||||
instance, builder_array_wasm->buf_offset);
|
||||
instance, (uint64)builder_array_wasm->buf_offset);
|
||||
|
||||
graph_builder *builder = (graph_builder *)wasm_runtime_malloc(
|
||||
builder_array_wasm->size * sizeof(graph_builder));
|
||||
@ -74,13 +76,14 @@ static error
|
||||
tensor_data_app_native(wasm_module_inst_t instance, uint32_t total_elements,
|
||||
tensor_wasm *input_tensor_wasm, tensor_data *data)
|
||||
{
|
||||
if (!wasm_runtime_validate_app_addr(
|
||||
instance, input_tensor_wasm->data_offset, total_elements)) {
|
||||
if (!wasm_runtime_validate_app_addr(instance,
|
||||
(uint64)input_tensor_wasm->data_offset,
|
||||
(uint64)total_elements)) {
|
||||
NN_ERR_PRINTF("input_tensor_wasm->data_offset is invalid");
|
||||
return invalid_argument;
|
||||
}
|
||||
*data = (tensor_data)wasm_runtime_addr_app_to_native(
|
||||
instance, input_tensor_wasm->data_offset);
|
||||
instance, (uint64)input_tensor_wasm->data_offset);
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -89,19 +92,20 @@ tensor_dimensions_app_native(wasm_module_inst_t instance,
|
||||
tensor_wasm *input_tensor_wasm,
|
||||
tensor_dimensions **dimensions)
|
||||
{
|
||||
if (!wasm_runtime_validate_app_addr(instance,
|
||||
input_tensor_wasm->dimensions_offset,
|
||||
sizeof(tensor_dimensions_wasm))) {
|
||||
if (!wasm_runtime_validate_app_addr(
|
||||
instance, (uint64)input_tensor_wasm->dimensions_offset,
|
||||
(uint64)sizeof(tensor_dimensions_wasm))) {
|
||||
NN_ERR_PRINTF("input_tensor_wasm->dimensions_offset is invalid");
|
||||
return invalid_argument;
|
||||
}
|
||||
|
||||
tensor_dimensions_wasm *dimensions_wasm =
|
||||
(tensor_dimensions_wasm *)wasm_runtime_addr_app_to_native(
|
||||
instance, input_tensor_wasm->dimensions_offset);
|
||||
instance, (uint64)input_tensor_wasm->dimensions_offset);
|
||||
|
||||
if (!wasm_runtime_validate_app_addr(instance, dimensions_wasm->buf_offset,
|
||||
sizeof(tensor_dimensions))) {
|
||||
if (!wasm_runtime_validate_app_addr(instance,
|
||||
(uint64)dimensions_wasm->buf_offset,
|
||||
(uint64)sizeof(tensor_dimensions))) {
|
||||
NN_ERR_PRINTF("dimensions_wasm->buf_offset is invalid");
|
||||
return invalid_argument;
|
||||
}
|
||||
@ -113,7 +117,7 @@ tensor_dimensions_app_native(wasm_module_inst_t instance,
|
||||
|
||||
(*dimensions)->size = dimensions_wasm->size;
|
||||
(*dimensions)->buf = (uint32_t *)wasm_runtime_addr_app_to_native(
|
||||
instance, dimensions_wasm->buf_offset);
|
||||
instance, (uint64)dimensions_wasm->buf_offset);
|
||||
|
||||
NN_DBG_PRINTF("Number of dimensions: %d", (*dimensions)->size);
|
||||
return success;
|
||||
@ -125,7 +129,7 @@ tensor_app_native(wasm_module_inst_t instance, tensor_wasm *input_tensor_wasm,
|
||||
{
|
||||
NN_DBG_PRINTF("Converting tensor_wasm to tensor");
|
||||
if (!wasm_runtime_validate_native_addr(instance, input_tensor_wasm,
|
||||
sizeof(tensor_wasm))) {
|
||||
(uint64)sizeof(tensor_wasm))) {
|
||||
NN_ERR_PRINTF("input_tensor_wasm is invalid");
|
||||
return invalid_argument;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user