Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: base/files/memory_mapped_file.cc

Issue 1156183003: Pass file Regions along with FDs to child processes on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: actual fix Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/files/memory_mapped_file.h ('k') | content/app/android/child_process_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/logging.h" 8 #include "base/logging.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 10
11 namespace base { 11 namespace base {
12 12
13 const MemoryMappedFile::Region MemoryMappedFile::Region::kWholeFile( 13 const MemoryMappedFile::Region MemoryMappedFile::Region::kWholeFile(
14 base::LINKER_INITIALIZED); 14 base::LINKER_INITIALIZED);
15 15
16 MemoryMappedFile::Region::Region(base::LinkerInitialized) : offset(0), size(0) { 16 MemoryMappedFile::Region::Region(base::LinkerInitialized) : offset(0), size(0) {
17 } 17 }
18 18
19 MemoryMappedFile::Region::Region() : offset(-1), size(-1) {
20 }
21
19 MemoryMappedFile::Region::Region(int64 offset, int64 size) 22 MemoryMappedFile::Region::Region(int64 offset, int64 size)
20 : offset(offset), size(size) { 23 : offset(offset), size(size) {
21 DCHECK_GE(offset, 0);
22 DCHECK_GT(size, 0);
23 } 24 }
24 25
25 bool MemoryMappedFile::Region::operator==( 26 bool MemoryMappedFile::Region::operator==(
26 const MemoryMappedFile::Region& other) const { 27 const MemoryMappedFile::Region& other) const {
27 return other.offset == offset && other.size == size; 28 return other.offset == offset && other.size == size;
28 } 29 }
29 30
30 MemoryMappedFile::~MemoryMappedFile() { 31 MemoryMappedFile::~MemoryMappedFile() {
31 CloseHandles(); 32 CloseHandles();
32 } 33 }
(...skipping 19 matching lines...) Expand all
52 } 53 }
53 54
54 bool MemoryMappedFile::Initialize(File file) { 55 bool MemoryMappedFile::Initialize(File file) {
55 return Initialize(file.Pass(), Region::kWholeFile); 56 return Initialize(file.Pass(), Region::kWholeFile);
56 } 57 }
57 58
58 bool MemoryMappedFile::Initialize(File file, const Region& region) { 59 bool MemoryMappedFile::Initialize(File file, const Region& region) {
59 if (IsValid()) 60 if (IsValid())
60 return false; 61 return false;
61 62
63 if (!(region == Region::kWholeFile)) {
Lei Zhang 2015/06/02 18:59:11 should we implement operator!= ?
agrieve 2015/06/02 19:21:38 Seems reasonable doesn't it? :) Done!
64 DCHECK_GE(region.offset, 0);
65 DCHECK_GT(region.size, 0);
66 }
67
62 file_ = file.Pass(); 68 file_ = file.Pass();
63 69
64 if (!MapFileRegionToMemory(region)) { 70 if (!MapFileRegionToMemory(region)) {
65 CloseHandles(); 71 CloseHandles();
66 return false; 72 return false;
67 } 73 }
68 74
69 return true; 75 return true;
70 } 76 }
71 77
(...skipping 10 matching lines...) Expand all
82 // Sadly, on Windows, the mmap alignment is not just equal to the page size. 88 // Sadly, on Windows, the mmap alignment is not just equal to the page size.
83 const int64 mask = static_cast<int64>(SysInfo::VMAllocationGranularity()) - 1; 89 const int64 mask = static_cast<int64>(SysInfo::VMAllocationGranularity()) - 1;
84 DCHECK_LT(mask, std::numeric_limits<int32>::max()); 90 DCHECK_LT(mask, std::numeric_limits<int32>::max());
85 *offset = start & mask; 91 *offset = start & mask;
86 *aligned_start = start & ~mask; 92 *aligned_start = start & ~mask;
87 *aligned_size = (size + *offset + mask) & ~mask; 93 *aligned_size = (size + *offset + mask) & ~mask;
88 } 94 }
89 #endif 95 #endif
90 96
91 } // namespace base 97 } // namespace base
OLDNEW
« no previous file with comments | « base/files/memory_mapped_file.h ('k') | content/app/android/child_process_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698