Skip to content

Commit

Permalink
fix wasi
Browse files Browse the repository at this point in the history
  • Loading branch information
victoryang00 committed Feb 1, 2024
1 parent 79a52e5 commit 4a1dc93
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
23 changes: 12 additions & 11 deletions src/wamr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ void WAMRInstance::recover(std::vector<std::unique_ptr<WAMRExecEnv>> *e_) {
// invoke_init_c();
// invoke_preopen(1, "/dev/stdout");
fprintf(stderr, "wakeup.release\n");
sleep(1);
sleep(5);
wakeup.release(100);

cur_env->is_restore = true;
Expand Down Expand Up @@ -719,35 +719,36 @@ void WAMRInstance::spawn_child(WASMExecEnv *cur_env) {
child_env = exec_;
// requires to record the args and callback for the pthread.
auto thread_arg = ThreadArgs{cur_env};
//cur_env->restore_call_chain = NULL;
// cur_env->is_restore = false;
// cur_env->is_restore = false;

argptr[id] = &thread_arg;
auto parent = child_tid_map[child_env->cur_count];
if (parent == cur_env->cur_count) {
LOGV(ERROR) << parent << " " << child_env->cur_count;
// restart thread execution

fprintf(stderr, "pthread_create_wrapper, func %d\n", child_env->cur_count);
// module_inst = wasm_runtime_instantiate(module, stack_size, heap_size, error_buf, sizeof(error_buf));
exec_env->is_restore = false;
auto s = exec_env->restore_call_chain;
exec_env->restore_call_chain = NULL;
invoke_init_c();
invoke_preopen(1, "/dev/stdout");
exec_env->is_restore = true;
exec_env->restore_call_chain = s;
if (tid_start_arg_map.find(child_env->cur_count) != tid_start_arg_map.end()) {
// find the parent env
cur_env->restore_call_chain = NULL;

// main thread
thread_spawn_wrapper(cur_env, tid_start_arg_map[child_env->cur_count]);

} else {
exec_env->is_restore = false;
auto s = exec_env->restore_call_chain;
exec_env->restore_call_chain = NULL;
invoke_init_c();
invoke_preopen(1, "/dev/stdout");
exec_env->is_restore = true;
exec_env->restore_call_chain = s;
pthread_create_wrapper(cur_env, nullptr, nullptr, id, id); // tid_map
}
fprintf(stderr, "child spawned %p\n\n", cur_env);
// sleep(1);
this->as_mtx.unlock();

thread_init.acquire();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/wamr_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ void insert_tid_start_arg(ssize_t tid, size_t start_arg){
wamr->tid_start_arg_map[tid] = start_arg;
};
void change_thread_id_to_child(ssize_t tid, ssize_t child_tid){
LOGV(ERROR)<<fmt::format("change_thread_id_to_child {} {}", tid, child_tid);
for (auto &[k, v] : wamr->child_tid_map) {
if (k == child_tid) {
wamr->child_tid_map[tid] = v;
Expand All @@ -317,6 +318,7 @@ void change_thread_id_to_child(ssize_t tid, ssize_t child_tid){
}
};
void insert_parent_child(ssize_t tid, ssize_t child_tid){
LOGV(ERROR)<<fmt::format("insert_parent_child {} {}", tid, child_tid);
wamr->child_tid_map[child_tid] = tid;
};
void lightweight_checkpoint(WASMExecEnv *exec_env) {
Expand Down

0 comments on commit 4a1dc93

Please sign in to comment.