From 1996b3059c6972d4d2ba7b929b47eace3dcf6f9a Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Tue, 20 Oct 2020 12:52:00 +0000 Subject: [PATCH 1/2] Add support for the _initialize() crt1 startup function. Signed-off-by: Piotr Sikora --- include/proxy-wasm/wasm.h | 1 + src/null/null_plugin.cc | 4 +++- src/wasm.cc | 6 ++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/proxy-wasm/wasm.h b/include/proxy-wasm/wasm.h index 4f81bd1ad..baaf3446d 100644 --- a/include/proxy-wasm/wasm.h +++ b/include/proxy-wasm/wasm.h @@ -172,6 +172,7 @@ 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> _initialize_; /* Emscripten v1.39.17+ */ WasmCallVoid<0> _start_; /* Emscripten v1.39.0+ */ WasmCallVoid<0> __wasm_call_ctors_; 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); From 8170fd0d7681992a6487b5881f594a9c356f1e2b Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Thu, 22 Oct 2020 01:51:28 +0000 Subject: [PATCH 2/2] review: fix format. Signed-off-by: Piotr Sikora --- include/proxy-wasm/wasm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/proxy-wasm/wasm.h b/include/proxy-wasm/wasm.h index baaf3446d..2b4291709 100644 --- a/include/proxy-wasm/wasm.h +++ b/include/proxy-wasm/wasm.h @@ -173,7 +173,7 @@ class WasmBase : public std::enable_shared_from_this { std::unordered_set pending_done_; // Root contexts not done during shutdown. WasmCallVoid<0> _initialize_; /* Emscripten v1.39.17+ */ - WasmCallVoid<0> _start_; /* Emscripten v1.39.0+ */ + WasmCallVoid<0> _start_; /* Emscripten v1.39.0+ */ WasmCallVoid<0> __wasm_call_ctors_; WasmCallWord<1> malloc_;