From acca269cde0404ebdcd0da39d7052e797712423a Mon Sep 17 00:00:00 2001 From: Rachel Green Date: Mon, 28 Jul 2025 18:56:22 +0000 Subject: [PATCH 1/3] Feat: Add additional virtual keywords to wasm base. Signed-off-by: Rachel Green --- include/proxy-wasm/context.h | 13 +++++++++++++ include/proxy-wasm/wasm.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/proxy-wasm/context.h b/include/proxy-wasm/context.h index 7f675525..55a36a4a 100644 --- a/include/proxy-wasm/context.h +++ b/include/proxy-wasm/context.h @@ -150,14 +150,23 @@ class ContextBase : public RootInterface, const std::shared_ptr &plugin_handle); // Stream context. virtual ~ContextBase(); +#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS + virtual WasmBase *wasm() const { return wasm_; } +#else WasmBase *wasm() const { return wasm_; } +#endif uint32_t id() const { return id_; } // The VM Context used for calling "malloc" has an id_ == 0. bool isVmContext() const { return id_ == 0; } // Root Contexts have the VM Context as a parent. bool isRootContext() const { return parent_context_id_ == 0; } +#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS + virtual ContextBase *parent_context() const { return parent_context_; } + virtual ContextBase *root_context() const { +#else ContextBase *parent_context() const { return parent_context_; } ContextBase *root_context() const { +#endif const ContextBase *previous = this; ContextBase *parent = parent_context_; while (parent != previous) { @@ -170,7 +179,11 @@ class ContextBase : public RootInterface, std::string_view log_prefix() const { return isRootContext() ? root_log_prefix_ : plugin_->log_prefix(); } +#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS + virtual WasmVm *wasmVm() const; +#else WasmVm *wasmVm() const; +#endif // Called before deleting the context. virtual void destroy(); diff --git a/include/proxy-wasm/wasm.h b/include/proxy-wasm/wasm.h index 3ab64b24..5f49f530 100644 --- a/include/proxy-wasm/wasm.h +++ b/include/proxy-wasm/wasm.h @@ -54,18 +54,34 @@ class WasmBase : public std::enable_shared_from_this { WasmBase(const std::shared_ptr &base_wasm_handle, const WasmVmFactory &factory); virtual ~WasmBase(); +#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS + virtual bool load(const std::string &code, bool allow_precompiled = false); + virtual bool initialize(); + virtual void startVm(ContextBase *root_context); + virtual bool configure(ContextBase *root_context, std::shared_ptr plugin); +#else bool load(const std::string &code, bool allow_precompiled = false); bool initialize(); void startVm(ContextBase *root_context); bool configure(ContextBase *root_context, std::shared_ptr plugin); +#endif // Returns the root ContextBase or nullptr if onStart returns false. +#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS + virtual ContextBase *start(const std::shared_ptr &plugin); +#else ContextBase *start(const std::shared_ptr &plugin); +#endif std::string_view vm_id() const { return vm_id_; } std::string_view vm_key() const { return vm_key_; } WasmVm *wasm_vm() const { return wasm_vm_.get(); } +#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS + virtual ContextBase *vm_context() const { return vm_context_.get(); } + virtual ContextBase *getRootContext(const std::shared_ptr &plugin, bool allow_closed); +#else ContextBase *vm_context() const { return vm_context_.get(); } ContextBase *getRootContext(const std::shared_ptr &plugin, bool allow_closed); +#endif ContextBase *getContext(uint32_t id) { auto it = contexts_.find(id); if (it != contexts_.end()) @@ -321,14 +337,23 @@ using WasmHandleCloneFactory = class WasmHandleBase : public std::enable_shared_from_this { public: explicit WasmHandleBase(std::shared_ptr wasm_base) : wasm_base_(wasm_base) {} +#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS + virtual ~WasmHandleBase() { +#else ~WasmHandleBase() { +#endif if (wasm_base_) { wasm_base_->startShutdown(); } } +#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS + virtual bool canary(const std::shared_ptr &plugin, + const WasmHandleCloneFactory &clone_factory); +#else bool canary(const std::shared_ptr &plugin, const WasmHandleCloneFactory &clone_factory); +#endif void kill() { wasm_base_ = nullptr; } @@ -356,7 +381,11 @@ class PluginHandleBase : public std::enable_shared_from_this { explicit PluginHandleBase(std::shared_ptr wasm_handle, std::shared_ptr plugin) : plugin_(plugin), wasm_handle_(wasm_handle) {} +#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS + virtual ~PluginHandleBase() { +#else ~PluginHandleBase() { +#endif if (wasm_handle_) { wasm_handle_->wasm()->startShutdown(plugin_->key()); } From e609f6239036cf96f44069932c0388b653ead751 Mon Sep 17 00:00:00 2001 From: Rachel Green Date: Wed, 30 Jul 2025 18:49:26 +0000 Subject: [PATCH 2/3] Always use the 'virtual' keyword. No longer condition it on a build setting. Signed-off-by: Rachel Green --- include/proxy-wasm/context.h | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/include/proxy-wasm/context.h b/include/proxy-wasm/context.h index 55a36a4a..208633ac 100644 --- a/include/proxy-wasm/context.h +++ b/include/proxy-wasm/context.h @@ -150,23 +150,14 @@ class ContextBase : public RootInterface, const std::shared_ptr &plugin_handle); // Stream context. virtual ~ContextBase(); -#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS virtual WasmBase *wasm() const { return wasm_; } -#else - WasmBase *wasm() const { return wasm_; } -#endif uint32_t id() const { return id_; } // The VM Context used for calling "malloc" has an id_ == 0. bool isVmContext() const { return id_ == 0; } // Root Contexts have the VM Context as a parent. bool isRootContext() const { return parent_context_id_ == 0; } -#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS virtual ContextBase *parent_context() const { return parent_context_; } virtual ContextBase *root_context() const { -#else - ContextBase *parent_context() const { return parent_context_; } - ContextBase *root_context() const { -#endif const ContextBase *previous = this; ContextBase *parent = parent_context_; while (parent != previous) { @@ -179,11 +170,7 @@ class ContextBase : public RootInterface, std::string_view log_prefix() const { return isRootContext() ? root_log_prefix_ : plugin_->log_prefix(); } -#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS virtual WasmVm *wasmVm() const; -#else - WasmVm *wasmVm() const; -#endif // Called before deleting the context. virtual void destroy(); From 31fb756eb5c5289ab6cf9ac58f78c09e5c1e7e3e Mon Sep 17 00:00:00 2001 From: Rachel Green Date: Wed, 30 Jul 2025 18:54:43 +0000 Subject: [PATCH 3/3] Always use the 'virtual' keyword for wasm.h. No longer condition it on a build setting. Signed-off-by: Rachel Green --- include/proxy-wasm/wasm.h | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/include/proxy-wasm/wasm.h b/include/proxy-wasm/wasm.h index 5f49f530..9b85710b 100644 --- a/include/proxy-wasm/wasm.h +++ b/include/proxy-wasm/wasm.h @@ -54,34 +54,18 @@ class WasmBase : public std::enable_shared_from_this { WasmBase(const std::shared_ptr &base_wasm_handle, const WasmVmFactory &factory); virtual ~WasmBase(); -#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS virtual bool load(const std::string &code, bool allow_precompiled = false); virtual bool initialize(); virtual void startVm(ContextBase *root_context); virtual bool configure(ContextBase *root_context, std::shared_ptr plugin); -#else - bool load(const std::string &code, bool allow_precompiled = false); - bool initialize(); - void startVm(ContextBase *root_context); - bool configure(ContextBase *root_context, std::shared_ptr plugin); -#endif // Returns the root ContextBase or nullptr if onStart returns false. -#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS virtual ContextBase *start(const std::shared_ptr &plugin); -#else - ContextBase *start(const std::shared_ptr &plugin); -#endif std::string_view vm_id() const { return vm_id_; } std::string_view vm_key() const { return vm_key_; } WasmVm *wasm_vm() const { return wasm_vm_.get(); } -#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS virtual ContextBase *vm_context() const { return vm_context_.get(); } virtual ContextBase *getRootContext(const std::shared_ptr &plugin, bool allow_closed); -#else - ContextBase *vm_context() const { return vm_context_.get(); } - ContextBase *getRootContext(const std::shared_ptr &plugin, bool allow_closed); -#endif ContextBase *getContext(uint32_t id) { auto it = contexts_.find(id); if (it != contexts_.end()) @@ -337,23 +321,14 @@ using WasmHandleCloneFactory = class WasmHandleBase : public std::enable_shared_from_this { public: explicit WasmHandleBase(std::shared_ptr wasm_base) : wasm_base_(wasm_base) {} -#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS virtual ~WasmHandleBase() { -#else - ~WasmHandleBase() { -#endif if (wasm_base_) { wasm_base_->startShutdown(); } } -#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS virtual bool canary(const std::shared_ptr &plugin, const WasmHandleCloneFactory &clone_factory); -#else - bool canary(const std::shared_ptr &plugin, - const WasmHandleCloneFactory &clone_factory); -#endif void kill() { wasm_base_ = nullptr; } @@ -381,11 +356,7 @@ class PluginHandleBase : public std::enable_shared_from_this { explicit PluginHandleBase(std::shared_ptr wasm_handle, std::shared_ptr plugin) : plugin_(plugin), wasm_handle_(wasm_handle) {} -#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS virtual ~PluginHandleBase() { -#else - ~PluginHandleBase() { -#endif if (wasm_handle_) { wasm_handle_->wasm()->startShutdown(plugin_->key()); }