Skip to content

Commit 6bac790

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
[wasm] Add code generator producing an exnref
The WasmThrowRefGenerator requires an exnref as an input. Without having a generator that produces it, it isn't very likely that there is an exnref available in the current program, so the generator cannot be run in most cases. Registering a generator producing that exnref (if a tag is available) helps significantly. Change-Id: Idbd9337f5a7339d58fe1f76e264569907f7081ce Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/9123976 Auto-Submit: Matthias Liedtke <mliedtke@google.com> Reviewed-by: Manos Koukoutos <manoskouk@google.com> Commit-Queue: Manos Koukoutos <manoskouk@google.com>
1 parent 2ae06c9 commit 6bac790

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ public let codeGeneratorWeights = [
324324
"WasmLegacyTryDelegateGenerator": 8,
325325
"WasmThrowGenerator": 2,
326326
"WasmLegacyRethrowGenerator": 10,
327+
// This generator is mostly just there, so that the WasmThrowRefGenerator
328+
// can create an exnref on demand (if a wasm tag is present).
329+
"WasmCreateExnRefGenerator": 1,
327330
"WasmThrowRefGenerator": 6,
328331
"WasmBranchGenerator": 6,
329332
"WasmBranchIfGenerator": 6,

Sources/Fuzzilli/CodeGen/WasmCodeGenerators.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,30 @@ public let WasmCodeGenerators: [CodeGenerator] = [
16201620
function.wasmBuildLegacyRethrow(exception)
16211621
},
16221622

1623+
CodeGenerator(
1624+
"WasmCreateExnRefGenerator", inContext: .single(.wasmFunction),
1625+
inputs: .required(.object(ofGroup: "WasmTag")),
1626+
produces: [.wasmExnRef()]
1627+
) { b, tag in
1628+
let function = b.currentWasmModule.currentWasmFunction
1629+
let tagType = b.type(of: tag).wasmTagType!
1630+
guard !tagType.isJSTag else {
1631+
// We can't throw a JSTag, so simply create a null value.
1632+
function.wasmRefNull(type: .wasmExnRef())
1633+
return
1634+
}
1635+
// Create a try-catch throwing and catching a tag producing an exnref as
1636+
// a result.
1637+
function.wasmBuildBlockWithResults(with: [] => (tagType.parameters + [.wasmExnRef()]), args: []) { label, _ in
1638+
let args = tagType.parameters.map(function.findOrGenerateWasmVar)
1639+
function.wasmBuildTryTable(with: [] => [], args: [tag, label], catches: [.Ref]) { _, _ in
1640+
function.WasmBuildThrow(tag: tag, inputs: args)
1641+
return []
1642+
}
1643+
return args + [function.wasmRefNull(type: .wasmExnRef())]
1644+
}
1645+
},
1646+
16231647
CodeGenerator(
16241648
"WasmThrowRefGenerator", inContext: .single(.wasmFunction),
16251649
inputs: .required(.wasmExnRef())

Tests/FuzzilliTests/ProgramBuilderTest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,6 +3125,7 @@ class ProgramBuilderTests: XCTestCase {
31253125
test("WasmStructNewDefaultGenerator", expectAny: WasmStructNewDefault.self)
31263126
test("WasmArrayGetGenerator", expectAny: WasmArrayGet.self, requiresTypes: true)
31273127
test("WasmStructGetGenerator", expectAny: WasmStructGet.self, requiresTypes: true)
3128+
test("WasmThrowRefGenerator", expectAny: WasmThrowRef.self)
31283129
}
31293130

31303131
func testThatGeneratorsExistAndAreBuildableFromJs() {

0 commit comments

Comments
 (0)