@@ -38,7 +38,7 @@ class Wasm3Engine final : public WasmEngine
3838
3939namespace
4040{
41- const void * env_adler32 (IM3Runtime /* runtime*/ , uint64_t * stack, void * mem)
41+ const void * env_adler32 (IM3Runtime /* runtime*/ , uint64_t * stack, void * mem, void * /* userdata */ )
4242{
4343 const uint32_t offset = static_cast <uint32_t >(stack[0 ]);
4444 const uint32_t length = static_cast <uint32_t >(stack[1 ]);
@@ -115,20 +115,33 @@ std::optional<WasmEngine::FuncRef> Wasm3Engine::find_function(
115115{
116116 IM3Function function;
117117 if (m3_FindFunction (&function, m_runtime, name.data ()) == m3Err_none)
118+ // TODO: validate input/output types
119+ // (m3_GetArgCount/m3_GetArgType/m3_GetRetCount/m3_GetRetType)
118120 return reinterpret_cast <WasmEngine::FuncRef>(function);
119121 return std::nullopt ;
120122}
121123
122124WasmEngine::Result Wasm3Engine::execute (
123125 WasmEngine::FuncRef func_ref, const std::vector<uint64_t >& args)
124126{
125- unsigned ret_valid;
126- uint64_t ret_value;
127127 IM3Function function = reinterpret_cast <IM3Function>(func_ref);
128- auto const result = m3_CallProper (
129- function, static_cast <uint32_t >(args.size ()), args.data (), &ret_valid, &ret_value);
128+
129+ std::vector<const void *> argPtrs;
130+ for (auto const & arg : args)
131+ argPtrs.push_back (&arg);
132+
133+ // This ensures input count/type matches. For the return value we assume find_function did the
134+ // validation.
135+ auto const result = m3_Call (function, static_cast <uint32_t >(args.size ()), argPtrs.data ());
130136 if (result == m3Err_none)
131- return {false , ret_valid ? ret_value : std::optional<uint64_t >{}};
137+ {
138+ if (m3_GetRetCount (function) == 0 )
139+ return {false , std::nullopt };
140+
141+ uint64_t ret_value = 0 ;
142+ assert (m3_GetResultsV (function, &ret_value) == m3Err_none);
143+ return {false , ret_value};
144+ }
132145 return {true , std::nullopt };
133146}
134147} // namespace fizzy::test
0 commit comments