@@ -25,6 +25,31 @@ namespace wasm {
2525
2626using 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.
2954struct LoggingExternalInterface : public ShellExternalInterface {
3055private:
@@ -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
0 commit comments