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
16 changes: 14 additions & 2 deletions src/wasmtime/wasmtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <cassert>
#include <cstring>
#include <limits>
#include <memory>
#include <optional>
#include <string>
Expand Down Expand Up @@ -56,7 +57,11 @@ using ::wasmtime::Table;
using ::wasmtime::TrapResult;

Engine *engine() {
static auto *const engine = []() { return new Engine(Config{}); }();
static auto *const engine = []() {
Config config;
config.epoch_interruption(true);
return new Engine(std::move(config));
}();
return engine;
}

Expand Down Expand Up @@ -121,7 +126,7 @@ class Wasmtime : public WasmVm {

void warm() override;

void terminate() override {}
void terminate() override { engine()->increment_epoch(); }

bool usesWasmByteOrder() override { return true; }

Expand Down Expand Up @@ -160,6 +165,11 @@ void Wasmtime::initStore() {
return;
}
store_.emplace(*engine());
store_->limiter(PROXY_WASM_HOST_MAX_WASM_MEMORY_SIZE_BYTES,
/*table_elements=*/10000,
/*instances=*/1,
/*tables=*/10000,
/*memories=*/1);
}

bool Wasmtime::load(std::string_view bytecode, std::string_view /*precompiled*/,
Expand Down Expand Up @@ -354,6 +364,7 @@ void Wasmtime::getModuleFunctionImpl(std::string_view function_name,
")");
}
InPlaceConvertHostToWasmEndianness(args...);
store_->context().set_epoch_deadline(1);
TrapResult<std::monostate> result = func.call(store_->context(), {args...});
if (!result) {
fail(FailState::RuntimeError,
Expand Down Expand Up @@ -387,6 +398,7 @@ void Wasmtime::getModuleFunctionImpl(std::string_view function_name,
")");
}
InPlaceConvertHostToWasmEndianness(args...);
store_->context().set_epoch_deadline(1);
TrapResult<R> result_wasm = func.call(store_->context(), {args...});
if (!result_wasm) {
fail(FailState::RuntimeError,
Expand Down
10 changes: 7 additions & 3 deletions test/runtime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ TEST_P(TestVm, StraceLogLevel) {

TEST_P(TestVm, TerminateExecution) {
// TODO(chaoqin-li1123): implement execution termination for other runtime.
if (engine_ != "v8") {
if (engine_ != "v8" && engine_ != "wasmtime") {
return;
}
auto source = readTestWasmFile("resource_limits.wasm");
Expand All @@ -102,12 +102,16 @@ TEST_P(TestVm, TerminateExecution) {
// Check integration logs.
auto *host = dynamic_cast<TestIntegration *>(wasm.wasm_vm()->integration().get());
EXPECT_TRUE(host->isErrorLogged("Function: infinite_loop failed"));
EXPECT_TRUE(host->isErrorLogged("TerminationException"));
if (engine_ == "v8") {
EXPECT_TRUE(host->isErrorLogged("TerminationException"));
} else if (engine_ == "wasmtime") {
EXPECT_TRUE(host->isErrorLogged("wasm trap: interrupt"));
}
Comment thread
leonm1 marked this conversation as resolved.
}

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