This repository has been archived on 2023-11-05. You can view files and clone it, but cannot push or open issues or pull requests.
wasm-micro-runtime/core/iwasm/interpreter/wasm_loader.h
liang.he 50b6474f54
Add WASI ABI compatibility check for multi-module (#913)
Refer to https://github.com/WebAssembly/WASI/blob/main/design/application-abi.md
to check the WASI ABI compatibility:
- Command (main module) may export _start function with signature "()"
- Reactor (sub module) may export _initialize function with signature "()"
- _start and _initialize can not be exported at the same time
- Reactor cannot export _start function
- Command and Reactor must export memory

And
- Rename module->is_wasi_module to module->import_wasi_api
- Refactor wasm_loader_find_export()
- Remove MULTI_MODULE related codes from mini_loader
- Update multi-module samples
- Fix a "use-after-free" issue. Since we reuse the memory instance of sub module,
   just to protect it from freeing an imported memory instance
2021-12-29 11:04:36 +08:00

81 lines
2.3 KiB
C

/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WASM_LOADER_H
#define _WASM_LOADER_H
#include "wasm.h"
#include "bh_hashmap.h"
#include "../common/wasm_runtime_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Load a WASM module from a specified byte buffer.
*
* @param buf the byte buffer which contains the WASM binary data
* @param size the size of the buffer
* @param error_buf output of the exception info
* @param error_buf_size the size of the exception string
*
* @return return module loaded, NULL if failed
*/
WASMModule *
wasm_loader_load(const uint8 *buf, uint32 size,
#if WASM_ENABLE_MULTI_MODULE != 0
bool main_module,
#endif
char *error_buf, uint32 error_buf_size);
/**
* Load a WASM module from a specified WASM section list.
*
* @param section_list the section list which contains each section data
* @param error_buf output of the exception info
* @param error_buf_size the size of the exception string
*
* @return return WASM module loaded, NULL if failed
*/
WASMModule *
wasm_loader_load_from_sections(WASMSection *section_list, char *error_buf,
uint32 error_buf_size);
/**
* Unload a WASM module.
*
* @param module the module to be unloaded
*/
void
wasm_loader_unload(WASMModule *module);
/**
* Find address of related else opcode and end opcode of opcode block/loop/if
* according to the start address of opcode.
*
* @param module the module to find
* @param start_addr the next address of opcode block/loop/if
* @param code_end_addr the end address of function code block
* @param block_type the type of block, 0/1/2 denotes block/loop/if
* @param p_else_addr returns the else addr if found
* @param p_end_addr returns the end addr if found
* @param error_buf returns the error log for this function
* @param error_buf_size returns the error log string length
*
* @return true if success, false otherwise
*/
bool
wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache,
const uint8 *start_addr, const uint8 *code_end_addr,
uint8 block_type, uint8 **p_else_addr,
uint8 **p_end_addr);
#ifdef __cplusplus
}
#endif
#endif /* end of _WASM_LOADER_H */