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" |
| 14 |
13 namespace v8_fuzzer { | 15 namespace v8_fuzzer { |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 FuzzerSupport* g_fuzzer_support = nullptr; | 19 FuzzerSupport* g_fuzzer_support = nullptr; |
18 | 20 |
19 void DeleteFuzzerSupport() { | 21 void DeleteFuzzerSupport() { |
20 if (g_fuzzer_support) { | 22 if (g_fuzzer_support) { |
21 delete g_fuzzer_support; | 23 delete g_fuzzer_support; |
22 g_fuzzer_support = nullptr; | 24 g_fuzzer_support = nullptr; |
23 } | 25 } |
24 } | 26 } |
25 | 27 |
26 } // namespace | 28 } // namespace |
27 | 29 |
28 class FuzzerSupport::ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 30 class FuzzerSupport::ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
29 public: | 31 public: |
30 virtual void* Allocate(size_t length) { | 32 virtual void* Allocate(size_t length) { |
31 void* data = AllocateUninitialized(length); | 33 void* data = AllocateUninitialized(length); |
32 return data == NULL ? data : memset(data, 0, length); | 34 return data == NULL ? data : memset(data, 0, length); |
33 } | 35 } |
34 virtual void* AllocateUninitialized(size_t length) { return malloc(length); } | 36 virtual void* AllocateUninitialized(size_t length) { return malloc(length); } |
35 virtual void Free(void* data, size_t) { free(data); } | 37 virtual void Free(void* data, size_t) { free(data); } |
36 }; | 38 }; |
37 | 39 |
38 FuzzerSupport::FuzzerSupport(int* argc, char*** argv) { | 40 FuzzerSupport::FuzzerSupport(int* argc, char*** argv) { |
| 41 v8::internal::FLAG_expose_gc = true; |
39 v8::V8::SetFlagsFromCommandLine(argc, *argv, true); | 42 v8::V8::SetFlagsFromCommandLine(argc, *argv, true); |
40 v8::V8::InitializeICU(); | 43 v8::V8::InitializeICU(); |
41 v8::V8::InitializeExternalStartupData((*argv)[0]); | 44 v8::V8::InitializeExternalStartupData((*argv)[0]); |
42 platform_ = v8::platform::CreateDefaultPlatform(); | 45 platform_ = v8::platform::CreateDefaultPlatform(); |
43 v8::V8::InitializePlatform(platform_); | 46 v8::V8::InitializePlatform(platform_); |
44 v8::V8::Initialize(); | 47 v8::V8::Initialize(); |
45 | 48 |
46 allocator_ = new ArrayBufferAllocator; | 49 allocator_ = new ArrayBufferAllocator; |
47 v8::Isolate::CreateParams create_params; | 50 v8::Isolate::CreateParams create_params; |
48 create_params.array_buffer_allocator = allocator_; | 51 create_params.array_buffer_allocator = allocator_; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 return handle_scope.Escape(context); | 94 return handle_scope.Escape(context); |
92 } | 95 } |
93 | 96 |
94 } // namespace v8_fuzzer | 97 } // namespace v8_fuzzer |
95 | 98 |
96 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { | 99 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { |
97 v8_fuzzer::g_fuzzer_support = new v8_fuzzer::FuzzerSupport(argc, argv); | 100 v8_fuzzer::g_fuzzer_support = new v8_fuzzer::FuzzerSupport(argc, argv); |
98 atexit(&v8_fuzzer::DeleteFuzzerSupport); | 101 atexit(&v8_fuzzer::DeleteFuzzerSupport); |
99 return 0; | 102 return 0; |
100 } | 103 } |
OLD | NEW |