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-09-01 13:20:46 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
|
|
|
namespace fuzzer {
|
2017-08-09 08:11:21 +00:00
|
|
|
|
2017-05-08 09:22:54 +00:00
|
|
|
class WasmCodeFuzzer : public WasmExecutionFuzzer {
|
2017-09-04 10:05:10 +00:00
|
|
|
bool GenerateModule(
|
2018-07-12 09:05:43 +00:00
|
|
|
Isolate* isolate, Zone* zone, Vector<const uint8_t> data,
|
2017-05-08 09:22:54 +00:00
|
|
|
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());
|
2018-07-12 09:05:43 +00:00
|
|
|
f->EmitCode(data.start(), static_cast<uint32_t>(data.size()));
|
2017-05-08 09:22:54 +00:00
|
|
|
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
|
|
|
|
2017-08-29 08:47:47 +00:00
|
|
|
builder.SetMaxMemorySize(32);
|
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) {
|
2018-11-20 14:41:36 +00:00
|
|
|
WasmCodeFuzzer().FuzzWasmModule({data, size});
|
|
|
|
return 0;
|
2016-08-29 13:55:41 +00:00
|
|
|
}
|
2017-09-01 13:20:46 +00:00
|
|
|
|
|
|
|
} // namespace fuzzer
|
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|