Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion source/extensions/access_loggers/wasm/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ WasmAccessLogFactory::createAccessLogInstance(const Protobuf::Message& proto_con
auto configuration = std::make_shared<std::string>(config.configuration());
auto tls_slot = context.threadLocal().allocateSlot();
if (config.has_vm_config()) {
// Create a base WASM to verify that the code loads before setting/cloning the for the individual threads.
// Create a base WASM to verify that the code loads before setting/cloning the for the
// individual threads.
auto base_wasm = Common::Wasm::createWasm(id, config.vm_config(), context.clusterManager(),
context.dispatcher(), context.api());
// NB: the Slot set() call doesn't complete inline, so all arguments must outlive this call.
Expand Down
4 changes: 2 additions & 2 deletions source/extensions/common/wasm/wasm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <memory>
#include <string>
#include <vector>

#include "envoy/common/exception.h"
#include "envoy/config/wasm/v2/wasm.pb.validate.h"
Expand Down Expand Up @@ -1020,7 +1019,8 @@ void Wasm::getFunctions() {
}

Wasm::Wasm(const Wasm& wasm)
: cluster_manager_(wasm.cluster_manager_), dispatcher_(wasm.dispatcher_) {
: std::enable_shared_from_this<Wasm>(), cluster_manager_(wasm.cluster_manager_),
dispatcher_(wasm.dispatcher_) {
wasm_vm_ = wasm.wasmVm()->clone();
general_context_ = createContext();
getFunctions();
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/common/wasm/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class Wasm : public Envoy::Server::Wasm,
uint32_t next_context_id_ = 0;
std::unique_ptr<WasmVm> wasm_vm_;
std::shared_ptr<Context> general_context_; // Context unrelated to any specific stream.
std::function<void(Common::Wasm::Context*)> tick_;
std::function<void(Context*)> tick_;
std::chrono::milliseconds tick_period_;
Event::TimerPtr timer_;

Expand Down
4 changes: 2 additions & 2 deletions source/extensions/common/wasm/wavm/wavm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ Wavm::~Wavm() {
}

std::unique_ptr<WasmVm> Wavm::clone() {
auto wavm = new Wavm();
auto wavm = std::make_unique<Wavm>();
wavm->compartment_ = WAVM::Runtime::cloneCompartment(compartment_);
wavm->memory_ = WAVM::Runtime::remapToClonedCompartment(memory_, wavm->compartment_);
wavm->context_ = WAVM::Runtime::createContext(wavm->compartment_);
wavm->envoyModuleInstance_ =
WAVM::Runtime::remapToClonedCompartment(envoyModuleInstance_, wavm->compartment_);
wavm->moduleInstance_ =
WAVM::Runtime::remapToClonedCompartment(moduleInstance_, wavm->compartment_);
return std::unique_ptr<WasmVm>(wavm);
return wavm;
}

bool Wavm::initialize(const std::string& code, absl::string_view name, bool allow_precompiled) {
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/filters/http/wasm/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Wasm {
Http::FilterFactoryCb WasmFilterConfig::createFilterFactoryFromProtoTyped(
const envoy::config::filter::http::wasm::v2::Wasm& proto_config, const std::string&,
Server::Configuration::FactoryContext& context) {
FilterConfigConstSharedPtr filter_config(new FilterConfig{proto_config, context});
auto filter_config = std::make_shared<FilterConfig>(proto_config, context);
return [filter_config](Http::FilterChainFactoryCallbacks& callbacks) -> void {
auto filter = filter_config->createFilter();
callbacks.addStreamFilter(filter);
Expand Down
3 changes: 2 additions & 1 deletion source/extensions/filters/http/wasm/wasm_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ FilterConfig::FilterConfig(const envoy::config::filter::http::wasm::v2::Wasm& co
auto id = config.id();
auto configuration = std::make_shared<std::string>(config.configuration());
if (config.has_vm_config()) {
// Create a base WASM to verify that the code loads before setting/cloning the for the individual threads.
// Create a base WASM to verify that the code loads before setting/cloning the for the
// individual threads.
auto base_wasm = Common::Wasm::createWasm(id, config.vm_config(), context.clusterManager(),
context.dispatcher(), context.api());
// NB: the Slot set() call doesn't complete inline, so all arguments must outlive this call.
Expand Down
8 changes: 3 additions & 5 deletions source/extensions/filters/http/wasm/wasm_filter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <map>
#include <memory>

#include "envoy/config/filter/http/wasm/v2/wasm.pb.validate.h"
#include "envoy/http/filter.h"
Expand All @@ -18,10 +18,6 @@ namespace Wasm {
using Envoy::Extensions::Common::Wasm::Context;
using Envoy::Extensions::Common::Wasm::Wasm;

class FilterConfig;

typedef std::shared_ptr<FilterConfig> FilterConfigConstSharedPtr;

class FilterConfig : Logger::Loggable<Logger::Id::wasm> {
public:
FilterConfig(const envoy::config::filter::http::wasm::v2::Wasm& proto_config,
Expand All @@ -33,6 +29,8 @@ class FilterConfig : Logger::Loggable<Logger::Id::wasm> {
ThreadLocal::SlotPtr tls_slot_;
};

typedef std::shared_ptr<FilterConfig> FilterConfigSharedPtr;

} // namespace Wasm
} // namespace HttpFilters
} // namespace Extensions
Expand Down
3 changes: 2 additions & 1 deletion source/extensions/wasm/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ static const std::string INLINE_STRING = "<inline>";

Server::WasmSharedPtr WasmFactory::createWasm(const envoy::config::wasm::v2::WasmConfig& config,
Server::Configuration::WasmFactoryContext& context) {
// Create a base WASM to verify that the code loads before setting/cloning the for the individual threads.
// Create a base WASM to verify that the code loads before setting/cloning the for the individual
// threads.
auto base_wasm =
Common::Wasm::createWasm(config.id(), config.vm_config(), context.clusterManager(),
context.dispatcher(), context.api());
Expand Down