Skip to content

Commit d9412bd

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
[wasm] Support more reference types in tag signatures
Change-Id: Ieeb8dab3eb77426d35414a5d24345ffdc51107c1 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/8447736 Reviewed-by: Manos Koukoutos <[email protected]> Commit-Queue: Matthias Liedtke <[email protected]> Reviewed-by: Carl Smith <[email protected]>
1 parent 73b6641 commit d9412bd

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

Sources/Fuzzilli/Base/ProgramBuilder.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3926,9 +3926,16 @@ public class ProgramBuilder {
39263926
}
39273927

39283928
public func randomTagParameters() -> [ILType] {
3929-
// TODO(mliedtke): The list of types should be shared with function signature generation etc.
3930-
return (0..<Int.random(in: 0...10)).map {_ in chooseUniform(from:
3931-
[.wasmi32, .wasmi64, .wasmf32, .wasmf64, .wasmFuncRef, .wasmExnRef, .wasmExternRef, .wasmI31Ref, .wasmSimd128])}
3929+
// TODO(mliedtke): The list of types should be shared with function signature generation
3930+
// etc. We should also support non-nullable references but that requires being able
3931+
// to generate valid ones which currently isn't the case for most of them.
3932+
return (0..<Int.random(in: 0...10)).map {_ in chooseUniform(from: [
3933+
// Value types:
3934+
.wasmi32, .wasmi64, .wasmf32, .wasmf64, .wasmSimd128,
3935+
// Subset of abstract heap types (the null (bottom) types are not allowed in the JS API):
3936+
.wasmExternRef, .wasmFuncRef, .wasmAnyRef, .wasmEqRef, .wasmI31Ref, .wasmStructRef,
3937+
.wasmArrayRef, .wasmExnRef
3938+
])}
39323939
}
39333940

39343941
public func randomWasmSignature() -> WasmSignature {

Sources/Fuzzilli/FuzzIL/TypeSystem.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ public struct ILType: Hashable {
229229
public static let wasmFuncRef = ILType.wasmRef(.Abstract(.WasmFunc), nullability: true)
230230
public static let wasmExnRef = ILType.wasmRef(.Abstract(.WasmExn), nullability: true)
231231
public static let wasmI31Ref = ILType.wasmRef(.Abstract(.WasmI31), nullability: true)
232+
public static let wasmAnyRef = ILType.wasmRef(.Abstract(.WasmAny), nullability: true)
233+
public static let wasmEqRef = ILType.wasmRef(.Abstract(.WasmEq), nullability: true)
234+
public static let wasmStructRef = ILType.wasmRef(.Abstract(.WasmStruct), nullability: true)
235+
public static let wasmArrayRef = ILType.wasmRef(.Abstract(.WasmArray), nullability: true)
232236
public static let wasmRefI31 = ILType.wasmRef(.Abstract(.WasmI31), nullability: false)
233237
public static let wasmSimd128 = ILType(definiteType: .wasmSimd128)
234238
public static let wasmGenericRef = ILType(definiteType: .wasmRef)

Sources/Fuzzilli/Lifting/JavaScriptLifter.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,8 +1539,6 @@ public class JavaScriptLifter: Lifter {
15391539
let LET = w.varKeyword
15401540
let types = op.parameterTypes.map {type in
15411541
switch(type) {
1542-
case .wasmExternRef:
1543-
return "\"externref\""
15441542
case .wasmf32:
15451543
return "\"f32\""
15461544
case .wasmf64:
@@ -1551,12 +1549,23 @@ public class JavaScriptLifter: Lifter {
15511549
return "\"i64\""
15521550
case .wasmSimd128:
15531551
return "\"v128\""
1552+
case .wasmExternRef:
1553+
return "\"externref\""
15541554
case .wasmFuncRef:
15551555
return "\"anyfunc\""
1556-
case .wasmExnRef:
1557-
return "\"exnref\""
1556+
case .wasmAnyRef:
1557+
return "\"anyref\""
1558+
case .wasmEqRef:
1559+
return "\"eqref\""
15581560
case .wasmI31Ref:
15591561
return "\"i31ref\""
1562+
case .wasmStructRef:
1563+
return "\"structref\""
1564+
case .wasmArrayRef:
1565+
return "\"arrayref\""
1566+
case .wasmExnRef:
1567+
return "\"exnref\""
1568+
15601569
default:
15611570
fatalError("Unhandled wasm type \(type)")
15621571
}

Tests/FuzzilliTests/WasmTests.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3642,18 +3642,23 @@ class WasmFoundationTests: XCTestCase {
36423642
try tagExportedToDifferentWasmModule(defineInWasm: false)
36433643
}
36443644

3645-
// Test that defining a Wasm tag in JS with a funcref in its parameter types does not fail.
3646-
func testTagFuncRefInJS() throws {
3645+
// Test that defining a Wasm tag in JS with all supported abstract ref types does not fail.
3646+
func testTagAllRefTypesInJS() throws {
36473647
let runner = try GetJavaScriptExecutorOrSkipTest(type: .any, withArguments: ["--experimental-wasm-exnref"])
36483648
let liveTestConfig = Configuration(logLevel: .error, enableInspection: true)
36493649
let fuzzer = makeMockFuzzer(config: liveTestConfig, environment: JavaScriptEnvironment())
36503650
let b = fuzzer.makeBuilder()
3651-
b.createWasmTag(parameterTypes: [.wasmFuncRef])
3651+
// Assumption: All types but the bottom (null) types are supported in the JS API.
3652+
let supportedTypes = WasmAbstractHeapType.allCases.filter {!$0.isBottom()}.map { heapType in
3653+
ILType.wasmRef(.Abstract(heapType), nullability:true)
3654+
}
3655+
b.createWasmTag(parameterTypes: supportedTypes)
36523656
let prog = b.finalize()
36533657
let jsProg = fuzzer.lifter.lift(prog, withOptions: [.includeComments])
36543658
// The "funcref" type name is only available with the reflection proposal. Otherwise the
36553659
// name has to be "anyfunc".
36563660
XCTAssert(jsProg.contains("\"anyfunc\""))
3661+
// We just expect the JS execution not throwing an exception.
36573662
testForOutput(program: jsProg, runner: runner, outputString: "")
36583663
}
36593664

0 commit comments

Comments
 (0)