diff options
-rwxr-xr-x | auto_update_tests.py | 2 | ||||
-rwxr-xr-x | check.py | 2 | ||||
-rw-r--r-- | src/shell-interface.h | 4 | ||||
-rw-r--r-- | src/tools/wasm-ctor-eval.cpp | 5 | ||||
-rw-r--r-- | src/wasm-interpreter.h | 3 | ||||
-rw-r--r-- | test/ctor-eval/bad-indirect-call3.wast | 16 | ||||
-rw-r--r-- | test/ctor-eval/bad-indirect-call3.wast.ctors | 1 | ||||
-rw-r--r-- | test/ctor-eval/bad-indirect-call3.wast.out | 22 | ||||
-rw-r--r-- | test/spec/call_indirect_sig_mismatch.wast | 14 |
9 files changed, 66 insertions, 3 deletions
diff --git a/auto_update_tests.py b/auto_update_tests.py index 8bb8362ae..563323752 100755 --- a/auto_update_tests.py +++ b/auto_update_tests.py @@ -273,7 +273,7 @@ def update_ctor_eval_tests(): for t in shared.get_tests(shared.get_test_dir('ctor-eval'), ['.wast', '.wasm']): print('..', os.path.basename(t)) ctors = open(t + '.ctors').read().strip() - cmd = shared.WASM_CTOR_EVAL + [t, '-o', 'a.wast', '-S', '--ctors', ctors] + cmd = shared.WASM_CTOR_EVAL + [t, '-all', '-o', 'a.wast', '-S', '--ctors', ctors] support.run_command(cmd) actual = open('a.wast').read() out = t + '.out' @@ -240,7 +240,7 @@ def run_ctor_eval_tests(): for t in shared.get_tests(shared.get_test_dir('ctor-eval'), ['.wast', '.wasm']): print('..', os.path.basename(t)) ctors = open(t + '.ctors').read().strip() - cmd = shared.WASM_CTOR_EVAL + [t, '-o', 'a.wat', '-S', '--ctors', ctors] + cmd = shared.WASM_CTOR_EVAL + [t, '-all', '-o', 'a.wat', '-S', '--ctors', ctors] support.run_command(cmd) actual = open('a.wat').read() out = t + '.out' diff --git a/src/shell-interface.h b/src/shell-interface.h index f1b68ab60..03b190626 100644 --- a/src/shell-interface.h +++ b/src/shell-interface.h @@ -150,6 +150,7 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { } Literal callTable(Index index, + Signature sig, LiteralList& arguments, Type results, ModuleInstance& instance) override { @@ -160,6 +161,9 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { if (!func) { trap("uninitialized table element"); } + if (sig != func->sig) { + trap("callIndirect: function signatures don't match"); + } const std::vector<Type>& params = func->sig.params.expand(); if (params.size() != arguments.size()) { trap("callIndirect: bad # of arguments"); diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index b45c624a4..3aef10cf0 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -215,6 +215,7 @@ struct CtorEvalExternalInterface : EvallingModuleInstance::ExternalInterface { } Literal callTable(Index index, + Signature sig, LiteralList& arguments, Type result, EvallingModuleInstance& instance) override { @@ -240,6 +241,10 @@ struct CtorEvalExternalInterface : EvallingModuleInstance::ExternalInterface { // if this is one of our functions, we can call it; if it was imported, // fail auto* func = wasm->getFunction(name); + if (func->sig != sig) { + throw FailToEvalException( + std::string("callTable signature mismatch: ") + name.str); + } if (!func->imported()) { return instance.callFunctionInternal(name, arguments); } else { diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index cf5908adf..cbed38b2f 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -1188,6 +1188,7 @@ public: virtual void importGlobals(GlobalManager& globals, Module& wasm) = 0; virtual Literal callImport(Function* import, LiteralList& arguments) = 0; virtual Literal callTable(Index index, + Signature sig, LiteralList& arguments, Type result, SubType& instance) = 0; @@ -1575,7 +1576,7 @@ private: Index index = target.value.geti32(); Type type = curr->isReturn ? scope.function->sig.results : curr->type; Flow ret = instance.externalInterface->callTable( - index, arguments, type, *instance.self()); + index, curr->sig, arguments, type, *instance.self()); // TODO: make this a proper tail call (return first) if (curr->isReturn) { Const c; diff --git a/test/ctor-eval/bad-indirect-call3.wast b/test/ctor-eval/bad-indirect-call3.wast new file mode 100644 index 000000000..cadff8097 --- /dev/null +++ b/test/ctor-eval/bad-indirect-call3.wast @@ -0,0 +1,16 @@ +(module + (type $funcref_=>_none (func (param funcref))) + (memory 256 256) + (data (i32.const 10) "waka waka waka waka waka") + (table funcref (elem $callee)) + (export "sig_mismatch" (func $sig_mismatch)) + (func $callee (param $0 exnref) + (i32.store8 (i32.const 40) (i32.const 67)) + ) + (func $sig_mismatch + (call_indirect (type $funcref_=>_none) ;; unsafe to call, signature mismatch + (ref.null) + (i32.const 0) + ) + ) +) diff --git a/test/ctor-eval/bad-indirect-call3.wast.ctors b/test/ctor-eval/bad-indirect-call3.wast.ctors new file mode 100644 index 000000000..363ce3a3c --- /dev/null +++ b/test/ctor-eval/bad-indirect-call3.wast.ctors @@ -0,0 +1 @@ +sig_mismatch diff --git a/test/ctor-eval/bad-indirect-call3.wast.out b/test/ctor-eval/bad-indirect-call3.wast.out new file mode 100644 index 000000000..ec1d2adf6 --- /dev/null +++ b/test/ctor-eval/bad-indirect-call3.wast.out @@ -0,0 +1,22 @@ +(module + (type $none_=>_none (func)) + (type $funcref_=>_none (func (param funcref))) + (type $exnref_=>_none (func (param exnref))) + (memory $0 256 256) + (data (i32.const 10) "waka waka waka waka waka") + (table $0 1 1 funcref) + (elem (i32.const 0) $callee) + (export "sig_mismatch" (func $sig_mismatch)) + (func $callee (; 0 ;) (param $0 exnref) + (i32.store8 + (i32.const 40) + (i32.const 67) + ) + ) + (func $sig_mismatch (; 1 ;) + (call_indirect (type $funcref_=>_none) + (ref.null) + (i32.const 0) + ) + ) +) diff --git a/test/spec/call_indirect_sig_mismatch.wast b/test/spec/call_indirect_sig_mismatch.wast new file mode 100644 index 000000000..15e5d6a5a --- /dev/null +++ b/test/spec/call_indirect_sig_mismatch.wast @@ -0,0 +1,14 @@ +(module + (type $funcref_=>_none (func (param funcref))) + (table funcref (elem $callee)) + (export "sig_mismatch" (func $sig_mismatch)) + (func $callee (param $0 exnref)) + (func $sig_mismatch + (call_indirect (type $funcref_=>_none) + (ref.null) + (i32.const 0) + ) + ) +) + +(assert_trap (invoke "sig_mismatch") "callIndirect: function signatures don't match") |