OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 "chrome/app/image_pre_reader_win.h" | 5 #include "chrome/app/image_pre_reader_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <limits> | 9 #include <limits> |
10 #include <vector> | 10 #include <vector> |
(...skipping 10 matching lines...) Expand all Loading... |
21 // The minimum buffer size to allocate when reading the PE file headers. | 21 // The minimum buffer size to allocate when reading the PE file headers. |
22 // | 22 // |
23 // The PE file headers usually fit into a single 1KB page, and a PE file must | 23 // The PE file headers usually fit into a single 1KB page, and a PE file must |
24 // at least contain the initial page with the headers. That said, as long as | 24 // at least contain the initial page with the headers. That said, as long as |
25 // we expect at least sizeof(IMAGE_DOS_HEADER) bytes, we're ok. | 25 // we expect at least sizeof(IMAGE_DOS_HEADER) bytes, we're ok. |
26 const size_t kMinHeaderBufferSize = 0x400; | 26 const size_t kMinHeaderBufferSize = 0x400; |
27 | 27 |
28 // A handy symbolic constant. | 28 // A handy symbolic constant. |
29 const size_t kOneHundredPercent = 100; | 29 const size_t kOneHundredPercent = 100; |
30 | 30 |
31 void StaticAssertions() { | 31 static_assert(kMinHeaderBufferSize >= sizeof(IMAGE_DOS_HEADER), |
32 COMPILE_ASSERT(kMinHeaderBufferSize >= sizeof(IMAGE_DOS_HEADER), | 32 "kMinHeaderBufferSize must be at least as big as the dos header"); |
33 min_header_buffer_size_at_least_as_big_as_the_dos_header); | |
34 } | |
35 | 33 |
36 // This struct provides a deallocation functor for use with scoped_ptr<T> | 34 // This struct provides a deallocation functor for use with scoped_ptr<T> |
37 // allocated with ::VirtualAlloc(). | 35 // allocated with ::VirtualAlloc(). |
38 struct VirtualFreeDeleter { | 36 struct VirtualFreeDeleter { |
39 void operator() (void* ptr) { | 37 void operator() (void* ptr) { |
40 ::VirtualFree(ptr, 0, MEM_RELEASE); | 38 ::VirtualFree(ptr, 0, MEM_RELEASE); |
41 } | 39 } |
42 }; | 40 }; |
43 | 41 |
44 // A wrapper for the Win32 ::SetFilePointer() function with some error checking. | 42 // A wrapper for the Win32 ::SetFilePointer() function with some error checking. |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 // Vista+ branch. On these OSes, we warm up the Image by reading its | 410 // Vista+ branch. On these OSes, we warm up the Image by reading its |
413 // file off the disk. | 411 // file off the disk. |
414 return PartialPreReadImageOnDisk(file_path, percentage, max_chunk_size); | 412 return PartialPreReadImageOnDisk(file_path, percentage, max_chunk_size); |
415 } | 413 } |
416 | 414 |
417 // WinXP branch. For XP, reading the image from disk doesn't do what we want | 415 // WinXP branch. For XP, reading the image from disk doesn't do what we want |
418 // so instead we pull the pages into memory by loading the DLL and touching | 416 // so instead we pull the pages into memory by loading the DLL and touching |
419 // initialized pages at a stride. | 417 // initialized pages at a stride. |
420 return PartialPreReadImageInMemory(file_path, percentage); | 418 return PartialPreReadImageInMemory(file_path, percentage); |
421 } | 419 } |
OLD | NEW |