Remove get_module_inst() and fix issue of call native (#120)
This commit is contained in:
@ -22,9 +22,6 @@
|
||||
#include "bh_platform.h"
|
||||
#include "wasm_export.h"
|
||||
|
||||
#define get_module_inst() \
|
||||
wasm_runtime_get_current_module_inst()
|
||||
|
||||
#define validate_app_addr(offset, size) \
|
||||
wasm_runtime_validate_app_addr(module_inst, offset, size)
|
||||
|
||||
|
||||
@ -14,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _WASM_EXPORT_H
|
||||
#define _WASM_EXPORT_H
|
||||
#ifndef _WASM_EXPORT_API_H
|
||||
#define _WASM_EXPORT_API_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
@ -28,6 +28,31 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void
|
||||
wasm_runtime_get_current_module_inst1(uint64_t *p_module_inst);
|
||||
|
||||
bool
|
||||
wasm_runtime_validate_app_addr1(uint32_t module_inst_part0,
|
||||
uint32_t module_inst_part1,
|
||||
int32_t app_offset, uint32_t size);
|
||||
bool
|
||||
wasm_runtime_validate_native_addr1(uint32_t module_inst_part0,
|
||||
uint32_t module_inst_part1,
|
||||
uint32_t native_ptr_part0,
|
||||
uint32_t native_ptr_part1,
|
||||
uint32_t size);
|
||||
bool
|
||||
wasm_runtime_addr_app_to_native1(uint32_t module_inst_part0,
|
||||
uint32_t module_inst_part1,
|
||||
int32_t app_offset,
|
||||
uint64_t *p_native_ptr);
|
||||
|
||||
int32_t
|
||||
wasm_runtime_addr_native_to_app1(uint32_t module_inst_part0,
|
||||
uint32_t module_inst_part1,
|
||||
uint32_t native_ptr_part0,
|
||||
uint32_t native_ptr_part1);
|
||||
|
||||
/**
|
||||
* Get current WASM module instance of the current native thread
|
||||
*
|
||||
@ -39,8 +64,13 @@ extern "C" {
|
||||
* 32-bit and 64-bit. And if the native pointer is 64-bit, data loss
|
||||
* occurs after converting it to WASM i32 type.
|
||||
*/
|
||||
uint64_t
|
||||
wasm_runtime_get_current_module_inst();
|
||||
static inline uint64_t
|
||||
wasm_runtime_get_current_module_inst()
|
||||
{
|
||||
uint64_t module_inst;
|
||||
wasm_runtime_get_current_module_inst1(&module_inst);
|
||||
return module_inst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the app address, check whether it belongs to WASM module
|
||||
@ -52,9 +82,15 @@ wasm_runtime_get_current_module_inst();
|
||||
*
|
||||
* @return true if success, false otherwise.
|
||||
*/
|
||||
bool
|
||||
static inline bool
|
||||
wasm_runtime_validate_app_addr(uint64_t module_inst,
|
||||
int32_t app_offset, uint32_t size);
|
||||
int32_t app_offset, uint32_t size)
|
||||
{
|
||||
union { uint64_t val; uint32_t parts[2]; } u;
|
||||
u.val = module_inst;
|
||||
return wasm_runtime_validate_app_addr1(u.parts[0], u.parts[1],
|
||||
app_offset, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the native address, check whether it belongs to WASM module
|
||||
@ -67,9 +103,17 @@ wasm_runtime_validate_app_addr(uint64_t module_inst,
|
||||
*
|
||||
* @return true if success, false otherwise.
|
||||
*/
|
||||
bool
|
||||
static inline bool
|
||||
wasm_runtime_validate_native_addr(uint64_t module_inst,
|
||||
uint64_t native_ptr, uint32_t size);
|
||||
uint64_t native_ptr, uint32_t size)
|
||||
{
|
||||
union { uint64_t val; uint32_t parts[2]; } u1, u2;
|
||||
u1.val = module_inst;
|
||||
u2.val = native_ptr;
|
||||
return wasm_runtime_validate_native_addr1(u1.parts[0], u1.parts[1],
|
||||
u2.parts[0], u2.parts[1],
|
||||
size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert app address(relative address) to native address(absolute address)
|
||||
@ -79,9 +123,18 @@ wasm_runtime_validate_native_addr(uint64_t module_inst,
|
||||
*
|
||||
* @return the native address converted
|
||||
*/
|
||||
uint64_t
|
||||
static inline uint64_t
|
||||
wasm_runtime_addr_app_to_native(uint64_t module_inst,
|
||||
int32_t app_offset);
|
||||
int32_t app_offset)
|
||||
{
|
||||
union { uint64_t val; uint32_t parts[2]; } u;
|
||||
uint64_t native_ptr;
|
||||
u.val = module_inst;
|
||||
if (!wasm_runtime_addr_app_to_native1(u.parts[0], u.parts[1],
|
||||
app_offset, &native_ptr))
|
||||
return 0;
|
||||
return native_ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert native address(absolute address) to app address(relative address)
|
||||
@ -91,12 +144,19 @@ wasm_runtime_addr_app_to_native(uint64_t module_inst,
|
||||
*
|
||||
* @return the app address converted
|
||||
*/
|
||||
int32_t
|
||||
static inline int32_t
|
||||
wasm_runtime_addr_native_to_app(uint64_t module_inst,
|
||||
uint64_t native_ptr);
|
||||
uint64_t native_ptr)
|
||||
{
|
||||
union { uint64_t val; uint32_t parts[2]; } u1, u2;
|
||||
u1.val = module_inst;
|
||||
u2.val = native_ptr;
|
||||
return wasm_runtime_addr_native_to_app1(u1.parts[0], u1.parts[1],
|
||||
u2.parts[0], u2.parts[1]);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _WASM_EXPORT_H */
|
||||
#endif /* end of _WASM_EXPORT_API_H */
|
||||
|
||||
Reference in New Issue
Block a user