From 6cbde81995826de9be74ad5ab958bcdf433e7a7d Mon Sep 17 00:00:00 2001 From: Rachel Green Date: Tue, 12 Aug 2025 18:48:01 +0000 Subject: [PATCH 1/3] Added 'Plugin Crash' to the plugin fail message for v8 Signed-off-by: Rachel Green --- src/v8/v8.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/v8/v8.cc b/src/v8/v8.cc index bc5b8285..b29f77bc 100644 --- a/src/v8/v8.cc +++ b/src/v8/v8.cc @@ -106,7 +106,7 @@ class V8 : public WasmVm { private: wasm::own trap(std::string message); - std::string getFailMessage(std::string_view function_name, wasm::own trap); + std::string getPluginFailMessage(std::string_view function_name, wasm::own trap); template void registerHostFunctionImpl(std::string_view module_name, std::string_view function_name, @@ -638,7 +638,8 @@ void V8::getModuleFunctionImpl(std::string_view function_name, } if (trap) { - fail(FailState::RuntimeError, getFailMessage(std::string(function_name), std::move(trap))); + fail(FailState::RuntimeError, + getPluginFailMessage(std::string(function_name), std::move(trap))); return; } if (log) { @@ -690,7 +691,8 @@ void V8::getModuleFunctionImpl(std::string_view function_name, } if (trap) { - fail(FailState::RuntimeError, getFailMessage(std::string(function_name), std::move(trap))); + fail(FailState::RuntimeError, + getPluginFailMessage(std::string(function_name), std::move(trap))); return R{}; } R rvalue = results[0].get::type>(); @@ -708,8 +710,8 @@ void V8::terminate() { isolate->TerminateExecution(); } -std::string V8::getFailMessage(std::string_view function_name, wasm::own trap) { - auto message = "Function: " + std::string(function_name) + " failed: "; +std::string V8::getPluginFailMessage(std::string_view function_name, wasm::own trap) { + auto message = "Plugin Crash: Function: " + std::string(function_name) + " failed: "; message += std::string(trap->message().get(), trap->message().size()); if (function_names_index_.empty()) { From 0a148d61aecd2caf45c62b75a619b413ccbdf886 Mon Sep 17 00:00:00 2001 From: Rachel Green Date: Thu, 21 Aug 2025 17:24:49 +0000 Subject: [PATCH 2/3] Add plugin crash message to higher level fail function in wasm_vm.h Signed-off-by: Rachel Green --- include/proxy-wasm/wasm_vm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/proxy-wasm/wasm_vm.h b/include/proxy-wasm/wasm_vm.h index db54ebd8..93442f7d 100644 --- a/include/proxy-wasm/wasm_vm.h +++ b/include/proxy-wasm/wasm_vm.h @@ -310,7 +310,7 @@ class WasmVm { bool isFailed() { return failed_ != FailState::Ok; } void fail(FailState fail_state, std::string_view message) { - integration()->error(message); + integration()->error("Plugin Crash: " + message); failed_ = fail_state; for (auto &callback : fail_callbacks_) { callback(fail_state); From 8bdf040341ab6c0e9acde7a9757c8fac17d63a4d Mon Sep 17 00:00:00 2001 From: Rachel Green Date: Tue, 16 Sep 2025 19:37:41 +0000 Subject: [PATCH 3/3] Moved the plugin crash prefix addition to wasm_vm.h, so that behavior is shared across all runtimes. Signed-off-by: Rachel Green --- include/proxy-wasm/wasm_vm.h | 7 ++++++- src/v8/v8.cc | 30 ++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/include/proxy-wasm/wasm_vm.h b/include/proxy-wasm/wasm_vm.h index 93442f7d..e5f0ff43 100644 --- a/include/proxy-wasm/wasm_vm.h +++ b/include/proxy-wasm/wasm_vm.h @@ -310,7 +310,11 @@ class WasmVm { bool isFailed() { return failed_ != FailState::Ok; } void fail(FailState fail_state, std::string_view message) { - integration()->error("Plugin Crash: " + message); + if (fail_state == FailState::RuntimeError) { + integration()->error(std::string(PluginCrashPrefix) + std::string(message)); + } else { + integration()->error(message); + } failed_ = fail_state; for (auto &callback : fail_callbacks_) { callback(fail_state); @@ -340,6 +344,7 @@ class WasmVm { std::vector> fail_callbacks_; private: + static constexpr std::string_view PluginCrashPrefix = "Plugin crash: "; bool restricted_callback_{false}; std::unordered_set allowed_hostcalls_{}; }; diff --git a/src/v8/v8.cc b/src/v8/v8.cc index b29f77bc..9e184f29 100644 --- a/src/v8/v8.cc +++ b/src/v8/v8.cc @@ -103,10 +103,12 @@ class V8 : public WasmVm { void terminate() override; bool usesWasmByteOrder() override { return true; } + void warm() override; + private: wasm::own trap(std::string message); - std::string getPluginFailMessage(std::string_view function_name, wasm::own trap); + std::string getFailMessage(std::string_view function_name, wasm::own trap); template void registerHostFunctionImpl(std::string_view module_name, std::string_view function_name, @@ -124,6 +126,9 @@ class V8 : public WasmVm { void getModuleFunctionImpl(std::string_view function_name, std::function *function); + // Initialize the V8 engine and store if necessary. + void initStore(); + wasm::own store_; wasm::own module_; wasm::own> shared_module_; @@ -260,9 +265,16 @@ template constexpr T convertValTypesToArgsTuple(const U // V8 implementation. +void V8::initStore() { + if (store_ != nullptr) { + return; + } + store_ = wasm::Store::make(engine()); +} + bool V8::load(std::string_view bytecode, std::string_view precompiled, const std::unordered_map &function_names) { - store_ = wasm::Store::make(engine()); + initStore(); if (store_ == nullptr) { return false; } @@ -638,8 +650,7 @@ void V8::getModuleFunctionImpl(std::string_view function_name, } if (trap) { - fail(FailState::RuntimeError, - getPluginFailMessage(std::string(function_name), std::move(trap))); + fail(FailState::RuntimeError, getFailMessage(std::string(function_name), std::move(trap))); return; } if (log) { @@ -691,8 +702,7 @@ void V8::getModuleFunctionImpl(std::string_view function_name, } if (trap) { - fail(FailState::RuntimeError, - getPluginFailMessage(std::string(function_name), std::move(trap))); + fail(FailState::RuntimeError, getFailMessage(std::string(function_name), std::move(trap))); return R{}; } R rvalue = results[0].get::type>(); @@ -710,8 +720,10 @@ void V8::terminate() { isolate->TerminateExecution(); } -std::string V8::getPluginFailMessage(std::string_view function_name, wasm::own trap) { - auto message = "Plugin Crash: Function: " + std::string(function_name) + " failed: "; +void V8::warm() { initStore(); } + +std::string V8::getFailMessage(std::string_view function_name, wasm::own trap) { + auto message = "Function: " + std::string(function_name) + " failed: "; message += std::string(trap->message().get(), trap->message().size()); if (function_names_index_.empty()) { @@ -743,6 +755,8 @@ std::string V8::getPluginFailMessage(std::string_view function_name, wasm::own createV8Vm() { return std::make_unique(); } } // namespace proxy_wasm