From 474a6209dab82d58c85e749032465b521a5f5a6e Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Sat, 28 Feb 2026 00:48:56 -0500 Subject: [PATCH] Call __main_void if exported by a plugin. This is how Rust exports main() function since Rust v1.67. Signed-off-by: Piotr Sikora --- include/proxy-wasm/wasm.h | 2 ++ include/proxy-wasm/wasm_vm.h | 4 ++-- src/wasm.cc | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/proxy-wasm/wasm.h b/include/proxy-wasm/wasm.h index 9b85710bd..00e11f500 100644 --- a/include/proxy-wasm/wasm.h +++ b/include/proxy-wasm/wasm.h @@ -226,6 +226,8 @@ class WasmBase : public std::enable_shared_from_this { WasmCallVoid<0> _start_; /* WASI command (Emscripten v1.39.0+, TinyGo) */ WasmCallWord<2> main_; + WasmCallWord<0> __main_void_; + WasmCallWord<1> malloc_; // Calls into the VM. diff --git a/include/proxy-wasm/wasm_vm.h b/include/proxy-wasm/wasm_vm.h index e2e2ea0bb..9fc435d35 100644 --- a/include/proxy-wasm/wasm_vm.h +++ b/include/proxy-wasm/wasm_vm.h @@ -71,8 +71,8 @@ using WasmCallWord = std::function) _f(proxy_wasm::WasmCallVoid<1>) _f(proxy_wasm::WasmCallVoid<2>) \ _f(proxy_wasm::WasmCallVoid<3>) _f(proxy_wasm::WasmCallVoid<5>) \ - _f(proxy_wasm::WasmCallWord<1>) _f(proxy_wasm::WasmCallWord<2>) \ - _f(proxy_wasm::WasmCallWord<3>) + _f(proxy_wasm::WasmCallWord<0>) _f(proxy_wasm::WasmCallWord<1>) \ + _f(proxy_wasm::WasmCallWord<2>) _f(proxy_wasm::WasmCallWord<3>) // These are templates and its helper for constructing signatures of functions callbacks from Wasm // VMs. diff --git a/src/wasm.cc b/src/wasm.cc index a1b4c1836..6502cd03f 100644 --- a/src/wasm.cc +++ b/src/wasm.cc @@ -162,6 +162,7 @@ void WasmBase::getFunctions() { _GET(_initialize); if (_initialize_) { _GET(main); + _GET(__main_void); } else { _GET(_start); } @@ -410,6 +411,8 @@ void WasmBase::startVm(ContextBase *root_context) { // Re-using main() keeps this consistent when switching between // WASI command (that calls main()) and reactor (that doesn't). main_(root_context, Word(0), Word(0)); + } else if (__main_void_) { + __main_void_(root_context); } } else if (_start_) { // WASI command.