Fix app manager fail to install large app file issue (#555)

Remove the limit of app file size no larger than 1 MB, fix possible memory leak issues when fail to install app file, change message size of aee_host_msg_callback() from uint16 type to uint32 type to fix possible integer overflow issue, and fix some coding style issues of app manager.

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
This commit is contained in:
Wenyong Huang
2021-03-03 06:19:24 -06:00
committed by GitHub
parent fe76ce3b68
commit 54e82ec439
14 changed files with 293 additions and 207 deletions

View File

@ -32,8 +32,8 @@ void app_manager_post_applets_update_event()
return;
if (!(attr_cont = attr_container_create("All Applets"))) {
app_manager_printf(
"Post applets update event failed: allocate memory failed.");
app_manager_printf("Post applets update event failed: "
"allocate memory failed.");
return;
}
@ -46,8 +46,8 @@ void app_manager_post_applets_update_event()
}
if (!(attr_container_set_int(&attr_cont, "num", num))) {
app_manager_printf(
"Post applets update event failed: set attr container key failed.");
app_manager_printf("Post applets update event failed: "
"set attr container key failed.");
goto fail;
}
@ -57,14 +57,14 @@ void app_manager_post_applets_update_event()
i++;
snprintf(buf, sizeof(buf), "%s%d", "applet", i);
if (!(attr_container_set_string(&attr_cont, buf, m_data->module_name))) {
app_manager_printf(
"Post applets update event failed: set attr applet name key failed.");
app_manager_printf("Post applets update event failed: "
"set attr applet name key failed.");
goto fail;
}
snprintf(buf, sizeof(buf), "%s%d", "heap", i);
if (!(attr_container_set_int(&attr_cont, buf, m_data->heap_size))) {
app_manager_printf(
"Post applets update event failed: set attr heap key failed.");
app_manager_printf("Post applets update event failed: "
"set attr heap key failed.");
goto fail;
}
m_data = m_data->next;
@ -114,7 +114,7 @@ static bool app_manager_query_applets(request_t *msg, const char *name)
attr_cont = attr_container_create("Applets Info");
if (!attr_cont) {
SEND_ERR_RESPONSE(msg->mid,
"Query Applets failed: allocate memory failed.");
"Query Applets failed: allocate memory failed.");
return false;
}
@ -128,7 +128,7 @@ static bool app_manager_query_applets(request_t *msg, const char *name)
if (name == NULL && !(attr_container_set_int(&attr_cont, "num", num))) {
SEND_ERR_RESPONSE(msg->mid,
"Query Applets failed: set attr container key failed.");
"Query Applets failed: set attr container key failed.");
goto fail;
}
@ -142,26 +142,31 @@ static bool app_manager_query_applets(request_t *msg, const char *name)
if (!(attr_container_set_string(&attr_cont, buf,
m_data->module_name))) {
SEND_ERR_RESPONSE(msg->mid,
"Query Applets failed: set attr container key failed.");
"Query Applets failed: "
"set attr container key failed.");
goto fail;
}
snprintf(buf, sizeof(buf), "%s%d", "heap", i);
if (!(attr_container_set_int(&attr_cont, buf, m_data->heap_size))) {
SEND_ERR_RESPONSE(msg->mid,
"Query Applets failed: set attr container heap key failed.");
"Query Applets failed: "
"set attr container heap key failed.");
goto fail;
}
} else if (!strcmp(name, m_data->module_name)) {
}
else if (!strcmp(name, m_data->module_name)) {
found = true;
if (!(attr_container_set_string(&attr_cont, "name",
m_data->module_name))) {
SEND_ERR_RESPONSE(msg->mid,
"Query Applet failed: set attr container key failed.");
"Query Applet failed: "
"set attr container key failed.");
goto fail;
}
if (!(attr_container_set_int(&attr_cont, "heap", m_data->heap_size))) {
SEND_ERR_RESPONSE(msg->mid,
"Query Applet failed: set attr container heap key failed.");
"Query Applet failed: "
"set attr container heap key failed.");
goto fail;
}
}
@ -266,7 +271,7 @@ static void app_manager_queue_callback(void *message, void *arg)
goto fail;
}
if (g_module_interfaces[module_type]
&& g_module_interfaces[module_type]->module_install) {
&& g_module_interfaces[module_type]->module_install) {
if (!g_module_interfaces[module_type]->module_install(request))
goto fail;
}
@ -276,14 +281,13 @@ static void app_manager_queue_callback(void *message, void *arg)
module_type = get_module_type(request->url + offset);
if (module_type == -1) {
SEND_ERR_RESPONSE(mid,
"Uninstall Applet failed: invalid module type.");
"Uninstall Applet failed: invalid module type.");
goto fail;
}
if (g_module_interfaces[module_type]
&& g_module_interfaces[module_type]->module_uninstall) {
if (!g_module_interfaces[module_type]->module_uninstall(
request))
if (!g_module_interfaces[module_type]->module_uninstall(request))
goto fail;
}
}
@ -292,18 +296,19 @@ static void app_manager_queue_callback(void *message, void *arg)
char name[APP_NAME_MAX_LEN] = { 0 };
char *properties = request->url + offset;
find_key_value(properties, strlen(properties), "name", name,
sizeof(name) - 1, '&');
sizeof(name) - 1, '&');
if (strlen(name) > 0)
app_manager_query_applets(request, name);
else
app_manager_query_applets(request, NULL);
} else {
}
else {
SEND_ERR_RESPONSE(mid, "Invalid request of applet: invalid action");
}
}
/* Event Register/Unregister */
else if ((offset = check_url_start(request->url, strlen(request->url),
"/event/")) > 0) {
"/event/")) > 0) {
char url_buf[256] = { 0 };
strncpy(url_buf, request->url + offset, sizeof(url_buf) - 1);
@ -313,11 +318,12 @@ static void app_manager_queue_callback(void *message, void *arg)
goto fail;
}
send_error_response_to_host(mid, CONTENT_2_05, NULL); /* OK */
} else {
}
else {
int i;
for (i = 0; i < Module_Max; i++) {
if (g_module_interfaces[i]
&& g_module_interfaces[i]->module_handle_host_url) {
&& g_module_interfaces[i]->module_handle_host_url) {
if (g_module_interfaces[i]->module_handle_host_url(request))
break;
}
@ -325,10 +331,8 @@ static void app_manager_queue_callback(void *message, void *arg)
}
fail:
fail:
return;
}
static void module_interfaces_init()
@ -360,7 +364,7 @@ void app_manager_startup(host_interface *interface)
am_register_resource("/app/", targeted_app_request_handler, ID_APP_MGR);
/*/app/ and /event/ are both processed by applet_mgt_reqeust_handler*/
/* /app/ and /event/ are both processed by applet_mgt_reqeust_handler */
am_register_resource("/applet", applet_mgt_reqeust_handler, ID_APP_MGR);
am_register_resource("/event/", applet_mgt_reqeust_handler, ID_APP_MGR);
@ -369,6 +373,12 @@ void app_manager_startup(host_interface *interface)
/* Enter loop run */
bh_queue_enter_loop_run(g_app_mgr_queue, app_manager_queue_callback, NULL);
/* Destroy registered resources */
am_cleanup_registeration(ID_APP_MGR);
/* Destroy watchdog */
watchdog_destroy();
fail2:
module_data_list_destroy();

View File

@ -13,11 +13,19 @@
static host_interface host_commu;
/* IMRTLink Two leading bytes */
static unsigned char leadings[] = { (unsigned char) 0x12, (unsigned char) 0x34 };
static unsigned char leadings[] = {
(unsigned char)0x12,
(unsigned char)0x34
};
/* IMRTLink Receiving Phase */
typedef enum recv_phase_t {
Phase_Non_Start, Phase_Leading, Phase_Type, Phase_Size, Phase_Payload
Phase_Non_Start,
Phase_Leading,
Phase_Type,
Phase_Size,
Phase_Payload,
Phase_Ignoring
} recv_phase_t;
/* IMRTLink Receive Context */
@ -74,7 +82,8 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
}
return 0;
} else if (ctx->phase == Phase_Leading) {
}
else if (ctx->phase == Phase_Leading) {
if (ch == leadings[1]) {
if (enable_log)
app_manager_printf("##On byte arrive: got leading 1\n");
@ -83,12 +92,14 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
ctx->phase = Phase_Non_Start;
return 0;
} else if (ctx->phase == Phase_Type) {
}
else if (ctx->phase == Phase_Type) {
if (ctx->size_in_phase++ == 0) {
if (enable_log)
app_manager_printf("##On byte arrive: got type 0\n");
ctx->message.message_type = ch;
} else {
}
else {
if (enable_log)
app_manager_printf("##On byte arrive: got type 1\n");
ctx->message.message_type |= (ch << 8);
@ -98,12 +109,13 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
}
return 0;
} else if (ctx->phase == Phase_Size) {
}
else if (ctx->phase == Phase_Size) {
unsigned char *p = (unsigned char *) &ctx->message.payload_size;
if (enable_log)
app_manager_printf("##On byte arrive: got payload_size, byte %d\n",
ctx->size_in_phase);
ctx->size_in_phase);
p[ctx->size_in_phase++] = ch;
if (ctx->size_in_phase == sizeof(ctx->message.payload_size)) {
@ -112,7 +124,7 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
if (enable_log)
app_manager_printf("##On byte arrive: payload_size: %d\n",
ctx->message.payload_size);
ctx->message.payload_size);
if (ctx->message.payload) {
APP_MGR_FREE(ctx->message.payload);
ctx->message.payload = NULL;
@ -122,16 +134,11 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
if (ctx->message.payload_size == 0) {
ctx->phase = Phase_Non_Start;
if (enable_log)
app_manager_printf(
"##On byte arrive: receive end, payload_size is 0.\n");
app_manager_printf("##On byte arrive: receive end, "
"payload_size is 0.\n");
return 1;
}
if (ctx->message.payload_size > 1024 * 1024) {
ctx->phase = Phase_Non_Start;
return 0;
}
if (ctx->message.message_type != INSTALL_WASM_APP) {
ctx->message.payload =
(char *) APP_MGR_MALLOC(ctx->message.payload_size);
@ -146,7 +153,8 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
}
return 0;
} else if (ctx->phase == Phase_Payload) {
}
else if (ctx->phase == Phase_Payload) {
if (ctx->message.message_type == INSTALL_WASM_APP) {
int received_size;
module_on_install_request_byte_arrive_func module_on_install =
@ -162,36 +170,53 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
ctx->phase = Phase_Non_Start;
return 1;
}
} else {
}
else {
/* receive or handle fail */
ctx->phase = Phase_Non_Start;
ctx->size_in_phase = 0;
if (ctx->size_in_phase < ctx->message.payload_size) {
ctx->phase = Phase_Ignoring;
}
else {
ctx->phase = Phase_Non_Start;
ctx->size_in_phase = 0;
}
return 0;
}
return 0;
} else {
}
else {
ctx->phase = Phase_Non_Start;
ctx->size_in_phase = 0;
return 0;
}
} else {
}
else {
ctx->message.payload[ctx->size_in_phase++] = ch;
if (ctx->size_in_phase == ctx->message.payload_size) {
ctx->phase = Phase_Non_Start;
if (enable_log)
app_manager_printf("##On byte arrive: receive end, payload_size is %d.\n",
app_manager_printf("##On byte arrive: receive end, "
"payload_size is %d.\n",
ctx->message.payload_size);
return 1;
}
return 0;
}
}
else if (ctx->phase == Phase_Ignoring) {
ctx->size_in_phase++;
if (ctx->size_in_phase == ctx->message.payload_size) {
if (ctx->message.payload)
APP_MGR_FREE(ctx->message.payload);
memset(ctx, 0, sizeof(*ctx));
return 0;
}
}
return 0;
}
int aee_host_msg_callback(void *msg, uint16_t msg_len)
int aee_host_msg_callback(void *msg, uint32_t msg_len)
{
unsigned char *p = msg, *p_end = p + msg_len;
@ -259,8 +284,8 @@ int app_manager_host_send_msg(int msg_type, const char *buf, int size)
bh_memcpy_s(header, 2, leadings, 2);
/* message type */
// todo: check if use network byte order!!!
*((uint16*) (header + 2)) = htons(msg_type);
/* TODO: check if use network byte order!!! */
*((uint16*)(header + 2)) = htons(msg_type);
/* payload length */
if (is_little_endian())
@ -279,7 +304,8 @@ int app_manager_host_send_msg(int msg_type, const char *buf, int size)
app_manager_printf("sent %d bytes to host\n", n);
return n;
} else {
}
else {
app_manager_printf("no send api provided\n");
}
return 0;

View File

@ -504,18 +504,20 @@ cleanup_app_resource(module_data *m_data)
/* Destroy remain sections (i.e. data segment section for bytecode file
* or text section of aot file) from app file's section list. */
if (is_bytecode)
if (is_bytecode) {
#if WASM_ENABLE_INTERP != 0 || WASM_ENABLE_JIT != 0
destroy_all_wasm_sections((wasm_section_list_t)(wasm_app_data->sections));
#else
bh_assert(0);
#endif
else
}
else {
#if WASM_ENABLE_AOT != 0
destroy_all_aot_sections((aot_section_list_t)(wasm_app_data->sections));
#else
bh_assert(0);
#endif
}
if (wasm_app_data->wasm_module)
wasm_runtime_unload(wasm_app_data->wasm_module);
@ -568,7 +570,7 @@ wasm_app_module_install(request_t * msg)
wasm_app_file_t *wasm_app_file;
wasm_data *wasm_app_data;
package_type_t package_type;
module_data *m_data;
module_data *m_data = NULL;
wasm_module_t module = NULL;
wasm_module_inst_t inst = NULL;
wasm_exec_env_t exec_env = NULL;
@ -589,23 +591,30 @@ wasm_app_module_install(request_t * msg)
return false;
}
/* Judge the app type is AOTed or not */
package_type = get_package_type((uint8 *)msg->payload, msg->payload_len);
wasm_app_file = (wasm_app_file_t *)msg->payload;
/* Check app name */
properties_offset = check_url_start(msg->url, strlen(msg->url), "/applet");
bh_assert(properties_offset > 0);
if (properties_offset <= 0)
return false;
if (properties_offset <= 0) {
SEND_ERR_RESPONSE(msg->mid, "Install WASM app failed: invalid app name.");
goto fail;
}
properties = msg->url + properties_offset;
find_key_value(properties, strlen(properties), "name", m_name,
sizeof(m_name) - 1, '&');
if (strlen(m_name) == 0) {
SEND_ERR_RESPONSE(msg->mid, "Install WASM app failed: invalid app name.");
return false;
goto fail;
}
if (app_manager_lookup_module_data(m_name)) {
SEND_ERR_RESPONSE(msg->mid, "Install WASM app failed: app already installed.");
return false;
goto fail;
}
/* Parse heap size */
@ -620,9 +629,6 @@ wasm_app_module_install(request_t * msg)
heap_size = APP_HEAP_SIZE_MAX;
}
/* Judge the app type is AOTed or not */
package_type = get_package_type((uint8 *) msg->payload, msg->payload_len);
/* Load WASM file and instantiate*/
switch (package_type) {
#if WASM_ENABLE_AOT != 0
@ -639,8 +645,6 @@ wasm_app_module_install(request_t * msg)
AOT_SECTION_TYPE_SIGANATURE
};
wasm_app_file = (wasm_app_file_t *) msg->payload;
bh_assert(wasm_app_file);
aot_file = &wasm_app_file->u.aot;
/* Load AOT module from sections */
@ -649,9 +653,7 @@ wasm_app_module_install(request_t * msg)
if (!module) {
SEND_ERR_RESPONSE(msg->mid,
"Install WASM app failed: load WASM file failed.");
app_manager_printf("error: %s\n", err);
destroy_all_aot_sections(aot_file->sections);
return false;
goto fail;
}
/* Destroy useless sections from list after load */
destroy_part_aot_sections(&aot_file->sections,
@ -663,9 +665,7 @@ wasm_app_module_install(request_t * msg)
wasi_dir_buf, sizeof(wasi_dir_buf))) {
SEND_ERR_RESPONSE(msg->mid,
"Install WASM app failed: prepare wasi env failed.");
wasm_runtime_unload(module);
destroy_all_aot_sections(aot_file->sections);
return false;
goto fail;
}
wasm_runtime_set_wasi_args(module,
wasi_dir_list, 1,
@ -679,10 +679,7 @@ wasm_app_module_install(request_t * msg)
if (!inst) {
SEND_ERR_RESPONSE(msg->mid,
"Install WASM app failed: instantiate wasm runtime failed.");
app_manager_printf("error: %s\n", err);
wasm_runtime_unload(module);
destroy_all_aot_sections(aot_file->sections);
return false;
goto fail;
}
break;
}
@ -712,8 +709,6 @@ wasm_app_module_install(request_t * msg)
/* Sections to be released after instantiating */
uint8 sections2[] = { SECTION_TYPE_DATA };
wasm_app_file = (wasm_app_file_t *) msg->payload;
bh_assert(wasm_app_file);
bytecode_file = &wasm_app_file->u.bytecode;
/* Load wasm module from sections */
@ -722,9 +717,7 @@ wasm_app_module_install(request_t * msg)
if (!module) {
SEND_ERR_RESPONSE(msg->mid,
"Install WASM app failed: load WASM file failed.");
app_manager_printf("error: %s\n", err);
destroy_all_wasm_sections(bytecode_file->sections);
return false;
goto fail;
}
/* Destroy useless sections from list after load */
@ -737,9 +730,7 @@ wasm_app_module_install(request_t * msg)
wasi_dir_buf, sizeof(wasi_dir_buf))) {
SEND_ERR_RESPONSE(msg->mid,
"Install WASM app failed: prepare wasi env failed.");
wasm_runtime_unload(module);
destroy_all_wasm_sections(bytecode_file->sections);
return false;
goto fail;
}
wasm_runtime_set_wasi_args(module,
wasi_dir_list, 1,
@ -753,10 +744,7 @@ wasm_app_module_install(request_t * msg)
if (!inst) {
SEND_ERR_RESPONSE(msg->mid,
"Install WASM app failed: instantiate wasm runtime failed.");
app_manager_printf("error: %s\n", err);
wasm_runtime_unload(module);
destroy_all_wasm_sections(bytecode_file->sections);
return false;
goto fail;
}
/* Destroy useless sections from list after instantiate */
@ -769,7 +757,7 @@ wasm_app_module_install(request_t * msg)
default:
SEND_ERR_RESPONSE(msg->mid,
"Install WASM app failed: invalid wasm package type.");
return false;
goto fail;
}
/* Create module data including the wasm_app_data as its internal_data*/
@ -875,8 +863,13 @@ wasm_app_module_install(request_t * msg)
fail:
if (m_data)
release_module(m_data);
wasm_runtime_deinstantiate(inst);
wasm_runtime_unload(module);
if (inst)
wasm_runtime_deinstantiate(inst);
if (module)
wasm_runtime_unload(module);
if (exec_env)
wasm_runtime_destroy_exec_env(exec_env);
@ -969,7 +962,7 @@ wasm_app_module_uninstall(request_t *msg)
static bool
wasm_app_module_handle_host_url(void *queue_msg)
{
//todo: implement in future
/* TODO: implement in future */
app_manager_printf("App handles host url address %d\n",
(int)(uintptr_t)queue_msg);
return false;
@ -985,7 +978,7 @@ wasm_app_module_get_module_data(void *inst)
static void
wasm_app_module_watchdog_kill(module_data *m_data)
{
//todo: implement in future
/* TODO: implement in future */
app_manager_printf("Watchdog kills app: %s\n", m_data->module_name);
return;
}
@ -997,7 +990,7 @@ wasm_register_msg_callback(int message_type,
int i;
int freeslot = -1;
for (i = 0; i < Max_Msg_Callback; i++) {
// replace handler for the same event registered
/* replace handler for the same event registered */
if (g_msg_type[i] == message_type)
break;
@ -1055,6 +1048,7 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
int *received_size)
{
uint8 *p;
int magic;
package_type_t package_type = Package_Type_Unknown;
if (recv_ctx.phase == Phase_Req_Ver) {
@ -1102,6 +1096,9 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
APP_MGR_MALLOC(recv_ctx.message.request_url_len + 1);
if (NULL == recv_ctx.message.request_url) {
app_manager_printf("Allocate memory failed!\n");
SEND_ERR_RESPONSE(recv_ctx.message.request_mid,
"Install WASM app failed: "
"allocate memory failed.");
goto fail;
}
memset(recv_ctx.message.request_url, 0,
@ -1131,7 +1128,7 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
if (recv_ctx.size_in_phase ==
sizeof(recv_ctx.message.app_file_magic)) {
int magic = recv_ctx.message.app_file_magic;
magic = recv_ctx.message.app_file_magic;
package_type = get_package_type((uint8 *)&magic, sizeof(magic) + 1);
switch (package_type) {
#if WASM_ENABLE_INTERP != 0 || WASM_ENABLE_JIT != 0
@ -1152,7 +1149,8 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
#endif
default:
SEND_ERR_RESPONSE(recv_ctx.message.request_mid,
"Install WASM app failed: invalid file format.");
"Install WASM app failed: "
"invalid file format.");
goto fail;
}
}
@ -1166,6 +1164,8 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
p[recv_ctx.size_in_phase++] = ch;
else {
app_manager_printf("Invalid WASM version!\n");
SEND_ERR_RESPONSE(recv_ctx.message.request_mid,
"Install WASM app failed: invalid WASM version.");
goto fail;
}
@ -1185,8 +1185,12 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
#endif
if (section_type <= section_type_max) {
wasm_section_t *new_section;
if (!(new_section = (wasm_section_t *) APP_MGR_MALLOC(sizeof(wasm_section_t)))) {
if (!(new_section = (wasm_section_t *)
APP_MGR_MALLOC(sizeof(wasm_section_t)))) {
app_manager_printf("Allocate memory failed!\n");
SEND_ERR_RESPONSE(recv_ctx.message.request_mid,
"Install WASM app failed: "
"allocate memory failed.");
goto fail;
}
memset(new_section, 0, sizeof(wasm_section_t));
@ -1209,7 +1213,13 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
return true;
}
else {
char error_buf[128];
app_manager_printf("Invalid wasm section type: %d\n", section_type);
snprintf(error_buf, sizeof(error_buf),
"Install WASM app failed: invalid wasm section type %d",
section_type);
SEND_ERR_RESPONSE(recv_ctx.message.request_mid, error_buf);
goto fail;
}
}
@ -1228,7 +1238,10 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
/* check leab128 overflow for uint32 value */
if (recv_ctx.size_in_phase >
(sizeof(section->section_body_size) * 8 + 7 - 1) / 7) {
app_manager_printf(" LEB overflow when parsing section size\n");
app_manager_printf("LEB overflow when parsing section size\n");
SEND_ERR_RESPONSE(recv_ctx.message.request_mid,
"Install WASM app failed: "
"LEB overflow when parsing section size");
goto fail;
}
@ -1236,6 +1249,8 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
/* leb128 encoded section size parsed done */
if (!(section->section_body = APP_MGR_MALLOC(section->section_body_size))) {
app_manager_printf("Allocate memory failed!\n");
SEND_ERR_RESPONSE(recv_ctx.message.request_mid,
"Install WASM app failed: allocate memory failed");
goto fail;
}
recv_ctx.phase = Phase_Wasm_Section_Content;
@ -1263,7 +1278,15 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
}
else {
app_manager_printf("Handle install message failed!\n");
goto fail;
SEND_ERR_RESPONSE(recv_ctx.message.request_mid,
"Install WASM app failed: "
"handle install message failed");
/**
* The sections were destroyed inside
* module_wasm_app_handle_install_msg(),
* no need to destroy again.
*/
return false;
}
}
else {
@ -1283,7 +1306,9 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
if (ch == wasm_aot_version[recv_ctx.size_in_phase])
p[recv_ctx.size_in_phase++] = ch;
else {
app_manager_printf("Invalid WASM AOT version!\n");
app_manager_printf("Invalid AOT version!\n");
SEND_ERR_RESPONSE(recv_ctx.message.request_mid,
"Install WASM app failed: invalid AOT version");
goto fail;
}
@ -1305,8 +1330,12 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
if (aot_file_cur_offset % 4)
return true;
if (!(cur_section = (aot_section_t *) APP_MGR_MALLOC(sizeof(aot_section_t)))) {
if (!(cur_section = (aot_section_t *)
APP_MGR_MALLOC(sizeof(aot_section_t)))) {
app_manager_printf("Allocate memory failed!\n");
SEND_ERR_RESPONSE(recv_ctx.message.request_mid,
"Install WASM app failed: "
"allocate memory failed");
goto fail;
}
memset(cur_section, 0, sizeof(aot_section_t));
@ -1336,8 +1365,14 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
recv_ctx.size_in_phase = 0;
}
else {
char error_buf[128];
app_manager_printf("Invalid AOT section id: %d\n",
cur_section->section_type);
snprintf(error_buf, sizeof(error_buf),
"Install WASM app failed: invalid AOT section id %d",
cur_section->section_type);
SEND_ERR_RESPONSE(recv_ctx.message.request_mid, error_buf);
goto fail;
}
}
@ -1375,6 +1410,9 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
os_mmap(NULL, (uint32)total_size,
map_prot, map_flags))) {
app_manager_printf("Allocate executable memory failed!\n");
SEND_ERR_RESPONSE(recv_ctx.message.request_mid,
"Install WASM app failed: "
"allocate memory failed");
goto fail;
}
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
@ -1387,6 +1425,9 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
if (!(section->section_body =
APP_MGR_MALLOC(section->section_body_size))) {
app_manager_printf("Allocate memory failed!\n");
SEND_ERR_RESPONSE(recv_ctx.message.request_mid,
"Install WASM app failed: "
"allocate memory failed");
goto fail;
}
}
@ -1426,7 +1467,15 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
}
else {
app_manager_printf("Handle install message failed!\n");
goto fail;
SEND_ERR_RESPONSE(recv_ctx.message.request_mid,
"Install WASM app failed: "
"handle install message failed");
/**
* The sections were destroyed inside
* module_wasm_app_handle_install_msg(),
* no need to destroy again.
*/
return false;
}
}
else {
@ -1441,6 +1490,9 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch,
#endif /* end of WASM_ENABLE_AOT != 0 */
fail:
/* Restore the package type */
magic = recv_ctx.message.app_file_magic;
package_type = get_package_type((uint8 *)&magic, sizeof(magic) + 1);
switch (package_type) {
#if WASM_ENABLE_INTERP != 0 || WASM_ENABLE_JIT != 0
case Wasm_Module_Bytecode:
@ -1461,10 +1513,7 @@ fail:
recv_ctx.message.request_url = NULL;
}
recv_ctx.phase = Phase_Req_Ver;
recv_ctx.size_in_phase = 0;
recv_ctx.total_received_size = 0;
memset(&recv_ctx, 0, sizeof(recv_ctx));
return false;
}

View File

@ -136,7 +136,8 @@ void * am_dispatch_request(request_t *request)
}
bool am_register_resource(const char *url,
void (*request_handler)(request_t *, void *), uint32 register_id)
void (*request_handler)(request_t *, void *),
uint32 register_id)
{
app_res_register_t * r = g_resources;
int register_num = 0;
@ -158,7 +159,7 @@ bool am_register_resource(const char *url,
if (register_num >= RESOURCE_REGISTRATION_NUM_MAX)
return false;
r = (app_res_register_t *) APP_MGR_MALLOC(sizeof(app_res_register_t));
r = (app_res_register_t *)APP_MGR_MALLOC(sizeof(app_res_register_t));
if (r == NULL)
return false;

View File

@ -124,3 +124,9 @@ bool watchdog_startup()
#endif
return true;
}
bool watchdog_destroy()
{
bh_queue_exit_loop_run(watchdog_queue);
bh_queue_destroy(watchdog_queue);
}

View File

@ -31,6 +31,9 @@ app_manager_get_watchdog_timer(void *timer);
bool
watchdog_startup();
bool
watchdog_destroy();
#ifdef __cplusplus
} /* end of extern "C" */
#endif

View File

@ -570,6 +570,7 @@ gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size,
}
}
hmu = alloc_hmu_ex(heap, tot_size);
if (!hmu)
goto finish;