Skip to content

Feat: Add additional virtual keywords to wasm base. #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/proxy-wasm/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ class ContextBase : public RootInterface,
const std::shared_ptr<PluginHandleBase> &plugin_handle); // Stream context.
virtual ~ContextBase();

WasmBase *wasm() const { return wasm_; }
virtual WasmBase *wasm() const { return wasm_; }
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; }
ContextBase *parent_context() const { return parent_context_; }
ContextBase *root_context() const {
virtual ContextBase *parent_context() const { return parent_context_; }
virtual ContextBase *root_context() const {
const ContextBase *previous = this;
ContextBase *parent = parent_context_;
while (parent != previous) {
Expand All @@ -170,7 +170,7 @@ class ContextBase : public RootInterface,
std::string_view log_prefix() const {
return isRootContext() ? root_log_prefix_ : plugin_->log_prefix();
}
WasmVm *wasmVm() const;
virtual WasmVm *wasmVm() const;

// Called before deleting the context.
virtual void destroy();
Expand Down
22 changes: 11 additions & 11 deletions include/proxy-wasm/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
WasmBase(const std::shared_ptr<WasmHandleBase> &base_wasm_handle, const WasmVmFactory &factory);
virtual ~WasmBase();

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<PluginBase> plugin);
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<PluginBase> plugin);
// Returns the root ContextBase or nullptr if onStart returns false.
ContextBase *start(const std::shared_ptr<PluginBase> &plugin);
virtual ContextBase *start(const std::shared_ptr<PluginBase> &plugin);

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(); }
ContextBase *vm_context() const { return vm_context_.get(); }
ContextBase *getRootContext(const std::shared_ptr<PluginBase> &plugin, bool allow_closed);
virtual ContextBase *vm_context() const { return vm_context_.get(); }
virtual ContextBase *getRootContext(const std::shared_ptr<PluginBase> &plugin, bool allow_closed);
ContextBase *getContext(uint32_t id) {
auto it = contexts_.find(id);
if (it != contexts_.end())
Expand Down Expand Up @@ -321,14 +321,14 @@ using WasmHandleCloneFactory =
class WasmHandleBase : public std::enable_shared_from_this<WasmHandleBase> {
public:
explicit WasmHandleBase(std::shared_ptr<WasmBase> wasm_base) : wasm_base_(wasm_base) {}
~WasmHandleBase() {
virtual ~WasmHandleBase() {
if (wasm_base_) {
wasm_base_->startShutdown();
}
}

bool canary(const std::shared_ptr<PluginBase> &plugin,
const WasmHandleCloneFactory &clone_factory);
virtual bool canary(const std::shared_ptr<PluginBase> &plugin,
const WasmHandleCloneFactory &clone_factory);

void kill() { wasm_base_ = nullptr; }

Expand Down Expand Up @@ -356,7 +356,7 @@ class PluginHandleBase : public std::enable_shared_from_this<PluginHandleBase> {
explicit PluginHandleBase(std::shared_ptr<WasmHandleBase> wasm_handle,
std::shared_ptr<PluginBase> plugin)
: plugin_(plugin), wasm_handle_(wasm_handle) {}
~PluginHandleBase() {
virtual ~PluginHandleBase() {
if (wasm_handle_) {
wasm_handle_->wasm()->startShutdown(plugin_->key());
}
Expand Down
Loading