OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "test/fuzzer/fuzzer-support.h" | 5 #include "test/fuzzer/fuzzer-support.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
11 #include "include/libplatform/libplatform.h" | 11 #include "include/libplatform/libplatform.h" |
12 | 12 |
13 #include "src/flags.h" | 13 #include "src/flags.h" |
14 | 14 |
15 namespace v8_fuzzer { | 15 namespace v8_fuzzer { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 FuzzerSupport* g_fuzzer_support = nullptr; | 19 FuzzerSupport* g_fuzzer_support = nullptr; |
20 | 20 |
21 void DeleteFuzzerSupport() { | 21 void DeleteFuzzerSupport() { |
22 if (g_fuzzer_support) { | 22 if (g_fuzzer_support) { |
23 delete g_fuzzer_support; | 23 delete g_fuzzer_support; |
24 g_fuzzer_support = nullptr; | 24 g_fuzzer_support = nullptr; |
25 } | 25 } |
26 } | 26 } |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 class FuzzerSupport::ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | |
31 public: | |
32 virtual void* Allocate(size_t length) { | |
33 void* data = AllocateUninitialized(length); | |
34 return data == NULL ? data : memset(data, 0, length); | |
35 } | |
36 virtual void* AllocateUninitialized(size_t length) { return malloc(length); } | |
37 virtual void Free(void* data, size_t) { free(data); } | |
38 }; | |
39 | |
40 FuzzerSupport::FuzzerSupport(int* argc, char*** argv) { | 30 FuzzerSupport::FuzzerSupport(int* argc, char*** argv) { |
41 v8::internal::FLAG_expose_gc = true; | 31 v8::internal::FLAG_expose_gc = true; |
42 v8::V8::SetFlagsFromCommandLine(argc, *argv, true); | 32 v8::V8::SetFlagsFromCommandLine(argc, *argv, true); |
43 v8::V8::InitializeICUDefaultLocation((*argv)[0]); | 33 v8::V8::InitializeICUDefaultLocation((*argv)[0]); |
44 v8::V8::InitializeExternalStartupData((*argv)[0]); | 34 v8::V8::InitializeExternalStartupData((*argv)[0]); |
45 platform_ = v8::platform::CreateDefaultPlatform(); | 35 platform_ = v8::platform::CreateDefaultPlatform(); |
46 v8::V8::InitializePlatform(platform_); | 36 v8::V8::InitializePlatform(platform_); |
47 v8::V8::Initialize(); | 37 v8::V8::Initialize(); |
48 | 38 |
49 allocator_ = new ArrayBufferAllocator; | 39 allocator_ = v8::ArrayBuffer::Allocator::NewDefaultAllocator(); |
50 v8::Isolate::CreateParams create_params; | 40 v8::Isolate::CreateParams create_params; |
51 create_params.array_buffer_allocator = allocator_; | 41 create_params.array_buffer_allocator = allocator_; |
52 isolate_ = v8::Isolate::New(create_params); | 42 isolate_ = v8::Isolate::New(create_params); |
53 | 43 |
54 { | 44 { |
55 v8::Isolate::Scope isolate_scope(isolate_); | 45 v8::Isolate::Scope isolate_scope(isolate_); |
56 v8::HandleScope handle_scope(isolate_); | 46 v8::HandleScope handle_scope(isolate_); |
57 context_.Reset(isolate_, v8::Context::New(isolate_)); | 47 context_.Reset(isolate_, v8::Context::New(isolate_)); |
58 } | 48 } |
59 } | 49 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 return handle_scope.Escape(context); | 85 return handle_scope.Escape(context); |
96 } | 86 } |
97 | 87 |
98 } // namespace v8_fuzzer | 88 } // namespace v8_fuzzer |
99 | 89 |
100 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { | 90 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { |
101 v8_fuzzer::g_fuzzer_support = new v8_fuzzer::FuzzerSupport(argc, argv); | 91 v8_fuzzer::g_fuzzer_support = new v8_fuzzer::FuzzerSupport(argc, argv); |
102 atexit(&v8_fuzzer::DeleteFuzzerSupport); | 92 atexit(&v8_fuzzer::DeleteFuzzerSupport); |
103 return 0; | 93 return 0; |
104 } | 94 } |
OLD | NEW |