2016-09-12 12:26:37 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef V8_WASM_MODULE_RUNNER_H_
|
|
|
|
#define V8_WASM_MODULE_RUNNER_H_
|
|
|
|
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/execution/isolate.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects.h"
|
2016-09-12 12:26:37 +00:00
|
|
|
#include "src/wasm/wasm-module.h"
|
2016-11-16 16:17:22 +00:00
|
|
|
#include "src/wasm/wasm-objects.h"
|
2016-09-12 12:26:37 +00:00
|
|
|
#include "src/wasm/wasm-result.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2017-01-27 13:53:13 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class Handle;
|
|
|
|
|
2018-04-27 13:38:40 +00:00
|
|
|
template <typename T>
|
|
|
|
class MaybeHandle;
|
|
|
|
|
2016-09-12 12:26:37 +00:00
|
|
|
namespace wasm {
|
|
|
|
namespace testing {
|
|
|
|
|
2017-09-07 09:48:34 +00:00
|
|
|
// Returns a MaybeHandle to the JsToWasm wrapper of the wasm function exported
|
|
|
|
// with the given name by the provided instance.
|
2017-10-11 12:52:26 +00:00
|
|
|
MaybeHandle<WasmExportedFunction> GetExportedFunction(
|
|
|
|
Isolate* isolate, Handle<WasmInstanceObject> instance, const char* name);
|
2017-09-07 09:48:34 +00:00
|
|
|
|
[wasm] Use pending exceptions consistently
In our internal code, we should only use pending exceptions. They will
be converted to scheduled exceptions on the API boundary.
Hence, the ErrorThrower just sets a pending exception; it should never
have to think about scheduled exceptions. The new
ScheduledErrorThrower inherits from ErrorThrower and reschedules any
pending exceptions in its destructor (turning them into scheduled
exceptions).
In some situations, there might already be a scheduled exception, e.g.
when calling other API methods (v8::Value::Get). In this case, the
ErrorThrower should also not set another pending exception. For the
reasons mentioned above, this can only be handled in the
ScheduledErrorThrower, which is used the API methods.
This fixes one DCHECK failure and one TODO about scheduled exceptions
if no instance can be created, because the start function throws.
R=mtrofin@chromium.org, mstarzinger@chromium.org
BUG=v8:6232,chromium:736256
Change-Id: I4905be04c565df9495de18fb26adbb5c05d193d2
Reviewed-on: https://chromium-review.googlesource.com/548641
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46314}
2017-06-29 08:16:29 +00:00
|
|
|
// Call an exported wasm function by name. Returns -1 if the export does not
|
|
|
|
// exist or throws an error. Errors are cleared from the isolate before
|
2020-08-18 08:14:25 +00:00
|
|
|
// returning. {exception} is set to to true if an exception happened during
|
|
|
|
// execution of the wasm function.
|
2017-10-11 12:52:26 +00:00
|
|
|
int32_t CallWasmFunctionForTesting(Isolate* isolate,
|
|
|
|
Handle<WasmInstanceObject> instance,
|
2020-08-11 08:48:31 +00:00
|
|
|
const char* name, int argc,
|
2020-08-18 08:14:25 +00:00
|
|
|
Handle<Object> argv[],
|
|
|
|
bool* exception = nullptr);
|
2016-09-12 12:26:37 +00:00
|
|
|
|
|
|
|
// Decode, verify, and run the function labeled "main" in the
|
|
|
|
// given encoded module. The module should have no imports.
|
|
|
|
int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start,
|
2017-06-09 18:37:54 +00:00
|
|
|
const byte* module_end);
|
|
|
|
|
2019-04-17 17:55:36 +00:00
|
|
|
// Decode and compile the given module with no imports.
|
|
|
|
MaybeHandle<WasmModuleObject> CompileForTesting(Isolate* isolate,
|
|
|
|
ErrorThrower* thrower,
|
|
|
|
const ModuleWireBytes& bytes);
|
|
|
|
|
2018-01-18 10:52:52 +00:00
|
|
|
// Decode, compile, and instantiate the given module with no imports.
|
|
|
|
MaybeHandle<WasmInstanceObject> CompileAndInstantiateForTesting(
|
|
|
|
Isolate* isolate, ErrorThrower* thrower, const ModuleWireBytes& bytes);
|
|
|
|
|
2018-11-20 14:39:29 +00:00
|
|
|
class WasmInterpretationResult {
|
|
|
|
public:
|
2020-08-10 14:20:01 +00:00
|
|
|
static WasmInterpretationResult Failed() { return {kFailed, 0, false}; }
|
2018-11-20 14:39:29 +00:00
|
|
|
static WasmInterpretationResult Trapped(bool possible_nondeterminism) {
|
|
|
|
return {kTrapped, 0, possible_nondeterminism};
|
|
|
|
}
|
|
|
|
static WasmInterpretationResult Finished(int32_t result,
|
|
|
|
bool possible_nondeterminism) {
|
|
|
|
return {kFinished, result, possible_nondeterminism};
|
|
|
|
}
|
|
|
|
|
2020-08-10 14:20:01 +00:00
|
|
|
// {failed()} captures different reasons: The module was invalid, no function
|
|
|
|
// to call was found in the module, the function did not termine within a
|
|
|
|
// limited number of steps, or a stack overflow happened.
|
|
|
|
bool failed() const { return status_ == kFailed; }
|
2018-11-20 14:39:29 +00:00
|
|
|
bool trapped() const { return status_ == kTrapped; }
|
|
|
|
bool finished() const { return status_ == kFinished; }
|
|
|
|
|
|
|
|
int32_t result() const {
|
|
|
|
DCHECK_EQ(status_, kFinished);
|
|
|
|
return result_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool possible_nondeterminism() const { return possible_nondeterminism_; }
|
|
|
|
|
|
|
|
private:
|
2020-08-10 14:20:01 +00:00
|
|
|
enum Status { kFinished, kTrapped, kFailed };
|
2018-11-20 14:39:29 +00:00
|
|
|
|
|
|
|
const Status status_;
|
|
|
|
const int32_t result_;
|
|
|
|
const bool possible_nondeterminism_;
|
|
|
|
|
|
|
|
WasmInterpretationResult(Status status, int32_t result,
|
|
|
|
bool possible_nondeterminism)
|
|
|
|
: status_(status),
|
|
|
|
result_(result),
|
|
|
|
possible_nondeterminism_(possible_nondeterminism) {}
|
|
|
|
};
|
|
|
|
|
2016-09-12 12:26:37 +00:00
|
|
|
// Interprets the given module, starting at the function specified by
|
|
|
|
// {function_index}. The return type of the function has to be int32. The module
|
|
|
|
// should not have any imports or exports
|
2018-11-20 14:39:29 +00:00
|
|
|
WasmInterpretationResult InterpretWasmModule(
|
|
|
|
Isolate* isolate, Handle<WasmInstanceObject> instance,
|
|
|
|
int32_t function_index, WasmValue* args);
|
2016-09-17 01:30:09 +00:00
|
|
|
|
2020-08-26 12:53:24 +00:00
|
|
|
// Generate an array of default arguments for the given signature, to be used in
|
|
|
|
// the interpreter.
|
2021-06-17 15:43:55 +00:00
|
|
|
base::OwnedVector<WasmValue> MakeDefaultInterpreterArguments(
|
|
|
|
Isolate* isolate, const FunctionSig* sig);
|
2020-08-26 12:53:24 +00:00
|
|
|
|
|
|
|
// Generate an array of default arguments for the given signature, to be used
|
|
|
|
// when calling compiled code. Make sure that the arguments match the ones
|
|
|
|
// returned by {MakeDefaultInterpreterArguments}, otherwise fuzzers will report
|
|
|
|
// differences between interpreter and compiled code.
|
2021-06-17 15:43:55 +00:00
|
|
|
base::OwnedVector<Handle<Object>> MakeDefaultArguments(Isolate* isolate,
|
|
|
|
const FunctionSig* sig);
|
2020-08-10 14:20:01 +00:00
|
|
|
|
2016-09-17 01:30:09 +00:00
|
|
|
// Install function map, module symbol for testing
|
|
|
|
void SetupIsolateForWasmModule(Isolate* isolate);
|
2017-06-12 11:13:15 +00:00
|
|
|
|
2016-09-12 12:26:37 +00:00
|
|
|
} // namespace testing
|
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_WASM_MODULE_RUNNER_H_
|