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

Side by Side Diff: base/shared_memory_win.cc

Issue 11876037: Added SharedMemory::MapFrom. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« base/shared_memory_posix.cc ('K') | « base/shared_memory_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/shared_memory.h" 5 #include "base/shared_memory.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/sys_info.h"
8 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
9 10
10 namespace base { 11 namespace base {
11 12
12 SharedMemory::SharedMemory() 13 SharedMemory::SharedMemory()
13 : mapped_file_(NULL), 14 : mapped_file_(NULL),
14 memory_(NULL), 15 memory_(NULL),
15 read_only_(false), 16 read_only_(false),
16 created_size_(0), 17 created_size_(0),
17 lock_(NULL) { 18 lock_(NULL) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 mapped_file_ = OpenFileMapping( 128 mapped_file_ = OpenFileMapping(
128 read_only_ ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS, false, 129 read_only_ ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS, false,
129 name_.empty() ? NULL : name_.c_str()); 130 name_.empty() ? NULL : name_.c_str());
130 if (mapped_file_ != NULL) { 131 if (mapped_file_ != NULL) {
131 // Note: size_ is not set in this case. 132 // Note: size_ is not set in this case.
132 return true; 133 return true;
133 } 134 }
134 return false; 135 return false;
135 } 136 }
136 137
137 bool SharedMemory::Map(size_t bytes) { 138 bool SharedMemory::MapFrom(off_t offset, size_t bytes) {
138 if (mapped_file_ == NULL) 139 if (mapped_file_ == NULL)
139 return false; 140 return false;
140 141
141 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max())) 142 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max()))
142 return false; 143 return false;
143 144
145 DCHECK_EQ(0U, offset & (SysInfo::VMAllocationGranularity() - 1));
Mark Mentovai 2013/01/15 21:51:42 Same.
Vitaly Buka (NO REVIEWS) 2013/01/15 22:13:05 So do you advise to remove DCHECK?
144 memory_ = MapViewOfFile(mapped_file_, 146 memory_ = MapViewOfFile(mapped_file_,
145 read_only_ ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS, 0, 0, bytes); 147 read_only_ ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS,
148 static_cast<uint64>(offset) >> 32,
149 static_cast<DWORD>(offset),
150 bytes);
151 int e = GetLastError();
Mark Mentovai 2013/01/15 21:51:42 Unused.
Vitaly Buka (NO REVIEWS) 2013/01/15 22:13:05 Done.
146 if (memory_ != NULL) { 152 if (memory_ != NULL) {
147 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) & 153 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) &
148 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1)); 154 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1));
149 return true; 155 return true;
150 } 156 }
151 return false; 157 return false;
152 } 158 }
153 159
154 bool SharedMemory::Unmap() { 160 bool SharedMemory::Unmap() {
155 if (memory_ == NULL) 161 if (memory_ == NULL)
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 void SharedMemory::Unlock() { 231 void SharedMemory::Unlock() {
226 DCHECK(lock_ != NULL); 232 DCHECK(lock_ != NULL);
227 ReleaseMutex(lock_); 233 ReleaseMutex(lock_);
228 } 234 }
229 235
230 SharedMemoryHandle SharedMemory::handle() const { 236 SharedMemoryHandle SharedMemory::handle() const {
231 return mapped_file_; 237 return mapped_file_;
232 } 238 }
233 239
234 } // namespace base 240 } // namespace base
OLDNEW
« base/shared_memory_posix.cc ('K') | « base/shared_memory_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698