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
5 changes: 5 additions & 0 deletions src/wasmtime/wasmtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ std::unique_ptr<WasmVm> Wasmtime::clone() {
}

clone->store_.emplace(Store(*engine()));
clone->store_->limiter(options_.max_wasm_memory_size_bytes,
/*table_elements=*/10000,
/*instances=*/1,
/*tables=*/10000,
/*memories=*/1);
if (!clone->store_.has_value()) {
return nullptr;
}
Expand Down
36 changes: 36 additions & 0 deletions test/runtime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,42 @@ TEST_P(TestVm, WasmMemoryLimit) {
}
}

TEST_P(TestVm, WasmMemoryLimitClone) {
// TODO(PiotrSikora): enforce memory limits in other engines.
if (engine_ != "v8" && engine_ != "wasmtime") {
return;
}
auto source = readTestWasmFile("resource_limits.wasm");
ASSERT_FALSE(source.empty());

auto base_wasm = std::make_shared<TestWasm>(std::move(vm_));
ASSERT_TRUE(base_wasm->load(source, false));
auto base_wasm_handle = std::make_shared<WasmHandleBase>(base_wasm);

TestWasm wasm(base_wasm_handle, [this]() { return makeVm(engine_); });
ASSERT_TRUE(wasm.initialize());

WasmCallVoid<0> infinite_memory;
wasm.wasm_vm()->getFunction("infinite_memory", &infinite_memory);
ASSERT_TRUE(infinite_memory != nullptr);
infinite_memory(wasm.vm_context());

EXPECT_GE(wasm.wasm_vm()->getMemorySize(), PROXY_WASM_HOST_MAX_WASM_MEMORY_SIZE_BYTES * 0.95);
EXPECT_LE(wasm.wasm_vm()->getMemorySize(), PROXY_WASM_HOST_MAX_WASM_MEMORY_SIZE_BYTES);

// Check integration logs.
auto *host = dynamic_cast<TestIntegration *>(wasm.wasm_vm()->integration().get());
EXPECT_TRUE(host->isErrorLogged("Function: infinite_memory failed"));
// Trap message
EXPECT_TRUE(host->isErrorLogged("unreachable"));
// Backtrace
if (engine_ == "v8") {
EXPECT_TRUE(host->isErrorLogged("Proxy-Wasm plugin in-VM backtrace:"));
EXPECT_TRUE(host->isErrorLogged("rust_oom"));
EXPECT_TRUE(host->isErrorLogged(" - alloc::alloc::handle_alloc_error"));
}
}

#if defined(PROXY_WASM_HOST_ENGINE_WASMTIME)
TEST_P(TestVm, WasmMemoryLimitCustomOption) {
if (engine_ != "wasmtime") {
Expand Down
Loading