Skip to content

Commit 04ab34d

Browse files
WIP fixing lit test
1 parent 12cb3ea commit 04ab34d

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

src/ir/import-utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ class ImportResolver {
138138
virtual RuntimeTable* getTableOrNull(ImportNames name,
139139
const Table& type) const = 0;
140140

141+
// TODO: this should probably be a const Tag
142+
// or maybe the member in the tag should be const.
141143
virtual Tag* getTagOrNull(ImportNames name, const Signature& type) const = 0;
142144
};
143145

src/tools/execution-results.h

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@ namespace wasm {
2525

2626
using Loggings = std::vector<Literal>;
2727

28+
const Tag& getWasmTag() {
29+
static const Tag tag = []() {
30+
Tag tag;
31+
tag.module = "fuzzing-support";
32+
tag.base = "wasmtag";
33+
tag.name = "imported-wasm-tag";
34+
tag.type = Signature(Type::i32, Type::none);
35+
36+
return tag;
37+
}();
38+
return tag;
39+
}
40+
41+
const Tag& getJsTag() {
42+
static const Tag tag = []() {
43+
Tag tag;
44+
tag.module = "fuzzing-support";
45+
tag.base = "jstag";
46+
tag.name = "imported-js-tag";
47+
tag.type = Signature(Type(HeapType::ext, Nullable), Type::none);
48+
return tag;
49+
}();
50+
return tag;
51+
}
52+
2853
// Logs every relevant import call parameter.
2954
struct LoggingExternalInterface : public ShellExternalInterface {
3055
private:
@@ -290,6 +315,27 @@ struct LoggingExternalInterface : public ShellExternalInterface {
290315
void setModuleRunner(ModuleRunner* instance_) { instance = instance_; }
291316
};
292317

318+
class FuzzerImportResolver
319+
: public LinkedInstancesImportResolver<ModuleRunner> {
320+
using LinkedInstancesImportResolver::LinkedInstancesImportResolver;
321+
Tag* getTagOrNull(ImportNames name, const Signature& type) const override {
322+
if (name.module != "fuzzing-support") {
323+
return nullptr;
324+
}
325+
if (name.name == "wasmtag") {
326+
return &wasmTag;
327+
}
328+
if (name.name == "jstag") {
329+
return &jsTag;
330+
}
331+
return nullptr;
332+
}
333+
334+
private:
335+
mutable Tag wasmTag = getWasmTag();
336+
mutable Tag jsTag = getJsTag();
337+
};
338+
293339
// gets execution results from a wasm module. this is useful for fuzzing
294340
//
295341
// we can only get results when there are no imports. we then call each method
@@ -310,7 +356,11 @@ struct ExecutionResults {
310356
try {
311357
// Instantiate the first module.
312358
LoggingExternalInterface interface(loggings, wasm);
313-
auto instance = std::make_shared<ModuleRunner>(wasm, &interface);
359+
// auto a = std::make_shared<FuzzerImportResolver>(std::map<Name,
360+
// std::shared_ptr<ModuleRunner>>());
361+
auto l = std::map<Name, std::shared_ptr<ModuleRunner>>();
362+
auto instance = std::make_shared<ModuleRunner>(
363+
wasm, &interface, l, std::make_shared<FuzzerImportResolver>(l));
314364
instantiate(*instance, interface);
315365

316366
// Instantiate the second, if there is one (we instantiate both before

src/wasm-interpreter.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5230,12 +5230,15 @@ class ModuleRunner : public ModuleRunnerBase<ModuleRunner> {
52305230
ModuleRunner(
52315231
Module& wasm,
52325232
ExternalInterface* externalInterface,
5233-
std::map<Name, std::shared_ptr<ModuleRunner>> linkedInstances = {})
5233+
std::map<Name, std::shared_ptr<ModuleRunner>> linkedInstances = {},
5234+
std::shared_ptr<ImportResolver> importResolver = nullptr)
52345235
: ModuleRunnerBase(
52355236
wasm,
52365237
externalInterface,
5237-
std::make_shared<LinkedInstancesImportResolver<ModuleRunner>>(
5238-
linkedInstances),
5238+
importResolver
5239+
? importResolver
5240+
: std::make_shared<LinkedInstancesImportResolver<ModuleRunner>>(
5241+
linkedInstances),
52395242
linkedInstances) {}
52405243

52415244
Literal makeFuncData(Name name, Type type) {

0 commit comments

Comments
 (0)