Skip to content

Commit d54b379

Browse files
authored
Add support for the _initialize() crt1 startup function. (#72)
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
1 parent 5e79871 commit d54b379

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

include/proxy-wasm/wasm.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
172172
std::unique_ptr<ShutdownHandle> shutdown_handle_;
173173
std::unordered_set<ContextBase *> pending_done_; // Root contexts not done during shutdown.
174174

175-
WasmCallVoid<0> _start_; /* Emscripten v1.39.0+ */
175+
WasmCallVoid<0> _initialize_; /* Emscripten v1.39.17+ */
176+
WasmCallVoid<0> _start_; /* Emscripten v1.39.0+ */
176177
WasmCallVoid<0> __wasm_call_ctors_;
177178

178179
WasmCallWord<1> malloc_;

src/null/null_plugin.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
namespace proxy_wasm {
3434

3535
void NullPlugin::getFunction(std::string_view function_name, WasmCallVoid<0> *f) {
36-
if (function_name == "_start") {
36+
if (function_name == "_initialize") {
37+
*f = nullptr;
38+
} else if (function_name == "_start") {
3739
*f = nullptr;
3840
} else if (function_name == "__wasm_call_ctors") {
3941
*f = nullptr;

src/wasm.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ void WasmBase::registerCallbacks() {
193193

194194
void WasmBase::getFunctions() {
195195
#define _GET(_fn) wasm_vm_->getFunction(#_fn, &_fn##_);
196+
_GET(_initialize);
196197
_GET(_start);
197198
_GET(__wasm_call_ctors);
198199

@@ -324,8 +325,9 @@ ContextBase *WasmBase::getOrCreateRootContext(const std::shared_ptr<PluginBase>
324325
}
325326

326327
void WasmBase::startVm(ContextBase *root_context) {
327-
/* Call "_start" function, and fallback to "__wasm_call_ctors" if the former is not available. */
328-
if (_start_) {
328+
if (_initialize_) {
329+
_initialize_(root_context);
330+
} else if (_start_) {
329331
_start_(root_context);
330332
} else if (__wasm_call_ctors_) {
331333
__wasm_call_ctors_(root_context);

0 commit comments

Comments
 (0)