OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/files/memory_mapped_file.h" | 5 #include "base/files/memory_mapped_file.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 if (!file_.IsValid()) | 25 if (!file_.IsValid()) |
26 return false; | 26 return false; |
27 | 27 |
28 int flags = image_ ? SEC_IMAGE | PAGE_READONLY : PAGE_READONLY; | 28 int flags = image_ ? SEC_IMAGE | PAGE_READONLY : PAGE_READONLY; |
29 | 29 |
30 file_mapping_.Set(::CreateFileMapping(file_.GetPlatformFile(), NULL, | 30 file_mapping_.Set(::CreateFileMapping(file_.GetPlatformFile(), NULL, |
31 flags, 0, 0, NULL)); | 31 flags, 0, 0, NULL)); |
32 if (!file_mapping_.IsValid()) | 32 if (!file_mapping_.IsValid()) |
33 return false; | 33 return false; |
34 | 34 |
35 LARGE_INTEGER map_start = {0}; | 35 LARGE_INTEGER map_start = {}; |
36 SIZE_T map_size = 0; | 36 SIZE_T map_size = 0; |
37 int32 data_offset = 0; | 37 int32 data_offset = 0; |
38 | 38 |
39 if (region == MemoryMappedFile::Region::kWholeFile) { | 39 if (region == MemoryMappedFile::Region::kWholeFile) { |
40 int64 file_len = file_.GetLength(); | 40 int64 file_len = file_.GetLength(); |
41 if (file_len <= 0 || file_len > kint32max) | 41 if (file_len <= 0 || file_len > kint32max) |
42 return false; | 42 return false; |
43 length_ = static_cast<size_t>(file_len); | 43 length_ = static_cast<size_t>(file_len); |
44 } else { | 44 } else { |
45 // The region can be arbitrarily aligned. MapViewOfFile, instead, requires | 45 // The region can be arbitrarily aligned. MapViewOfFile, instead, requires |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 if (file_mapping_.IsValid()) | 83 if (file_mapping_.IsValid()) |
84 file_mapping_.Close(); | 84 file_mapping_.Close(); |
85 if (file_.IsValid()) | 85 if (file_.IsValid()) |
86 file_.Close(); | 86 file_.Close(); |
87 | 87 |
88 data_ = NULL; | 88 data_ = NULL; |
89 length_ = 0; | 89 length_ = 0; |
90 } | 90 } |
91 | 91 |
92 } // namespace base | 92 } // namespace base |
OLD | NEW |