-
Notifications
You must be signed in to change notification settings - Fork 702
Allow finer control of start function on instantiation #4072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sjamesr
wants to merge
1
commit into
bytecodealliance:main
Choose a base branch
from
sjamesr:instantiate_timeout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2333,6 +2333,25 @@ wasm_set_running_mode(WASMModuleInstance *module_inst, RunningMode running_mode) | |
return set_running_mode(module_inst, running_mode, false); | ||
} | ||
|
||
bool | ||
wasm_runtime_instantiate_run_start_func(wasm_module_inst_t module_inst, | ||
wasm_module_inst_t parent, | ||
wasm_exec_env_t exec_env, | ||
char *error_buf, | ||
uint32_t error_buf_size) | ||
{ | ||
const bool is_sub_inst = parent != NULL; | ||
if (!execute_post_instantiate_functions((WASMModuleInstance *)module_inst, | ||
is_sub_inst, exec_env)) { | ||
set_error_buf(error_buf, error_buf_size, | ||
((WASMModuleInstance *)module_inst)->cur_exception); | ||
wasm_runtime_deinstantiate(module_inst); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as wasm_runtime_instantiate succeeded at this point, |
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Instantiate module | ||
*/ | ||
|
@@ -2341,6 +2360,41 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent, | |
WASMExecEnv *exec_env_main, uint32 stack_size, | ||
uint32 heap_size, uint32 max_memory_pages, char *error_buf, | ||
uint32 error_buf_size) | ||
{ | ||
WASMModuleInstance *module_inst = wasm_instantiate_without_start_function( | ||
module, parent, exec_env_main, stack_size, heap_size, max_memory_pages, | ||
error_buf, error_buf_size); | ||
|
||
if (!module_inst) { | ||
// wasm_instantiate_without_start_function will deinstantiate on | ||
// failure. | ||
return NULL; | ||
} | ||
|
||
if (!wasm_runtime_instantiate_run_start_func( | ||
(WASMModuleInstanceCommon *)module_inst, | ||
(WASMModuleInstanceCommon *)parent, exec_env_main, error_buf, | ||
error_buf_size)) { | ||
// run_start_func will deinstantiate on failure. | ||
set_error_buf(error_buf, error_buf_size, module_inst->cur_exception); | ||
return NULL; | ||
} | ||
|
||
#if WASM_ENABLE_MEMORY_TRACING != 0 | ||
wasm_runtime_dump_module_inst_mem_consumption( | ||
(WASMModuleInstanceCommon *)module_inst); | ||
#endif | ||
|
||
return module_inst; | ||
} | ||
|
||
WASMModuleInstance * | ||
wasm_instantiate_without_start_function(WASMModule *module, | ||
WASMModuleInstance *parent, | ||
WASMExecEnv *exec_env_main, | ||
uint32 stack_size, uint32 heap_size, | ||
uint32 max_memory_pages, | ||
char *error_buf, uint32 error_buf_size) | ||
{ | ||
WASMModuleInstance *module_inst; | ||
WASMGlobalInstance *globals = NULL, *global; | ||
|
@@ -3257,17 +3311,6 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent, | |
&module_inst->e->functions[module->start_function]; | ||
} | ||
|
||
if (!execute_post_instantiate_functions(module_inst, is_sub_inst, | ||
exec_env_main)) { | ||
set_error_buf(error_buf, error_buf_size, module_inst->cur_exception); | ||
goto fail; | ||
} | ||
|
||
#if WASM_ENABLE_MEMORY_TRACING != 0 | ||
wasm_runtime_dump_module_inst_mem_consumption( | ||
(WASMModuleInstanceCommon *)module_inst); | ||
#endif | ||
|
||
(void)global_data_end; | ||
return module_inst; | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this name is a bit confusing because it doesn't run wasi's entry point,
_start
.how about wasm_runtime_execute_instantiate_functions?