Add parameter module inst for native wrapper functions (#117)

And add asm code of em64/arm/mips version to call native wrapper functions;
Fix some issues of calling wrapper functions;
This commit is contained in:
wenyongh
2019-09-10 10:23:46 +08:00
committed by GitHub
parent 2294f52e3a
commit 26149021ff
58 changed files with 1287 additions and 494 deletions

View File

@ -16,23 +16,28 @@
#ifndef CONNECTION_API_H_
#define CONNECTION_API_H_
#include "bh_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
uint32 wasm_open_connection(int32 name_offset, int32 args_offset, uint32 len);
uint32
wasm_open_connection(const char *name, char *args_buf, uint32 args_buf_len);
void wasm_close_connection(uint32 handle);
void
wasm_close_connection(uint32 handle);
int wasm_send_on_connection(uint32 handle, int32 data_offset, uint32 len);
int
wasm_send_on_connection(uint32 handle, const char *data, uint32 data_len);
bool wasm_config_connection(uint32 handle, int32 cfg_offset, uint32 len);
bool
wasm_config_connection(uint32 handle, const char *cfg_buf, uint32 cfg_buf_len);
#ifdef __cplusplus
}
#endif
#endif /* CONNECTION_API_H_ */
#endif /* end of CONNECTION_API_H_ */

View File

@ -14,19 +14,29 @@
* limitations under the License.
*/
#ifndef GUI_API_H_
#define GUI_API_H_
#ifndef _GUI_API_H_
#define _GUI_API_H_
#include "bh_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
void wasm_obj_native_call(int32 func_id, uint32 argv_offset, uint32 argc);
void wasm_btn_native_call(int32 func_id, uint32 argv_offset, uint32 argc);
void wasm_label_native_call(int32 func_id, uint32 argv_offset, uint32 argc);
void wasm_cb_native_call(int32 func_id, uint32 argv_offset, uint32 argc);
void wasm_list_native_call(int32 func_id, uint32 argv_offset, uint32 argc);
void
wasm_obj_native_call(int32 func_id, uint32 *argv, uint32 argc);
void
wasm_btn_native_call(int32 func_id, uint32 *argv, uint32 argc);
void
wasm_label_native_call(int32 func_id, uint32 *argv, uint32 argc);
void
wasm_cb_native_call(int32 func_id, uint32 *argv, uint32 argc);
void
wasm_list_native_call(int32 func_id, uint32 *argv, uint32 argc);
#ifdef __cplusplus
@ -34,4 +44,4 @@ void wasm_list_native_call(int32 func_id, uint32 argv_offset, uint32 argc);
#endif
#endif /* GUI_API_H_ */
#endif /* end of _GUI_API_H_ */

View File

@ -14,12 +14,13 @@
* limitations under the License.
*/
#ifndef DEPS_SSG_MICRO_RUNTIME_WASM_POC_APP_LIBS_NATIVE_INTERFACE_NATIVE_INTERFACE_H_
#define DEPS_SSG_MICRO_RUNTIME_WASM_POC_APP_LIBS_NATIVE_INTERFACE_NATIVE_INTERFACE_H_
#ifndef _NATIVE_INTERFACE_H_
#define _NATIVE_INTERFACE_H_
// note: the bh_plaform.h is the only head file separately
// implemented by both [app] and [native] worlds
/* Note: the bh_plaform.h is the only head file separately
implemented by both [app] and [native] worlds */
#include "bh_platform.h"
#include "wasm_export.h"
#define get_module_inst() \
wasm_runtime_get_current_module_inst()
@ -39,52 +40,102 @@
#define module_free(offset) \
wasm_runtime_module_free(module_inst, offset)
char *wa_strdup(const char *);
bool
wasm_response_send(int32 buffer_offset, int size);
void wasm_register_resource(int32 url_offset);
void wasm_post_request(int32 buffer_offset, int size);
void wasm_sub_event(int32 url_offset);
/*char *wa_strdup(const char *);*/
/*
* ************* sensor interfaces *************
* request/response interfaces
*/
bool
wasm_sensor_config(uint32 sensor, int interval, int bit_cfg, int delay);
uint32
wasm_sensor_open(int32 name_offset, int instance);
bool
wasm_sensor_config_with_attr_container(uint32 sensor, int32 buffer_offset,
int len);
bool
wasm_sensor_close(uint32 sensor);
wasm_response_send(wasm_module_inst_t module_inst,
int32 buffer_offset, int size);
void
wasm_register_resource(wasm_module_inst_t module_inst,
int32 url_offset);
void
wasm_post_request(wasm_module_inst_t module_inst,
int32 buffer_offset, int size);
void
wasm_sub_event(wasm_module_inst_t module_inst,
int32 url_offset);
/*
* *** timer interface ***
* sensor interfaces
*/
bool
wasm_sensor_config(wasm_module_inst_t module_inst,
uint32 sensor, int interval, int bit_cfg, int delay);
uint32
wasm_sensor_open(wasm_module_inst_t module_inst,
int32 name_offset, int instance);
bool
wasm_sensor_config_with_attr_container(wasm_module_inst_t module_inst,
uint32 sensor,
int32 buffer_offset, int len);
bool
wasm_sensor_close(wasm_module_inst_t module_inst,
uint32 sensor);
/*
* timer interfaces
*/
typedef unsigned int timer_id_t;
timer_id_t wasm_create_timer(int interval, bool is_period, bool auto_start);
void wasm_timer_destory(timer_id_t timer_id);
void wasm_timer_cancel(timer_id_t timer_id);
void wasm_timer_restart(timer_id_t timer_id, int interval);
uint32 wasm_get_sys_tick_ms(void);
timer_id_t
wasm_create_timer(wasm_module_inst_t module_inst,
int interval, bool is_period, bool auto_start);
void
wasm_timer_destory(wasm_module_inst_t module_inst, timer_id_t timer_id);
void
wasm_timer_cancel(wasm_module_inst_t module_inst, timer_id_t timer_id);
void
wasm_timer_restart(wasm_module_inst_t module_inst,
timer_id_t timer_id, int interval);
uint32
wasm_get_sys_tick_ms(wasm_module_inst_t module_inst);
/*
* *** connection interface ***
* connection interfaces
*/
uint32 wasm_open_connection(int32 name_offset, int32 args_offset, uint32 len);
void wasm_close_connection(uint32 handle);
int wasm_send_on_connection(uint32 handle, int32 data_offset, uint32 len);
bool wasm_config_connection(uint32 handle, int32 cfg_offset, uint32 len);
#include "gui_api.h"
uint32
wasm_open_connection(wasm_module_inst_t module_inst,
int32 name_offset, int32 args_offset, uint32 len);
void
wasm_close_connection(wasm_module_inst_t module_inst,
uint32 handle);
int
wasm_send_on_connection(wasm_module_inst_t module_inst,
uint32 handle, int32 data_offset, uint32 len);
bool
wasm_config_connection(wasm_module_inst_t module_inst,
uint32 handle, int32 cfg_offset, uint32 len);
/**
* gui interfaces
*/
void
wasm_obj_native_call(wasm_module_inst_t module_inst,
int32 func_id, uint32 argv_offset, uint32 argc);
void
wasm_btn_native_call(wasm_module_inst_t module_inst,
int32 func_id, uint32 argv_offset, uint32 argc);
void
wasm_label_native_call(wasm_module_inst_t module_inst,
int32 func_id, uint32 argv_offset, uint32 argc);
void
wasm_cb_native_call(wasm_module_inst_t module_inst,
int32 func_id, uint32 argv_offset, uint32 argc);
void
wasm_list_native_call(wasm_module_inst_t module_inst,
int32 func_id, uint32 argv_offset, uint32 argc);
#endif /* end of _NATIVE_INTERFACE_H */
#endif /* DEPS_SSG_MICRO_RUNTIME_WASM_PO
C_APP_LIBS_NATIVE_INTERFACE_NATIVE_INTERFACE_H_ */

View File

@ -1,6 +1,6 @@
Attention:
=======
Only add files are shared by both wasm application and native runtime into this directory!
Only add files which are shared by both wasm application and native runtime into this directory!
The c files are both compiled into the the WASM APP and native runtime.

View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _REQ_RESP_API_H_
#define _REQ_RESP_API_H_
#include "bh_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
bool
wasm_response_send(const char *buf, int size);
void
wasm_register_resource(const char *url);
void
wasm_post_request(const char *buf, int size);
void
wasm_sub_event(const char *url);
#ifdef __cplusplus
}
#endif
#endif /* end of _REQ_RESP_API_H_ */

View File

@ -19,7 +19,6 @@
#include <stdbool.h>
#include <stdio.h>
#include "native_interface.h"
#include "shared_utils.h"
/* Serialization of request and response message

View File

@ -14,8 +14,9 @@
* limitations under the License.
*/
#ifndef DEPS_IWASM_APP_LIBS_NATIVE_INTERFACE_SENSOR_API_H_
#define DEPS_IWASM_APP_LIBS_NATIVE_INTERFACE_SENSOR_API_H_
#ifndef _SENSOR_API_H_
#define _SENSOR_API_H_
#include "bh_platform.h"
#ifdef __cplusplus
@ -29,7 +30,7 @@ bool
wasm_sensor_config(uint32 sensor, int interval, int bit_cfg, int delay);
bool
wasm_sensor_config_with_attr_container(uint32 sensor, char * buffer, int len);
wasm_sensor_config_with_attr_container(uint32 sensor, char *buffer, int len);
bool
wasm_sensor_close(uint32 sensor);
@ -38,4 +39,5 @@ wasm_sensor_close(uint32 sensor);
}
#endif
#endif /* DEPS_IWASM_APP_LIBS_NATIVE_INTERFACE_SENSOR_API_H_ */
#endif /* end of _SENSOR_API_H_ */

View File

@ -14,10 +14,10 @@
* limitations under the License.
*/
#ifndef DEPS_SSG_MICRO_RUNTIME_WASM_POC_APP_LIBS_NATIVE_INTERFACE_SHARED_UTILS_H_
#define DEPS_SSG_MICRO_RUNTIME_WASM_POC_APP_LIBS_NATIVE_INTERFACE_SHARED_UTILS_H_
#ifndef _SHARED_UTILS_H_
#define _SHARED_UTILS_H_
#include "native_interface.h"
#include "bh_platform.h"
#ifdef __cplusplus
extern "C" {
@ -71,16 +71,27 @@ typedef struct response {
unsigned long reciever;
} response_t;
int check_url_start(const char* url, int url_len, const char * leading_str);
bool match_url(char * pattern, char * matched);
char * find_key_value(char * buffer, int buffer_len, char * key, char * value,
int value_len, char delimiter);
int
check_url_start(const char* url, int url_len, const char * leading_str);
request_t *clone_request(request_t *request);
void request_cleaner(request_t *request);
bool
match_url(char * pattern, char * matched);
response_t * clone_response(response_t * response);
void response_cleaner(response_t * response);
char *
find_key_value(char * buffer, int buffer_len, char * key, char * value,
int value_len, char delimiter);
request_t *
clone_request(request_t *request);
void
request_cleaner(request_t *request);
response_t *
clone_response(response_t * response);
void
response_cleaner(response_t * response);
/**
* @brief Set fields of response.
@ -95,8 +106,9 @@ void response_cleaner(response_t * response);
*
* @warning the response pointer MUST NOT be NULL
*/
response_t * set_response(response_t * response, int status, int fmt,
const char *payload, int payload_len);
response_t *
set_response(response_t * response, int status, int fmt,
const char *payload, int payload_len);
/**
* @brief Make a response for a request.
@ -108,8 +120,8 @@ response_t * set_response(response_t * response, int status, int fmt,
*
* @warning the request and response pointers MUST NOT be NULL
*/
response_t * make_response_for_request(request_t * request,
response_t * response);
response_t *
make_response_for_request(request_t * request, response_t * response);
/**
* @brief Initialize a request.
@ -125,14 +137,24 @@ response_t * make_response_for_request(request_t * request,
*
* @warning the request pointer MUST NOT be NULL
*/
request_t * init_request(request_t * request, char *url, int action, int fmt,
void *payload, int payload_len);
request_t *
init_request(request_t * request, char *url, int action, int fmt,
void *payload, int payload_len);
char * pack_request(request_t *request, int * size);
request_t * unpack_request(char * packet, int size, request_t * request);
char * pack_response(response_t *response, int * size);
response_t * unpack_response(char * packet, int size, response_t * response);
void free_req_resp_packet(char * packet);
char *
pack_request(request_t *request, int * size);
request_t *
unpack_request(char * packet, int size, request_t * request);
char *
pack_response(response_t *response, int * size);
response_t *
unpack_response(char * packet, int size, response_t * response);
void
free_req_resp_packet(char * packet);
#include "wgl_shared_utils.h"
@ -140,4 +162,4 @@ void free_req_resp_packet(char * packet);
}
#endif
#endif /* DEPS_SSG_MICRO_RUNTIME_WASM_POC_APP_LIBS_NATIVE_INTERFACE_SHARED_UTILS_H_ */
#endif /* end of _SHARED_UTILS_H_ */

View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _TIMER_API_H_
#define _TIMER_API_H_
#include "bh_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned int timer_id_t;
timer_id_t
wasm_create_timer(int interval, bool is_period, bool auto_start);
void
wasm_timer_destory(timer_id_t timer_id);
void
wasm_timer_cancel(timer_id_t timer_id);
void
wasm_timer_restart(timer_id_t timer_id, int interval);
uint32
wasm_get_sys_tick_ms(void);
#ifdef __cplusplus
}
#endif
#endif /* end of _TIMER_API_H_ */

View File

@ -0,0 +1,102 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _WASM_EXPORT_H
#define _WASM_EXPORT_H
#include <inttypes.h>
#include <stdbool.h>
/**
* API exported to WASM application
*/
#ifdef __cplusplus
extern "C" {
#endif
/**
* Get current WASM module instance of the current native thread
*
* @return current WASM module instance of the current native thread, 0
* if not found
* Note: the return type is uint64_t but not pointer type, because that
* the we only supports WASM-32, in which the pointer type is
* compiled to WASM i32 type, but the pointer type in native can be
* 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();
/**
* Validate the app address, check whether it belongs to WASM module
* instance's address space, or in its heap space or memory space.
*
* @param module_inst the WASM module instance
* @param app_offset the app address to validate, which is a relative address
* @param size the size bytes of the app address
*
* @return true if success, false otherwise.
*/
bool
wasm_runtime_validate_app_addr(uint64_t module_inst,
int32_t app_offset, uint32_t size);
/**
* Validate the native address, check whether it belongs to WASM module
* instance's address space, or in its heap space or memory space.
*
* @param module_inst the WASM module instance
* @param native_ptr the native address to validate, which is an absolute
* address
* @param size the size bytes of the app address
*
* @return true if success, false otherwise.
*/
bool
wasm_runtime_validate_native_addr(uint64_t module_inst,
uint64_t native_ptr, uint32_t size);
/**
* Convert app address(relative address) to native address(absolute address)
*
* @param module_inst the WASM module instance
* @param app_offset the app adress
*
* @return the native address converted
*/
uint64_t
wasm_runtime_addr_app_to_native(uint64_t module_inst,
int32_t app_offset);
/**
* Convert native address(absolute address) to app address(relative address)
*
* @param module_inst the WASM module instance
* @param native_ptr the native address
*
* @return the app address converted
*/
int32_t
wasm_runtime_addr_native_to_app(uint64_t module_inst,
uint64_t native_ptr);
#ifdef __cplusplus
}
#endif
#endif /* end of _WASM_EXPORT_H */