Skip to content

Commit f783ebf

Browse files
Fuzzing: Update FuzzTranslator to instantiate modules explicitly
1 parent 65ed01b commit f783ebf

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

FuzzTesting/Sources/FuzzTranslator/FuzzTranslator.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,27 @@ public func FuzzCheck(_ start: UnsafePointer<UInt8>, _ count: Int) -> CInt {
55
let bytes = Array(UnsafeBufferPointer(start: start, count: count))
66
do {
77
var module = try WasmKit.parseWasm(bytes: bytes)
8-
try module.materializeAll()
8+
let engine = Engine(configuration: EngineConfiguration(compilationMode: .eager))
9+
let store = Store(engine: engine)
10+
var imports = Imports()
11+
for importEntry in module.imports {
12+
let value: ExternalValueConvertible
13+
switch importEntry.descriptor {
14+
case .function(let typeIndex):
15+
let type = module.types[Int(typeIndex)]
16+
value = Function(store: store, type: type) { _, _ in
17+
fatalError("unreachable")
18+
}
19+
case .global(let globalType):
20+
value = try Global(store: store, type: globalType, value: .i32(0))
21+
case .memory(let memoryType):
22+
value = try Memory(store: store, type: memoryType)
23+
case .table(let tableType):
24+
value = try Table(store: store, type: tableType)
25+
}
26+
imports.define(module: importEntry.module, name: importEntry.name, value.externalValue)
27+
}
28+
_ = try module.instantiate(store: store, imports: imports)
929
} catch {
1030
// Ignore errors
1131
}

Sources/WasmKit/Module.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,8 @@ public struct Module {
227227
}
228228

229229
/// Materialize lazily-computed elements in this module
230-
public mutating func materializeAll() throws {
231-
let allocator = ISeqAllocator()
232-
let funcTypeInterner = Interner<FunctionType>()
233-
for function in functions {
234-
_ = try function.compile(module: self, funcTypeInterner: funcTypeInterner, allocator: allocator)
235-
}
236-
}
230+
@available(*, deprecated, message: "Module materialization is no longer supported. Instantiate the module explicitly instead.")
231+
public mutating func materializeAll() throws {}
237232
}
238233

239234
extension Module {
@@ -275,8 +270,4 @@ typealias LabelIndex = UInt32
275270
struct GuestFunction {
276271
let type: FunctionType
277272
let code: Code
278-
279-
func compile(module: Module, funcTypeInterner: Interner<FunctionType>, allocator: ISeqAllocator) throws -> InstructionSequence {
280-
throw TranslationError("Compile without instantiation is no longer supported")
281-
}
282273
}

0 commit comments

Comments
 (0)