Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: test/common/wasm/wasm-module-runner.cc

Issue 2341673002: [wasm] Allocate memory for the wasm interpreter in the fuzzer. (Closed)
Patch Set: Delete stale code. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/common/wasm/wasm-module-runner.cc
diff --git a/test/common/wasm/wasm-module-runner.cc b/test/common/wasm/wasm-module-runner.cc
index 008149fb6c62b9a7ffd47dbb95db5f369a74badb..22b6b035fdd29f74e6499c833bd3f1655f669857 100644
--- a/test/common/wasm/wasm-module-runner.cc
+++ b/test/common/wasm/wasm-module-runner.cc
@@ -110,34 +110,43 @@ int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower& thrower,
if (thrower.error()) return -1;
- WasmModuleInstance instance(module);
- instance.context = isolate->native_context();
- instance.mem_size = GetMinModuleMemSize(module);
- instance.mem_start = nullptr;
- instance.globals_start = nullptr;
-
ModuleEnv module_env;
module_env.module = module;
- module_env.instance = &instance;
module_env.origin = module->origin;
- const WasmFunction* function = &(module->functions[function_index]);
-
- FunctionBody body = {&module_env, function->sig, module->module_start,
- module->module_start + function->code_start_offset,
- module->module_start + function->code_end_offset};
- DecodeResult result = VerifyWasmCode(isolate->allocator(), body);
- if (result.failed()) {
- thrower.Error("Function did not verify");
- return -1;
+ for (size_t i = 0; i < module->functions.size(); i++) {
+ FunctionBody body = {
+ &module_env, module->functions[i].sig, module->module_start,
+ module->module_start + module->functions[i].code_start_offset,
+ module->module_start + module->functions[i].code_end_offset};
+ DecodeResult result = VerifyWasmCode(isolate->allocator(), body);
+ if (result.failed()) {
+ thrower.Error("Function did not verify");
+ return -1;
+ }
}
+ // The code verifies, we create an instance to run it in the interpreter.
+ WasmModuleInstance instance(module);
+ instance.context = isolate->native_context();
+ instance.mem_size = GetMinModuleMemSize(module);
+ // TODO(ahaas): Move memory allocation to wasm-module.cc for better
+ // encapsulation.
+ instance.mem_start =
+ static_cast<byte*>(calloc(GetMinModuleMemSize(module), 1));
+ instance.globals_start = nullptr;
+ module_env.instance = &instance;
+
WasmInterpreter interpreter(&instance, isolate->allocator());
WasmInterpreter::Thread* thread = interpreter.GetThread(0);
thread->Reset();
- thread->PushFrame(function, args);
- if (thread->Run() == WasmInterpreter::FINISHED) {
+ thread->PushFrame(&(module->functions[function_index]), args);
+ WasmInterpreter::State interpreter_result = thread->Run();
+ if (instance.mem_start) {
+ free(instance.mem_start);
+ }
+ if (interpreter_result == WasmInterpreter::FINISHED) {
WasmVal val = thread->GetReturnValue();
return val.to<int32_t>();
} else if (thread->state() == WasmInterpreter::TRAPPED) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698