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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 return false; | 136 return false; |
137 | 137 |
138 // Windows ignores DACLs on certain unnamed objects (like shared sections). | 138 // Windows ignores DACLs on certain unnamed objects (like shared sections). |
139 // So, we generate a random name when we need to enforce read-only. | 139 // So, we generate a random name when we need to enforce read-only. |
140 uint64_t rand_values[4]; | 140 uint64_t rand_values[4]; |
141 RandBytes(&rand_values, sizeof(rand_values)); | 141 RandBytes(&rand_values, sizeof(rand_values)); |
142 name_ = StringPrintf(L"CrSharedMem_%016x%016x%016x%016x", | 142 name_ = StringPrintf(L"CrSharedMem_%016x%016x%016x%016x", |
143 rand_values[0], rand_values[1], | 143 rand_values[0], rand_values[1], |
144 rand_values[2], rand_values[3]); | 144 rand_values[2], rand_values[3]); |
145 } | 145 } |
| 146 |
146 mapped_file_ = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, | 147 mapped_file_ = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, |
147 PAGE_READWRITE, 0, static_cast<DWORD>(rounded_size), name_.c_str()); | 148 PAGE_READWRITE, 0, static_cast<DWORD>(rounded_size), |
| 149 name_.empty() ? nullptr : name_.c_str()); |
148 if (!mapped_file_) | 150 if (!mapped_file_) |
149 return false; | 151 return false; |
150 | 152 |
151 requested_size_ = options.size; | 153 requested_size_ = options.size; |
152 | 154 |
153 // Check if the shared memory pre-exists. | 155 // Check if the shared memory pre-exists. |
154 if (GetLastError() == ERROR_ALREADY_EXISTS) { | 156 if (GetLastError() == ERROR_ALREADY_EXISTS) { |
155 // If the file already existed, set requested_size_ to 0 to show that | 157 // If the file already existed, set requested_size_ to 0 to show that |
156 // we don't know the size. | 158 // we don't know the size. |
157 requested_size_ = 0; | 159 requested_size_ = 0; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 void SharedMemory::UnlockDeprecated() { | 276 void SharedMemory::UnlockDeprecated() { |
275 DCHECK(lock_ != NULL); | 277 DCHECK(lock_ != NULL); |
276 ReleaseMutex(lock_); | 278 ReleaseMutex(lock_); |
277 } | 279 } |
278 | 280 |
279 SharedMemoryHandle SharedMemory::handle() const { | 281 SharedMemoryHandle SharedMemory::handle() const { |
280 return mapped_file_; | 282 return mapped_file_; |
281 } | 283 } |
282 | 284 |
283 } // namespace base | 285 } // namespace base |
OLD | NEW |