-
Notifications
You must be signed in to change notification settings - Fork 816
[Exceptions] Fix cross-module Tag handling in interpreter #7955
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
Changes from all commits
3bc8a54
403269c
1e98549
18acf83
6b45a18
167cc41
2b5a6d7
08827ee
7cd8db0
b876369
9bbdfe7
7047703
fbcfc9c
ac39b5f
d13eca9
dda230b
046fec3
0eb9913
360f53f
0b94658
5b32bee
c0a8436
d764d4c
6678d81
1c0e0af
c51dcb2
f4e39fd
a0d9732
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 |
---|---|---|
|
@@ -42,13 +42,11 @@ struct LoggingExternalInterface : public ShellExternalInterface { | |
Name exportedTable; | ||
Module& wasm; | ||
|
||
// The name of the imported fuzzing tag for wasm. | ||
Name wasmTag; | ||
// The imported fuzzing tag for wasm. | ||
Tag wasmTag; | ||
|
||
// The name of the imported tag for js exceptions. If it is not imported, we | ||
// use a default name here (which should differentiate it from any wasm | ||
// exceptions). | ||
Name jsTag = "__private"; | ||
// The imported tag for js exceptions. | ||
Tag jsTag; | ||
|
||
// The ModuleRunner and this ExternalInterface end up needing links both ways, | ||
// so we cannot init this in the constructor. | ||
|
@@ -67,15 +65,26 @@ struct LoggingExternalInterface : public ShellExternalInterface { | |
} | ||
} | ||
|
||
for (auto& tag : wasm.tags) { | ||
if (tag->module == "fuzzing-support") { | ||
if (tag->base == "wasmtag") { | ||
wasmTag = tag->name; | ||
} else if (tag->base == "jstag") { | ||
jsTag = tag->name; | ||
} | ||
// Set up tags. (Setting these values is useful for debugging - making the | ||
// Tag objects valid - and also appears in fuzz-exec logging.) | ||
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. We should also need to set the type of the tags to make them valid. Hopefully the fuzzer can find that. 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. Added, can't hurt for debugging. I'm not sure if we notice these atm enough for the fuzzer to. |
||
wasmTag.module = "fuzzing-support"; | ||
wasmTag.base = "wasmtag"; | ||
wasmTag.name = "imported-wasm-tag"; | ||
wasmTag.type = Signature(Type::i32, Type::none); | ||
|
||
jsTag.module = "fuzzing-support"; | ||
jsTag.base = "jstag"; | ||
jsTag.name = "imported-js-tag"; | ||
jsTag.type = Signature(Type(HeapType::ext, Nullable), Type::none); | ||
} | ||
|
||
Tag* getImportedTag(Tag* tag) override { | ||
for (auto* imported : {&wasmTag, &jsTag}) { | ||
if (imported->module == tag->module && imported->base == tag->base) { | ||
return imported; | ||
} | ||
} | ||
Fatal() << "missing host tag " << tag->module << '.' << tag->base; | ||
} | ||
|
||
Literal getImportedFunction(Function* import) override { | ||
|
@@ -122,7 +131,7 @@ struct LoggingExternalInterface : public ShellExternalInterface { | |
if (arguments[0].geti32() == 0) { | ||
throwJSException(); | ||
} else { | ||
auto payload = std::make_shared<ExnData>(wasmTag, arguments); | ||
auto payload = std::make_shared<ExnData>(&wasmTag, arguments); | ||
throwException(WasmException{Literal(payload)}); | ||
} | ||
} else if (import->base == "table-get") { | ||
|
@@ -213,7 +222,7 @@ struct LoggingExternalInterface : public ShellExternalInterface { | |
auto empty = HeapType(Struct{}); | ||
auto inner = Literal(std::make_shared<GCData>(empty, Literals{}), empty); | ||
Literals arguments = {inner.externalize()}; | ||
auto payload = std::make_shared<ExnData>(jsTag, arguments); | ||
auto payload = std::make_shared<ExnData>(&jsTag, arguments); | ||
throwException(WasmException{Literal(payload)}); | ||
} | ||
|
||
|
tlively marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
;; RUN: wasm-opt %s -all --fuzz-exec-before --fuzz-exec-second=%s.second -q -o /dev/null 2>&1 | filecheck %s | ||
|
||
;; Define a tag in this module, and another tag in the secondary module, with | ||
;; the same name but different (incompatible) contents. The second module will | ||
;; call our export, and when we throw our tag, it should not catch it. | ||
|
||
(module | ||
(tag $tag (param structref)) | ||
|
||
(export "primary-tag" (tag $tag)) | ||
|
||
(func $func (export "func") (result i32) | ||
(throw $tag | ||
(ref.null struct) | ||
) | ||
) | ||
) | ||
|
||
;; CHECK: [fuzz-exec] calling func | ||
;; CHECK-NEXT: [exception thrown: tag nullref] | ||
;; CHECK-NEXT: [fuzz-exec] calling func2-internal | ||
;; CHECK-NEXT: [exception thrown: tag nullref] | ||
;; CHECK-NEXT: [fuzz-exec] calling func2-imported | ||
;; CHECK-NEXT: func2-imported => null | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
(module | ||
(import "primary" "func" (func $import (result i32))) | ||
|
||
(import "primary" "primary-tag" (tag $ptag (param structref))) | ||
|
||
(tag $tag (param (ref array))) | ||
|
||
(func $func2-internal (export "func2-internal") (result (ref array)) | ||
;; Try to catch the internal tag. This fails to catch. | ||
(block $block (result (ref array)) | ||
(try_table (catch $tag $block) | ||
(drop | ||
(call $import) | ||
) | ||
) | ||
(unreachable) | ||
) | ||
) | ||
|
||
(func $func2-imported (export "func2-imported") (result structref) | ||
;; Try to catch the imported tag. This successfully catches. | ||
(block $block (result structref) | ||
(try_table (catch $ptag $block) | ||
(drop | ||
(call $import) | ||
) | ||
) | ||
(unreachable) | ||
) | ||
) | ||
) | ||
|
Uh oh!
There was an error while loading. Please reload this page.