diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 685c56edf..a9bf70566 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -172,7 +172,7 @@ jobs: os: ubuntu-20.04 arch: x86_64 action: test - flags: --config=clang + flags: --config=clang -c opt - name: 'Wasmtime on Linux/x86_64 with ASan' engine: 'wasmtime' repo: 'com_github_bytecodealliance_wasmtime' diff --git a/src/v8/v8.cc b/src/v8/v8.cc index dc9555494..dea883252 100644 --- a/src/v8/v8.cc +++ b/src/v8/v8.cc @@ -586,6 +586,8 @@ void V8::getModuleFunctionImpl(std::string_view function_name, const bool log = cmpLogLevel(LogLevel::trace); SaveRestoreContext saved_context(context); wasm::own trap = nullptr; + + // Workaround for MSVC++ not supporting zero-sized arrays. if constexpr (sizeof...(args) > 0) { wasm::Val params[] = {makeVal(args)...}; if (log) { @@ -599,6 +601,7 @@ void V8::getModuleFunctionImpl(std::string_view function_name, } trap = func->call(nullptr, nullptr); } + if (trap) { fail(FailState::RuntimeError, getFailMessage(std::string(function_name), std::move(trap))); return; @@ -635,6 +638,8 @@ void V8::getModuleFunctionImpl(std::string_view function_name, SaveRestoreContext saved_context(context); wasm::Val results[1]; wasm::own trap = nullptr; + + // Workaround for MSVC++ not supporting zero-sized arrays. if constexpr (sizeof...(args) > 0) { wasm::Val params[] = {makeVal(args)...}; if (log) { @@ -648,6 +653,7 @@ void V8::getModuleFunctionImpl(std::string_view function_name, } trap = func->call(nullptr, results); } + if (trap) { fail(FailState::RuntimeError, getFailMessage(std::string(function_name), std::move(trap))); return R{}; diff --git a/src/wasmtime/wasmtime.cc b/src/wasmtime/wasmtime.cc index 4bbc32b5f..06f4f0e3c 100644 --- a/src/wasmtime/wasmtime.cc +++ b/src/wasmtime/wasmtime.cc @@ -591,21 +591,28 @@ void Wasmtime::getModuleFunctionImpl(std::string_view function_name, } *function = [func, function_name, this](ContextBase *context, Args... args) -> void { - wasm_val_vec_t params; + const bool log = cmpLogLevel(LogLevel::trace); + SaveRestoreContext saved_context(context); + wasm_val_vec_t results = WASM_EMPTY_VEC; + WasmTrapPtr trap; + + // Workaround for MSVC++ not supporting zero-sized arrays. if constexpr (sizeof...(args) > 0) { wasm_val_t params_arr[] = {makeVal(args)...}; - params = WASM_ARRAY_VEC(params_arr); + wasm_val_vec_t params = WASM_ARRAY_VEC(params_arr); + if (log) { + integration()->trace("[host->vm] " + std::string(function_name) + "(" + + printValues(¶ms) + ")"); + } + trap.reset(wasm_func_call(func, ¶ms, &results)); } else { - params = WASM_EMPTY_VEC; - } - wasm_val_vec_t results = WASM_EMPTY_VEC; - const bool log = cmpLogLevel(LogLevel::trace); - if (log) { - integration()->trace("[host->vm] " + std::string(function_name) + "(" + printValues(¶ms) + - ")"); + wasm_val_vec_t params = WASM_EMPTY_VEC; + if (log) { + integration()->trace("[host->vm] " + std::string(function_name) + "()"); + } + trap.reset(wasm_func_call(func, ¶ms, &results)); } - SaveRestoreContext saved_context(context); - WasmTrapPtr trap{wasm_func_call(func, ¶ms, &results)}; + if (trap) { WasmByteVec error_message; wasm_trap_message(trap.get(), error_message.get()); @@ -645,22 +652,29 @@ void Wasmtime::getModuleFunctionImpl(std::string_view function_name, } *function = [func, function_name, this](ContextBase *context, Args... args) -> R { - wasm_val_vec_t params; + const bool log = cmpLogLevel(LogLevel::trace); + SaveRestoreContext saved_context(context); + wasm_val_t results_arr[1]; + wasm_val_vec_t results = WASM_ARRAY_VEC(results_arr); + WasmTrapPtr trap; + + // Workaround for MSVC++ not supporting zero-sized arrays. if constexpr (sizeof...(args) > 0) { wasm_val_t params_arr[] = {makeVal(args)...}; - params = WASM_ARRAY_VEC(params_arr); + wasm_val_vec_t params = WASM_ARRAY_VEC(params_arr); + if (log) { + integration()->trace("[host->vm] " + std::string(function_name) + "(" + + printValues(¶ms) + ")"); + } + trap.reset(wasm_func_call(func, ¶ms, &results)); } else { - params = WASM_EMPTY_VEC; - } - wasm_val_t results_arr[1]; - wasm_val_vec_t results = WASM_ARRAY_VEC(results_arr); - const bool log = cmpLogLevel(LogLevel::trace); - if (log) { - integration()->trace("[host->vm] " + std::string(function_name) + "(" + printValues(¶ms) + - ")"); + wasm_val_vec_t params = WASM_EMPTY_VEC; + if (log) { + integration()->trace("[host->vm] " + std::string(function_name) + "()"); + } + trap.reset(wasm_func_call(func, ¶ms, &results)); } - SaveRestoreContext saved_context(context); - WasmTrapPtr trap{wasm_func_call(func, ¶ms, &results)}; + if (trap) { WasmByteVec error_message; wasm_trap_message(trap.get(), error_message.get());