diff --git a/include/proxy-wasm/wasm.h b/include/proxy-wasm/wasm.h index 4f81bd1ad..2b4291709 100644 --- a/include/proxy-wasm/wasm.h +++ b/include/proxy-wasm/wasm.h @@ -172,7 +172,8 @@ class WasmBase : public std::enable_shared_from_this { std::unique_ptr shutdown_handle_; std::unordered_set pending_done_; // Root contexts not done during shutdown. - WasmCallVoid<0> _start_; /* Emscripten v1.39.0+ */ + WasmCallVoid<0> _initialize_; /* Emscripten v1.39.17+ */ + WasmCallVoid<0> _start_; /* Emscripten v1.39.0+ */ WasmCallVoid<0> __wasm_call_ctors_; WasmCallWord<1> malloc_; diff --git a/src/null/null_plugin.cc b/src/null/null_plugin.cc index cea740707..dfc2dbfaa 100644 --- a/src/null/null_plugin.cc +++ b/src/null/null_plugin.cc @@ -33,7 +33,9 @@ namespace proxy_wasm { void NullPlugin::getFunction(std::string_view function_name, WasmCallVoid<0> *f) { - if (function_name == "_start") { + if (function_name == "_initialize") { + *f = nullptr; + } else if (function_name == "_start") { *f = nullptr; } else if (function_name == "__wasm_call_ctors") { *f = nullptr; diff --git a/src/wasm.cc b/src/wasm.cc index 496041cf4..5f8b7652f 100644 --- a/src/wasm.cc +++ b/src/wasm.cc @@ -193,6 +193,7 @@ void WasmBase::registerCallbacks() { void WasmBase::getFunctions() { #define _GET(_fn) wasm_vm_->getFunction(#_fn, &_fn##_); + _GET(_initialize); _GET(_start); _GET(__wasm_call_ctors); @@ -324,8 +325,9 @@ ContextBase *WasmBase::getOrCreateRootContext(const std::shared_ptr } void WasmBase::startVm(ContextBase *root_context) { - /* Call "_start" function, and fallback to "__wasm_call_ctors" if the former is not available. */ - if (_start_) { + if (_initialize_) { + _initialize_(root_context); + } else if (_start_) { _start_(root_context); } else if (__wasm_call_ctors_) { __wasm_call_ctors_(root_context);