| OLD | NEW |
| 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/memory/shared_memory.h" | 5 #include "base/memory/shared_memory.h" |
| 6 | 6 |
| 7 #include <aclapi.h> | 7 #include <aclapi.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 ::CloseHandle(handle); | 93 ::CloseHandle(handle); |
| 94 } | 94 } |
| 95 | 95 |
| 96 // static | 96 // static |
| 97 size_t SharedMemory::GetHandleLimit() { | 97 size_t SharedMemory::GetHandleLimit() { |
| 98 // Rounded down from value reported here: | 98 // Rounded down from value reported here: |
| 99 // http://blogs.technet.com/b/markrussinovich/archive/2009/09/29/3283844.aspx | 99 // http://blogs.technet.com/b/markrussinovich/archive/2009/09/29/3283844.aspx |
| 100 return static_cast<size_t>(1 << 23); | 100 return static_cast<size_t>(1 << 23); |
| 101 } | 101 } |
| 102 | 102 |
| 103 // static |
| 104 SharedMemoryHandle SharedMemory::DuplicateHandle( |
| 105 const SharedMemoryHandle& handle) { |
| 106 ProcessHandle process = GetCurrentProcess(); |
| 107 SharedMemoryHandle duped_handle; |
| 108 BOOL success = ::DuplicateHandle(process, handle, process, &duped_handle, 0, |
| 109 FALSE, DUPLICATE_SAME_ACCESS); |
| 110 if (success) |
| 111 return duped_handle; |
| 112 return NULLHandle(); |
| 113 } |
| 114 |
| 103 bool SharedMemory::CreateAndMapAnonymous(size_t size) { | 115 bool SharedMemory::CreateAndMapAnonymous(size_t size) { |
| 104 return CreateAnonymous(size) && Map(size); | 116 return CreateAnonymous(size) && Map(size); |
| 105 } | 117 } |
| 106 | 118 |
| 107 bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { | 119 bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { |
| 108 // TODO(bsy,sehr): crbug.com/210609 NaCl forces us to round up 64k here, | 120 // TODO(bsy,sehr): crbug.com/210609 NaCl forces us to round up 64k here, |
| 109 // wasting 32k per mapping on average. | 121 // wasting 32k per mapping on average. |
| 110 static const size_t kSectionMask = 65536 - 1; | 122 static const size_t kSectionMask = 65536 - 1; |
| 111 DCHECK(!options.executable); | 123 DCHECK(!options.executable); |
| 112 DCHECK(!mapped_file_); | 124 DCHECK(!mapped_file_); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 options = DUPLICATE_CLOSE_SOURCE; | 247 options = DUPLICATE_CLOSE_SOURCE; |
| 236 mapped_file_ = NULL; | 248 mapped_file_ = NULL; |
| 237 Unmap(); | 249 Unmap(); |
| 238 } | 250 } |
| 239 | 251 |
| 240 if (process == GetCurrentProcess() && close_self) { | 252 if (process == GetCurrentProcess() && close_self) { |
| 241 *new_handle = mapped_file; | 253 *new_handle = mapped_file; |
| 242 return true; | 254 return true; |
| 243 } | 255 } |
| 244 | 256 |
| 245 if (!DuplicateHandle(GetCurrentProcess(), mapped_file, process, | 257 if (!::DuplicateHandle(GetCurrentProcess(), mapped_file, process, &result, |
| 246 &result, access, FALSE, options)) | 258 access, FALSE, options)) { |
| 247 return false; | 259 return false; |
| 260 } |
| 248 *new_handle = result; | 261 *new_handle = result; |
| 249 return true; | 262 return true; |
| 250 } | 263 } |
| 251 | 264 |
| 252 | 265 |
| 253 void SharedMemory::Close() { | 266 void SharedMemory::Close() { |
| 254 if (mapped_file_ != NULL) { | 267 if (mapped_file_ != NULL) { |
| 255 CloseHandle(mapped_file_); | 268 CloseHandle(mapped_file_); |
| 256 mapped_file_ = NULL; | 269 mapped_file_ = NULL; |
| 257 } | 270 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 275 void SharedMemory::UnlockDeprecated() { | 288 void SharedMemory::UnlockDeprecated() { |
| 276 DCHECK(lock_ != NULL); | 289 DCHECK(lock_ != NULL); |
| 277 ReleaseMutex(lock_); | 290 ReleaseMutex(lock_); |
| 278 } | 291 } |
| 279 | 292 |
| 280 SharedMemoryHandle SharedMemory::handle() const { | 293 SharedMemoryHandle SharedMemory::handle() const { |
| 281 return mapped_file_; | 294 return mapped_file_; |
| 282 } | 295 } |
| 283 | 296 |
| 284 } // namespace base | 297 } // namespace base |
| OLD | NEW |