Skip to content

Commit 4746eaa

Browse files
committed
Merge main into dev/fast_jit
2 parents e675564 + d7a2888 commit 4746eaa

File tree

92 files changed

+2068
-557
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+2068
-557
lines changed

build-scripts/build_llvm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def main():
208208
},
209209
"xtensa": {
210210
"repo": "https://github.com/espressif/llvm-project.git",
211-
"branch": "xtensa_release_11.0.0",
211+
"branch": "xtensa_release_13.0.0",
212212
},
213213
"default": {
214214
"repo": "https://github.com/llvm/llvm-project.git",

core/app-framework/base/native/runtime_lib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "runtime_timer.h"
1010

11-
void
11+
bool
1212
init_wasm_timer();
1313
void
1414
exit_wasm_timer();

core/app-framework/base/native/timer_wrapper.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,36 @@ wakeup_modules_timer_thread(timer_ctx_t ctx)
8383
os_mutex_unlock(&g_timer_ctx_list_mutex);
8484
}
8585

86-
void
86+
bool
8787
init_wasm_timer()
8888
{
8989
korp_tid tm_tid;
9090
bh_list_init(&g_timer_ctx_list);
9191

92-
os_cond_init(&g_timer_ctx_list_cond);
92+
if (os_cond_init(&g_timer_ctx_list_cond) != 0) {
93+
return false;
94+
}
9395
/* temp solution for: thread_modulers_timer_check thread
9496
would recursive lock the mutex */
95-
os_recursive_mutex_init(&g_timer_ctx_list_mutex);
97+
if (os_recursive_mutex_init(&g_timer_ctx_list_mutex) != 0) {
98+
goto fail1;
99+
}
100+
101+
if (0
102+
!= os_thread_create(&tm_tid, thread_modulers_timer_check, NULL,
103+
BH_APPLET_PRESERVED_STACK_SIZE)) {
104+
goto fail2;
105+
}
106+
107+
return true;
108+
109+
fail2:
110+
os_mutex_destroy(&g_timer_ctx_list_mutex);
111+
112+
fail1:
113+
os_cond_destroy(&g_timer_ctx_list_cond);
96114

97-
os_thread_create(&tm_tid, thread_modulers_timer_check, NULL,
98-
BH_APPLET_PRESERVED_STACK_SIZE);
115+
return false;
99116
}
100117

101118
void

core/app-framework/sensor/native/runtime_sensor.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,13 @@ add_sys_sensor(char *name, char *description, int instance,
309309
g_sys_sensors = s;
310310
}
311311

312-
os_mutex_init(&s->lock);
312+
if (os_mutex_init(&s->lock) != 0) {
313+
if (s->description) {
314+
wasm_runtime_free(s->description);
315+
}
316+
wasm_runtime_free(s->name);
317+
wasm_runtime_free(s);
318+
}
313319

314320
return s;
315321
}
@@ -358,6 +364,7 @@ find_sensor_client(sys_sensor_t *sensor, unsigned int client_id,
358364
return c;
359365
}
360366
else {
367+
prev = c;
361368
c = c->next;
362369
}
363370
}

core/app-framework/sensor/native/runtime_sensor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ check_sensor_timers();
5959
void
6060
reschedule_sensor_read();
6161

62-
void
62+
bool
6363
init_sensor_framework();
6464
void
6565
start_sensor_framework();

core/app-framework/sensor/native/sensor_mgr_ref.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,27 @@ cb_wakeup_thread()
106106
void
107107
set_sensor_reshceduler(void (*callback)());
108108

109-
void
109+
bool
110110
init_sensor_framework()
111111
{
112-
// init the mutext and conditions
113-
os_cond_init(&cond);
114-
os_mutex_init(&mutex);
112+
/* init the mutext and conditions */
113+
if (os_cond_init(&cond) != 0) {
114+
return false;
115+
}
116+
117+
if (os_mutex_init(&mutex) != 0) {
118+
os_cond_destroy(&cond);
119+
return false;
120+
}
115121

116122
set_sensor_reshceduler(cb_wakeup_thread);
117123

118124
wasm_register_msg_callback(SENSOR_EVENT_WASM,
119125
app_mgr_sensor_event_callback);
120126

121127
wasm_register_cleanup_callback(sensor_cleanup_callback);
128+
129+
return true;
122130
}
123131

124132
void

core/app-mgr/app-manager/app_manager_host.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,21 @@ aee_host_msg_callback(void *msg, uint32_t msg_len)
264264
bool
265265
app_manager_host_init(host_interface *interface)
266266
{
267-
os_mutex_init(&host_lock);
267+
if (os_mutex_init(&host_lock) != 0) {
268+
return false;
269+
}
268270
memset(&recv_ctx, 0, sizeof(recv_ctx));
269271

270272
host_commu.init = interface->init;
271273
host_commu.send = interface->send;
272274
host_commu.destroy = interface->destroy;
273275

274-
if (host_commu.init != NULL)
275-
return host_commu.init();
276+
if (host_commu.init != NULL) {
277+
if (!host_commu.init()) {
278+
os_mutex_destroy(&host_lock);
279+
return false;
280+
}
281+
}
276282

277283
return true;
278284
}

core/app-mgr/app-manager/module_wasm_app.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,12 @@ app_instance_queue_callback(void *queue_msg, void *arg)
207207

208208
wasm_module_inst_t inst = (wasm_module_inst_t)arg;
209209
module_data *m_data = app_manager_get_module_data(Module_WASM_App, inst);
210-
wasm_data *wasm_app_data = (wasm_data *)m_data->internal_data;
211-
int message_type = bh_message_type(queue_msg);
210+
wasm_data *wasm_app_data;
211+
int message_type;
212212

213213
bh_assert(m_data);
214+
wasm_app_data = (wasm_data *)m_data->internal_data;
215+
message_type = bh_message_type(queue_msg);
214216

215217
if (message_type < BASE_EVENT_MAX) {
216218
switch (message_type) {
@@ -410,16 +412,15 @@ wasm_app_prepare_wasi_dir(wasm_module_t module, const char *module_name,
410412
p += module_name_len;
411413
*p++ = '\0';
412414

413-
/* Create a wasi dir for the module */
414-
if (stat(wasi_dir_buf, &st) == 0) {
415-
/* exist, but is a regular file, not a dir */
416-
if (st.st_mode & S_IFREG)
417-
return false;
418-
}
419-
else {
420-
/* not exist, create it */
421-
if (mkdir(wasi_dir_buf, 0777) != 0)
422-
return false;
415+
if (mkdir(wasi_dir_buf, 0777) != 0) {
416+
if (errno == EEXIST) {
417+
/* Failed due to dir already exist */
418+
if ((stat(wasi_dir_buf, &st) == 0) && (st.st_mode & S_IFDIR)) {
419+
return true;
420+
}
421+
}
422+
423+
return false;
423424
}
424425

425426
return true;
@@ -491,9 +492,16 @@ wasm_app_routine(void *arg)
491492
fail2:
492493
/* Call WASM app onDestroy() method if there is */
493494
func_onDestroy = app_manager_lookup_function(inst, "_on_destroy", "()");
494-
if (func_onDestroy)
495-
wasm_runtime_call_wasm(wasm_app_data->exec_env, func_onDestroy, 0,
496-
NULL);
495+
if (func_onDestroy) {
496+
if (!wasm_runtime_call_wasm(wasm_app_data->exec_env, func_onDestroy, 0,
497+
NULL)) {
498+
const char *exception = wasm_runtime_get_exception(inst);
499+
bh_assert(exception);
500+
app_manager_printf("Got exception running WASM code: %s\n",
501+
exception);
502+
wasm_runtime_clear_exception(inst);
503+
}
504+
}
497505

498506
fail1:
499507

core/iwasm/aot/aot_loader.c

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -261,48 +261,34 @@ load_string(uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
261261
char *str;
262262
uint16 str_len;
263263

264-
CHECK_BUF(p, p_end, 1);
265-
if (*p & 0x80) {
266-
/* The string has been adjusted */
267-
str = (char *)++p;
268-
/* Ensure the whole string is in range */
269-
do {
270-
CHECK_BUF(p, p_end, 1);
271-
} while (*p++ != '\0');
264+
read_uint16(p, p_end, str_len);
265+
CHECK_BUF(p, p_end, str_len);
266+
267+
if (str_len == 0) {
268+
str = "";
269+
}
270+
else if (p[str_len - 1] == '\0') {
271+
/* The string is terminated with '\0', use it directly */
272+
str = (char *)p;
273+
}
274+
else if (is_load_from_file_buf) {
275+
/* As the file buffer can be referred to after loading,
276+
we use the 2 bytes of size to adjust the string:
277+
move string 2 byte backward and then append '\0' */
278+
str = (char *)(p - 2);
279+
bh_memmove_s(str, (uint32)(str_len + 1), p, (uint32)str_len);
280+
str[str_len] = '\0';
272281
}
273282
else {
274-
/* The string hasn't been adjusted */
275-
read_uint16(p, p_end, str_len);
276-
CHECK_BUF(p, p_end, str_len);
277-
278-
if (str_len == 0) {
279-
str = "";
280-
}
281-
else if (p[str_len - 1] == '\0') {
282-
/* The string is terminated with '\0', use it directly */
283-
str = (char *)p;
284-
}
285-
else if (is_load_from_file_buf) {
286-
/* As the file buffer can be referred to after loading,
287-
we use the 2 bytes of size to adjust the string:
288-
mark the flag with the highest bit of size[0],
289-
move string 1 byte backward and then append '\0' */
290-
*(p - 2) |= 0x80;
291-
bh_memmove_s(p - 1, (uint32)(str_len + 1), p, (uint32)str_len);
292-
p[str_len - 1] = '\0';
293-
str = (char *)(p - 1);
294-
}
295-
else {
296-
/* Load from sections, the file buffer cannot be reffered to
297-
after loading, we must create another string and insert it
298-
into const string set */
299-
if (!(str = const_str_set_insert((uint8 *)p, str_len, module,
300-
error_buf, error_buf_size))) {
301-
goto fail;
302-
}
283+
/* Load from sections, the file buffer cannot be reffered to
284+
after loading, we must create another string and insert it
285+
into const string set */
286+
if (!(str = const_str_set_insert((uint8 *)p, str_len, module, error_buf,
287+
error_buf_size))) {
288+
goto fail;
303289
}
304-
p += str_len;
305290
}
291+
p += str_len;
306292

307293
*p_buf = p;
308294
return str;
@@ -1850,7 +1836,9 @@ do_text_relocation(AOTModule *module, AOTRelocationGroup *group,
18501836
|| !strcmp(symbol, ".rdata")
18511837
|| !strcmp(symbol, ".rodata")
18521838
/* ".rodata.cst4/8/16/.." */
1853-
|| !strncmp(symbol, ".rodata.cst", strlen(".rodata.cst"))) {
1839+
|| !strncmp(symbol, ".rodata.cst", strlen(".rodata.cst"))
1840+
/* ".rodata.strn.m" */
1841+
|| !strncmp(symbol, ".rodata.str", strlen(".rodata.str"))) {
18541842
symbol_addr = get_data_section_addr(module, symbol, NULL);
18551843
if (!symbol_addr) {
18561844
set_error_buf_v(error_buf, error_buf_size,
@@ -2054,6 +2042,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
20542042
uint8 *symbol_buf, *symbol_buf_end;
20552043
int map_prot, map_flags;
20562044
bool ret = false;
2045+
char **symbols = NULL;
20572046

20582047
read_uint32(buf, buf_end, symbol_count);
20592048

@@ -2074,6 +2063,14 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
20742063
goto fail;
20752064
}
20762065

2066+
if (symbol_count > 0) {
2067+
symbols = loader_malloc((uint64)sizeof(*symbols) * symbol_count,
2068+
error_buf, error_buf_size);
2069+
if (symbols == NULL) {
2070+
goto fail;
2071+
}
2072+
}
2073+
20772074
#if defined(BH_PLATFORM_WINDOWS)
20782075
buf = symbol_buf_end;
20792076
read_uint32(buf, buf_end, group_count);
@@ -2208,7 +2205,6 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
22082205
for (i = 0, group = groups; i < group_count; i++, group++) {
22092206
AOTRelocation *relocation;
22102207
uint32 name_index;
2211-
uint8 *name_addr;
22122208

22132209
/* section name address is 4 bytes aligned. */
22142210
buf = (uint8 *)align_ptr(buf, sizeof(uint32));
@@ -2220,8 +2216,12 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
22202216
goto fail;
22212217
}
22222218

2223-
name_addr = symbol_buf + symbol_offsets[name_index];
2224-
read_string(name_addr, buf_end, group->section_name);
2219+
if (symbols[name_index] == NULL) {
2220+
uint8 *name_addr = symbol_buf + symbol_offsets[name_index];
2221+
2222+
read_string(name_addr, buf_end, symbols[name_index]);
2223+
}
2224+
group->section_name = symbols[name_index];
22252225

22262226
read_uint32(buf, buf_end, group->relocation_count);
22272227

@@ -2236,7 +2236,6 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
22362236
/* Load each relocation */
22372237
for (j = 0; j < group->relocation_count; j++, relocation++) {
22382238
uint32 symbol_index;
2239-
uint8 *symbol_addr;
22402239

22412240
if (sizeof(void *) == 8) {
22422241
read_uint64(buf, buf_end, relocation->relocation_offset);
@@ -2258,8 +2257,12 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
22582257
goto fail;
22592258
}
22602259

2261-
symbol_addr = symbol_buf + symbol_offsets[symbol_index];
2262-
read_string(symbol_addr, buf_end, relocation->symbol_name);
2260+
if (symbols[symbol_index] == NULL) {
2261+
uint8 *symbol_addr = symbol_buf + symbol_offsets[symbol_index];
2262+
2263+
read_string(symbol_addr, buf_end, symbols[symbol_index]);
2264+
}
2265+
relocation->symbol_name = symbols[symbol_index];
22632266
}
22642267

22652268
if (!strcmp(group->section_name, ".rel.text")
@@ -2314,14 +2317,20 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
23142317
|| !strcmp(data_section->name, ".rodata")
23152318
/* ".rodata.cst4/8/16/.." */
23162319
|| !strncmp(data_section->name, ".rodata.cst",
2317-
strlen(".rodata.cst"))) {
2320+
strlen(".rodata.cst"))
2321+
/* ".rodata.strn.m" */
2322+
|| !strncmp(data_section->name, ".rodata.str",
2323+
strlen(".rodata.str"))) {
23182324
os_mprotect(data_section->data, data_section->size, map_prot);
23192325
}
23202326
}
23212327

23222328
ret = true;
23232329

23242330
fail:
2331+
if (symbols) {
2332+
wasm_runtime_free(symbols);
2333+
}
23252334
if (groups) {
23262335
for (i = 0, group = groups; i < group_count; i++, group++)
23272336
if (group->relocations)

0 commit comments

Comments
 (0)