Repository navigation
Trap on argument count mismatch in DefinedFunc::DoCall #2866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,6 +174,21 @@ TEST_F(InterpTest, Fac) { | |
| EXPECT_EQ(120u, results[0].Get<u32>()); | ||
| } | ||
|
|
||
| TEST_F(InterpTest, CallArgCountMismatch) { | ||
| ReadModule(s_fac_module); | ||
| Instantiate(); | ||
| auto func = GetFuncExport(0); | ||
|
|
||
| // Calling the one-parameter export with no arguments must trap rather than | ||
| // read past the end of the params vector. | ||
| Values results; | ||
| Trap::Ptr trap; | ||
| Result result = func->Call(store_, {}, results, &trap); | ||
|
|
||
| ASSERT_EQ(Result::Error, result); | ||
| ASSERT_TRUE(trap); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this test not be written as a normal text-based test? Binary encoded tests like these should be avoided where possible I think.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tried that first, but a text spec test can't reach this path. wast2json validates invoke arity, so
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dropped the new blob. The test now reuses the existing Re-checked the text route before doing that. |
||
| } | ||
|
|
||
| TEST_F(InterpTest, Fac_Trace) { | ||
| ReadModule(s_fac_module); | ||
| Instantiate(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this is the hot path? I mean every call goes through this path? If this affect user code only, maybe adding something higher level would be better. I know this interpreter is testing only, but still.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the hot path. Traced it before adding the check:
call,call_indirect,call_refandreturn_call*all route throughThread::DoCall(interp.cc:2198). For aDefinedFuncthat only doesPushCall, so it never entersDefinedFunc::DoCall.DefinedFunc::DoCallis reached solely from the twoFunc::Calloverloads, i.e. the embedder boundary. In tree that's spectest-interp'sRunAction, wasm-interp, the C API and the wasi start call.So it costs one size comparison per external call, next to a
Threadconstruction and a params copy, and nothing per in-wasm call. Behaviour inside the interpreter loop is untouched.On moving it higher:
DefinedFunc::DoCallis already the single funnel for bothFunc::Calloverloads. Putting the check inFunc::Callwould mean duplicating it across both (theThread&overload is the one re-entrant host callbacks use) or leaving one unguarded. Happy to move it up if you'd prefer that shape.