Skip to content

Commit

Permalink
[gin] Unify snapshot loading on Windows and other platforms.
Browse files Browse the repository at this point in the history
Removes extra v8 snapshot and natives validation on Windows. All platforms
have the same validation henceforth.

BUG=501799

Review-Url: https://codereview.chromium.org/2103903002
Cr-Commit-Position: refs/heads/master@{#403430}
  • Loading branch information
ohodson authored and Commit bot committed Jul 1, 2016
1 parent 9242e9a commit 10b5a96
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 260 deletions.
4 changes: 0 additions & 4 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,6 @@ group("both_gn_and_gyp") {
deps += [ "//components/policy:policy_templates" ]
}

if (v8_use_external_startup_data) {
deps += [ "//gin:gin_v8_snapshot_fingerprint" ]
}

if (is_win) {
deps += [
"//chrome/installer/gcapi",
Expand Down
1 change: 0 additions & 1 deletion build/gn_migration.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
'../content/content_shell_and_tests.gyp:content_unittests',
'../crypto/crypto.gyp:crypto_unittests',
'../device/device_tests.gyp:device_unittests',
'../gin/gin.gyp:gin_v8_snapshot_fingerprint',
'../gpu/gpu.gyp:angle_unittests',
'../gpu/gpu.gyp:gl_tests',
'../gpu/gpu.gyp:gpu_perftests',
Expand Down
35 changes: 0 additions & 35 deletions gin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ component("gin") {
"//base/third_party/dynamic_annotations",
"//crypto",
]
if (v8_use_external_startup_data && is_win) {
public_deps += [ ":gin_v8_snapshot_fingerprint" ]
sources += [ "$target_gen_dir/v8_snapshot_fingerprint.cc" ]
defines += [ "V8_VERIFY_EXTERNAL_STARTUP_DATA" ]
}

if (is_mac) {
libs = [ "CoreFoundation.framework" ]
Expand All @@ -99,36 +94,6 @@ component("gin") {
configs += [ "//v8:external_startup_data" ]
}

if (v8_use_external_startup_data) {
action("gin_v8_snapshot_fingerprint") {
script = "//gin/fingerprint/fingerprint_v8_snapshot.py"

snapshot_file = "$root_out_dir/snapshot_blob.bin"
natives_file = "$root_out_dir/natives_blob.bin"
output_file = "$target_gen_dir/v8_snapshot_fingerprint.cc"

args = [
"--snapshot_file",
rebase_path(snapshot_file, root_build_dir),
"--natives_file",
rebase_path(natives_file, root_build_dir),
"--output_file",
rebase_path(output_file, root_build_dir),
]
inputs = [
snapshot_file,
natives_file,
]
outputs = [
output_file,
]

deps = [
"//v8",
]
}
}

executable("gin_shell") {
sources = [
"shell/gin_main.cc",
Expand Down
47 changes: 0 additions & 47 deletions gin/fingerprint/fingerprint_v8_snapshot.gypi

This file was deleted.

86 changes: 0 additions & 86 deletions gin/fingerprint/fingerprint_v8_snapshot.py

This file was deleted.

24 changes: 0 additions & 24 deletions gin/gin.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,6 @@
'wrappable.h',
'wrapper_info.cc',
],
'conditions': [
['v8_use_external_startup_data==1 and OS=="win"', {
'dependencies': [
'gin_v8_snapshot_fingerprint',
'../crypto/crypto.gyp:crypto',
],
'sources': [
'<(gin_gen_path)/v8_snapshot_fingerprint.cc',
],
'defines': [
'V8_VERIFY_EXTERNAL_STARTUP_DATA',
]
}],
],
},
{
'target_name': 'gin_v8_snapshot_fingerprint',
'type': 'none',
'variables': {
'snapshot_file': '<(PRODUCT_DIR)/snapshot_blob.bin',
'natives_file': '<(PRODUCT_DIR)/natives_blob.bin',
'output_file': '<(gin_gen_path)/v8_snapshot_fingerprint.cc',
},
'includes': [ '../gin/fingerprint/fingerprint_v8_snapshot.gypi' ],
},
{
'target_name': 'gin_shell',
Expand Down
74 changes: 11 additions & 63 deletions gin/v8_initializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,36 +191,6 @@ static const OpenedFileMap::mapped_type OpenFileIfNecessary(
return opened;
}

#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
bool VerifyV8StartupFile(base::MemoryMappedFile** file,
const unsigned char* fingerprint) {
unsigned char output[crypto::kSHA256Length];
crypto::SHA256HashString(
base::StringPiece(reinterpret_cast<const char*>((*file)->data()),
(*file)->length()),
output, sizeof(output));
if (!memcmp(fingerprint, output, sizeof(output))) {
return true;
}

// TODO(oth): Remove this temporary diagnostics for http://crbug.com/501799
uint64_t input[sizeof(output)];
memcpy(input, fingerprint, sizeof(input));

base::debug::Alias(output);
base::debug::Alias(input);

const uint64_t* o64 = reinterpret_cast<const uint64_t*>(output);
const uint64_t* f64 = reinterpret_cast<const uint64_t*>(fingerprint);
LOG(FATAL) << "Natives length " << (*file)->length()
<< " H(computed) " << o64[0] << o64[1] << o64[2] << o64[3]
<< " H(expected) " << f64[0] << f64[1] << f64[2] << f64[3];

delete *file;
*file = NULL;
return false;
}
#endif // V8_VERIFY_EXTERNAL_STARTUP_DATA
#endif // V8_USE_EXTERNAL_STARTUP_DATA

bool GenerateEntropy(unsigned char* buffer, size_t amount) {
Expand All @@ -243,47 +213,37 @@ bool ShouldUseIgnition() {
} // namespace

#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
// Defined in gen/gin/v8_snapshot_fingerprint.cc
extern const unsigned char g_natives_fingerprint[];
extern const unsigned char g_snapshot_fingerprint[];
#endif // V8_VERIFY_EXTERNAL_STARTUP_DATA

namespace {

enum LoadV8FileResult {
V8_LOAD_SUCCESS = 0,
V8_LOAD_FAILED_OPEN,
V8_LOAD_FAILED_MAP,
V8_LOAD_FAILED_VERIFY,
V8_LOAD_FAILED_VERIFY, // Deprecated.
V8_LOAD_MAX_VALUE
};

static LoadV8FileResult MapVerify(const OpenedFileMap::mapped_type& file_region,
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
const unsigned char* fingerprint,
#endif
base::MemoryMappedFile** mmapped_file_out) {
LoadV8FileResult MapOpenedFile(
const OpenedFileMap::mapped_type& file_region,
base::MemoryMappedFile** mmapped_file_out) {
if (file_region.first == base::kInvalidPlatformFile)
return V8_LOAD_FAILED_OPEN;
if (!MapV8File(file_region.first, file_region.second, mmapped_file_out))
return V8_LOAD_FAILED_MAP;
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
if (!VerifyV8StartupFile(mmapped_file_out, fingerprint))
return V8_LOAD_FAILED_VERIFY;
#endif // V8_VERIFY_EXTERNAL_STARTUP_DATA
return V8_LOAD_SUCCESS;
}

} // namespace

// static
void V8Initializer::LoadV8Snapshot() {
if (g_mapped_snapshot)
return;

OpenFileIfNecessary(kSnapshotFileName);
LoadV8FileResult result = MapVerify(GetOpenedFile(kSnapshotFileName),
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
g_snapshot_fingerprint,
#endif
&g_mapped_snapshot);
LoadV8FileResult result = MapOpenedFile(GetOpenedFile(kSnapshotFileName),
&g_mapped_snapshot);
// V8 can't start up without the source of the natives, but it can
// start up (slower) without the snapshot.
UMA_HISTOGRAM_ENUMERATION("V8.Initializer.LoadV8Snapshot.Result", result,
Expand All @@ -295,10 +255,7 @@ void V8Initializer::LoadV8Natives() {
return;

OpenFileIfNecessary(kNativesFileName);
LoadV8FileResult result = MapVerify(GetOpenedFile(kNativesFileName),
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
g_natives_fingerprint,
#endif
LoadV8FileResult result = MapOpenedFile(GetOpenedFile(kNativesFileName),
&g_mapped_natives);
if (result != V8_LOAD_SUCCESS) {
LOG(FATAL) << "Couldn't mmap v8 natives data file, status code is "
Expand Down Expand Up @@ -326,10 +283,6 @@ void V8Initializer::LoadV8SnapshotFromFD(base::PlatformFile snapshot_pf,
LoadV8FileResult result = V8_LOAD_SUCCESS;
if (!MapV8File(snapshot_pf, snapshot_region, &g_mapped_snapshot))
result = V8_LOAD_FAILED_MAP;
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
if (!VerifyV8StartupFile(&g_mapped_snapshot, g_snapshot_fingerprint))
result = V8_LOAD_FAILED_VERIFY;
#endif // V8_VERIFY_EXTERNAL_STARTUP_DATA
if (result == V8_LOAD_SUCCESS) {
g_opened_files.Get()[kSnapshotFileName] =
std::make_pair(snapshot_pf, snapshot_region);
Expand Down Expand Up @@ -357,11 +310,6 @@ void V8Initializer::LoadV8NativesFromFD(base::PlatformFile natives_pf,
if (!MapV8File(natives_pf, natives_region, &g_mapped_natives)) {
LOG(FATAL) << "Couldn't mmap v8 natives data file";
}
#if defined(V8_VERIFY_EXTERNAL_STARTUP_DATA)
if (!VerifyV8StartupFile(&g_mapped_natives, g_natives_fingerprint)) {
LOG(FATAL) << "Couldn't verify contents of v8 natives data file";
}
#endif // V8_VERIFY_EXTERNAL_STARTUP_DATA
g_opened_files.Get()[kNativesFileName] =
std::make_pair(natives_pf, natives_region);
}
Expand Down

0 comments on commit 10b5a96

Please sign in to comment.