2016-08-29 13:55:41 +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.
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "src/isolate.h"
|
2017-02-13 09:52:26 +00:00
|
|
|
#include "src/objects-inl.h"
|
2016-09-22 12:54:52 +00:00
|
|
|
#include "src/objects.h"
|
2016-09-12 12:26:37 +00:00
|
|
|
#include "src/wasm/wasm-interpreter.h"
|
2016-09-29 11:29:05 +00:00
|
|
|
#include "src/wasm/wasm-module-builder.h"
|
2016-10-05 11:59:47 +00:00
|
|
|
#include "test/common/wasm/test-signatures.h"
|
2017-05-08 09:22:54 +00:00
|
|
|
#include "test/fuzzer/wasm-fuzzer-common.h"
|
2016-09-22 12:54:52 +00:00
|
|
|
|
2017-08-09 08:11:21 +00:00
|
|
|
#if __clang__
|
|
|
|
// TODO(mostynb@opera.com): remove the using statements and these pragmas.
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wheader-hygiene"
|
|
|
|
#endif
|
|
|
|
|
2017-05-08 09:22:54 +00:00
|
|
|
using namespace v8::internal;
|
2016-09-12 12:26:37 +00:00
|
|
|
using namespace v8::internal::wasm;
|
2017-05-08 09:22:54 +00:00
|
|
|
using namespace v8::internal::wasm::fuzzer;
|
|
|
|
|
2017-08-09 08:11:21 +00:00
|
|
|
#if __clang__
|
|
|
|
// TODO(mostynb@opera.com): remove the using statements and these pragmas.
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
2017-05-08 09:22:54 +00:00
|
|
|
class WasmCodeFuzzer : public WasmExecutionFuzzer {
|
|
|
|
virtual bool GenerateModule(
|
|
|
|
Isolate* isolate, Zone* zone, const uint8_t* data, size_t size,
|
|
|
|
ZoneBuffer& buffer, int32_t& num_args,
|
2017-07-14 13:49:01 +00:00
|
|
|
std::unique_ptr<WasmValue[]>& interpreter_args,
|
2017-05-08 09:22:54 +00:00
|
|
|
std::unique_ptr<Handle<Object>[]>& compiler_args) override {
|
|
|
|
TestSignatures sigs;
|
|
|
|
WasmModuleBuilder builder(zone);
|
|
|
|
WasmFunctionBuilder* f = builder.AddFunction(sigs.i_iii());
|
|
|
|
f->EmitCode(data, static_cast<uint32_t>(size));
|
|
|
|
uint8_t end_opcode = kExprEnd;
|
|
|
|
f->EmitCode(&end_opcode, 1);
|
2017-05-12 11:06:25 +00:00
|
|
|
builder.AddExport(CStrVector("main"), f);
|
2017-05-08 09:22:54 +00:00
|
|
|
|
|
|
|
builder.WriteTo(buffer);
|
|
|
|
num_args = 3;
|
2017-07-14 13:49:01 +00:00
|
|
|
interpreter_args.reset(
|
|
|
|
new WasmValue[3]{WasmValue(1), WasmValue(2), WasmValue(3)});
|
2017-05-08 09:22:54 +00:00
|
|
|
|
|
|
|
compiler_args.reset(new Handle<Object>[3]{
|
2017-06-09 10:58:08 +00:00
|
|
|
handle(Smi::FromInt(1), isolate), handle(Smi::FromInt(2), isolate),
|
|
|
|
handle(Smi::FromInt(3), isolate)});
|
2017-05-08 09:22:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2016-09-12 12:26:37 +00:00
|
|
|
|
2016-08-29 13:55:41 +00:00
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
2017-05-08 09:22:54 +00:00
|
|
|
return WasmCodeFuzzer().FuzzWasmModule(data, size);
|
2016-08-29 13:55:41 +00:00
|
|
|
}
|