| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 ::CloseHandle(handle); | 87 ::CloseHandle(handle); |
| 88 } | 88 } |
| 89 | 89 |
| 90 // static | 90 // static |
| 91 size_t SharedMemory::GetHandleLimit() { | 91 size_t SharedMemory::GetHandleLimit() { |
| 92 // Rounded down from value reported here: | 92 // Rounded down from value reported here: |
| 93 // http://blogs.technet.com/b/markrussinovich/archive/2009/09/29/3283844.aspx | 93 // http://blogs.technet.com/b/markrussinovich/archive/2009/09/29/3283844.aspx |
| 94 return static_cast<size_t>(1 << 23); | 94 return static_cast<size_t>(1 << 23); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // static |
| 98 scoped_ptr<SharedMemory> SharedMemory::NewAnonymousReadOnly( |
| 99 StringPiece contents) { |
| 100 SharedMemory writable_handle; |
| 101 writable_handle.CreateAndMapAnonymous(contents.size()); |
| 102 memcpy(writable_handle.memory(), contents.data(), contents.size()); |
| 103 writable_handle.Unmap(); |
| 104 |
| 105 return make_scoped_ptr(new SharedMemory( |
| 106 writable_handle.handle(), /*read_only=*/true, GetCurrentProcess())); |
| 107 } |
| 108 |
| 97 bool SharedMemory::CreateAndMapAnonymous(size_t size) { | 109 bool SharedMemory::CreateAndMapAnonymous(size_t size) { |
| 98 return CreateAnonymous(size) && Map(size); | 110 return CreateAnonymous(size) && Map(size); |
| 99 } | 111 } |
| 100 | 112 |
| 101 bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { | 113 bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { |
| 102 // TODO(bsy,sehr): crbug.com/210609 NaCl forces us to round up 64k here, | 114 // TODO(bsy,sehr): crbug.com/210609 NaCl forces us to round up 64k here, |
| 103 // wasting 32k per mapping on average. | 115 // wasting 32k per mapping on average. |
| 104 static const size_t kSectionMask = 65536 - 1; | 116 static const size_t kSectionMask = 65536 - 1; |
| 105 DCHECK(!options.executable); | 117 DCHECK(!options.executable); |
| 106 DCHECK(!mapped_file_); | 118 DCHECK(!mapped_file_); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 void SharedMemory::Unlock() { | 263 void SharedMemory::Unlock() { |
| 252 DCHECK(lock_ != NULL); | 264 DCHECK(lock_ != NULL); |
| 253 ReleaseMutex(lock_); | 265 ReleaseMutex(lock_); |
| 254 } | 266 } |
| 255 | 267 |
| 256 SharedMemoryHandle SharedMemory::handle() const { | 268 SharedMemoryHandle SharedMemory::handle() const { |
| 257 return mapped_file_; | 269 return mapped_file_; |
| 258 } | 270 } |
| 259 | 271 |
| 260 } // namespace base | 272 } // namespace base |
| OLD | NEW |