Commit 09323a6a authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Use activations of the interpreter in the fuzzers

Typically the interpreter returns 0xdeadbeef to indicate an exception.
However, for stack overflows a normal exception is used. The interpreter
requires an activation, however, to deal with normal exceptions. With
this CL we start an activation before we execute the fuzzer input in the
interpreter.

R=clemensh@chromium.org

Bug: chromium:781103
Change-Id: I4fc3a18bfc2076aab9ff7d2324a3311fe222954a
Reviewed-on: https://chromium-review.googlesource.com/776835
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49545}
parent 136b4edb
...@@ -89,10 +89,19 @@ bool InterpretWasmModuleForTesting(Isolate* isolate, ...@@ -89,10 +89,19 @@ bool InterpretWasmModuleForTesting(Isolate* isolate,
WasmInterpreter::HeapObjectsScope heap_objects_scope(interpreter, instance); WasmInterpreter::HeapObjectsScope heap_objects_scope(interpreter, instance);
WasmInterpreter::Thread* thread = interpreter->GetThread(0); WasmInterpreter::Thread* thread = interpreter->GetThread(0);
thread->Reset(); thread->Reset();
// Start an activation so that we can deal with stack overflows. We do not
// finish the activation. An activation is just part of the state of the
// interpreter, and we do not reuse the interpreter anyways. In addition,
// finishing the activation is not correct in all cases, e.g. when the
// execution of the interpreter did not finish after kMaxNumSteps.
thread->StartActivation();
thread->InitFrame(&instance->module()->functions[function_index], thread->InitFrame(&instance->module()->functions[function_index],
arguments.get()); arguments.get());
WasmInterpreter::State interpreter_result = thread->Run(kMaxNumSteps); WasmInterpreter::State interpreter_result = thread->Run(kMaxNumSteps);
isolate->clear_pending_exception();
return interpreter_result != WasmInterpreter::PAUSED; return interpreter_result != WasmInterpreter::PAUSED;
} }
...@@ -150,20 +159,30 @@ int32_t InterpretWasmModule(Isolate* isolate, ...@@ -150,20 +159,30 @@ int32_t InterpretWasmModule(Isolate* isolate,
WasmInterpreter::HeapObjectsScope heap_objects_scope(interpreter, instance); WasmInterpreter::HeapObjectsScope heap_objects_scope(interpreter, instance);
WasmInterpreter::Thread* thread = interpreter->GetThread(0); WasmInterpreter::Thread* thread = interpreter->GetThread(0);
thread->Reset(); thread->Reset();
// Start an activation so that we can deal with stack overflows. We do not
// finish the activation. An activation is just part of the state of the
// interpreter, and we do not reuse the interpreter anyways. In addition,
// finishing the activation is not correct in all cases, e.g. when the
// execution of the interpreter did not finish after kMaxNumSteps.
thread->StartActivation();
thread->InitFrame(&(instance->module()->functions[function_index]), args); thread->InitFrame(&(instance->module()->functions[function_index]), args);
WasmInterpreter::State interpreter_result = thread->Run(kMaxNumSteps); WasmInterpreter::State interpreter_result = thread->Run(kMaxNumSteps);
bool stack_overflow = isolate->has_pending_exception();
isolate->clear_pending_exception();
*possible_nondeterminism = thread->PossibleNondeterminism(); *possible_nondeterminism = thread->PossibleNondeterminism();
if (interpreter_result == WasmInterpreter::FINISHED) { if (stack_overflow) return 0xdeadbeef;
WasmValue val = thread->GetReturnValue();
return val.to<int32_t>(); if (thread->state() == WasmInterpreter::TRAPPED) return 0xdeadbeef;
} else if (thread->state() == WasmInterpreter::TRAPPED) {
return 0xdeadbeef; if (interpreter_result == WasmInterpreter::FINISHED)
} else { return thread->GetReturnValue().to<int32_t>();
thrower->RangeError( thrower->RangeError(
"Interpreter did not finish execution within its step bound"); "Interpreter did not finish execution within its step bound");
return -1; return -1;
}
} }
MaybeHandle<WasmExportedFunction> GetExportedFunction( MaybeHandle<WasmExportedFunction> GetExportedFunction(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment