OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 "src/startup-data-util.h" | 5 #include "src/startup-data-util.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "src/base/logging.h" | 10 #include "src/base/logging.h" |
11 #include "src/base/platform/platform.h" | 11 #include "src/base/platform/platform.h" |
| 12 #include "src/utils.h" |
12 | 13 |
13 | 14 |
14 namespace v8 { | 15 namespace v8 { |
15 namespace internal { | 16 namespace internal { |
16 | 17 |
17 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 18 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 v8::StartupData g_natives; | 22 v8::StartupData g_natives; |
(...skipping 15 matching lines...) Expand all Loading... |
37 void FreeStartupData() { | 38 void FreeStartupData() { |
38 DeleteStartupData(&g_natives); | 39 DeleteStartupData(&g_natives); |
39 DeleteStartupData(&g_snapshot); | 40 DeleteStartupData(&g_snapshot); |
40 } | 41 } |
41 | 42 |
42 | 43 |
43 void Load(const char* blob_file, v8::StartupData* startup_data, | 44 void Load(const char* blob_file, v8::StartupData* startup_data, |
44 void (*setter_fn)(v8::StartupData*)) { | 45 void (*setter_fn)(v8::StartupData*)) { |
45 ClearStartupData(startup_data); | 46 ClearStartupData(startup_data); |
46 | 47 |
47 if (!blob_file) return; | 48 CHECK(blob_file); |
48 | 49 |
49 FILE* file = fopen(blob_file, "rb"); | 50 FILE* file = fopen(blob_file, "rb"); |
50 if (!file) return; | 51 if (!file) { |
| 52 PrintF(stderr, "Failed to open startup resource '%s'.\n", blob_file); |
| 53 return; |
| 54 } |
51 | 55 |
52 fseek(file, 0, SEEK_END); | 56 fseek(file, 0, SEEK_END); |
53 startup_data->raw_size = static_cast<int>(ftell(file)); | 57 startup_data->raw_size = static_cast<int>(ftell(file)); |
54 rewind(file); | 58 rewind(file); |
55 | 59 |
56 startup_data->data = new char[startup_data->raw_size]; | 60 startup_data->data = new char[startup_data->raw_size]; |
57 int read_size = static_cast<int>(fread(const_cast<char*>(startup_data->data), | 61 int read_size = static_cast<int>(fread(const_cast<char*>(startup_data->data), |
58 1, startup_data->raw_size, file)); | 62 1, startup_data->raw_size, file)); |
59 fclose(file); | 63 fclose(file); |
60 | 64 |
61 if (startup_data->raw_size == read_size) (*setter_fn)(startup_data); | 65 if (startup_data->raw_size == read_size) { |
| 66 (*setter_fn)(startup_data); |
| 67 } else { |
| 68 PrintF(stderr, "Corrupted startup resource '%s'.\n", blob_file); |
| 69 } |
62 } | 70 } |
63 | 71 |
64 | 72 |
65 void LoadFromFiles(const char* natives_blob, const char* snapshot_blob) { | 73 void LoadFromFiles(const char* natives_blob, const char* snapshot_blob) { |
66 Load(natives_blob, &g_natives, v8::V8::SetNativesDataBlob); | 74 Load(natives_blob, &g_natives, v8::V8::SetNativesDataBlob); |
67 Load(snapshot_blob, &g_snapshot, v8::V8::SetSnapshotDataBlob); | 75 Load(snapshot_blob, &g_snapshot, v8::V8::SetSnapshotDataBlob); |
68 | 76 |
69 atexit(&FreeStartupData); | 77 atexit(&FreeStartupData); |
70 } | 78 } |
71 | 79 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 116 |
109 void InitializeExternalStartupData(const char* natives_blob, | 117 void InitializeExternalStartupData(const char* natives_blob, |
110 const char* snapshot_blob) { | 118 const char* snapshot_blob) { |
111 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 119 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
112 LoadFromFiles(natives_blob, snapshot_blob); | 120 LoadFromFiles(natives_blob, snapshot_blob); |
113 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 121 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
114 } | 122 } |
115 | 123 |
116 } // namespace internal | 124 } // namespace internal |
117 } // namespace v8 | 125 } // namespace v8 |
OLD | NEW |