Commit bbbb6e38 authored by Joe Laughlin's avatar Joe Laughlin Committed by Commit Bot

Fix Issue 961669 in chromium: Chrome: Crash Report - PreReadFile

The Windows version check is failing on some systems, so branch on the existence
of the PrefetchVirtualMemeory API which is present on Win8 and above.

Bug: 961669
Change-Id: I891f47fd463bf7f487b84034ce2d7ed5595c0f70
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1607134Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Joe Laughlin <joel@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#659107}
parent a08b11a2
...@@ -10,17 +10,22 @@ ...@@ -10,17 +10,22 @@
#include "base/files/file.h" #include "base/files/file.h"
#include "base/files/memory_mapped_file.h" #include "base/files/memory_mapped_file.h"
#include "base/win/windows_version.h"
void PreReadFile(const base::FilePath& file_path) { void PreReadFile(const base::FilePath& file_path) {
// On Win10 RS6 and higher with the increased prefetch limit we don't need // On Win8 and higher use ::PrefetchVirtualMemory(). This is better than
// to do in process prefetch. On OS releases Win8/Server 2012 to Win10 RS5 // a simple data file read, more from a RAM perspective than CPU. This is
// use ::PrefetchVirtualMemory(). This is better than a simple data file // because reading the file as data results in double mapping to
// read, more from a RAM perspective than CPU. This is because reading the // Image/executable pages for all pages of code executed. On Win7 just do a
// file as data results in double mapping to Image/executable pages for all // simple file read as data.
// pages of code executed. On Win7 just do a simple file read as data.
// ::PrefetchVirtualMemory() isn't available on Win7.
if (base::win::GetVersion() == base::win::Version::WIN7) { HMODULE kernel32_library = GetModuleHandleA("kernel32.dll");
auto prefetch_virtual_memory =
reinterpret_cast<decltype(&::PrefetchVirtualMemory)>(
GetProcAddress(kernel32_library, "PrefetchVirtualMemory"));
if (!prefetch_virtual_memory) {
// On Win7 read in the file as data since the OS doesn't have // On Win7 read in the file as data since the OS doesn't have
// the support for better options. // the support for better options.
...@@ -55,13 +60,6 @@ void PreReadFile(const base::FilePath& file_path) { ...@@ -55,13 +60,6 @@ void PreReadFile(const base::FilePath& file_path) {
_WIN32_MEMORY_RANGE_ENTRY address_range = {mapped_file.data(), _WIN32_MEMORY_RANGE_ENTRY address_range = {mapped_file.data(),
mapped_file.length() / 2}; mapped_file.length() / 2};
// ::PrefetchVirtualMemory() isn't available on Win7.
HMODULE kernel32_library = GetModuleHandleA("kernel32.dll");
auto prefetch_virtual_memory =
reinterpret_cast<decltype(&::PrefetchVirtualMemory)>(
GetProcAddress(kernel32_library, "PrefetchVirtualMemory"));
// NB: PrefetchVirtualMemory requires the file to be opened with // NB: PrefetchVirtualMemory requires the file to be opened with
// only read access or it will fail. // only read access or it will fail.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment