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 | |
147 LPCWSTR shared_memory_name = NULL; | |
rvargas (doing something else)
2015/02/21 01:01:22
nit: wchar_t* or char16*
Shrikant Kelkar
2015/02/21 02:32:40
removed, as per second comment.
| |
148 if (!name_.empty()) | |
149 shared_memory_name = name_.c_str(); | |
150 | |
146 mapped_file_ = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, | 151 mapped_file_ = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, |
147 PAGE_READWRITE, 0, static_cast<DWORD>(rounded_size), name_.c_str()); | 152 PAGE_READWRITE, 0, static_cast<DWORD>(rounded_size), shared_memory_name); |
rvargas (doing something else)
2015/02/21 01:01:22
name_.empty() ? nullptr : name_.c_str() ?
Separate
Shrikant Kelkar
2015/02/21 02:32:40
Done.
| |
148 if (!mapped_file_) | 153 if (!mapped_file_) |
149 return false; | 154 return false; |
150 | 155 |
151 requested_size_ = options.size; | 156 requested_size_ = options.size; |
152 | 157 |
153 // Check if the shared memory pre-exists. | 158 // Check if the shared memory pre-exists. |
154 if (GetLastError() == ERROR_ALREADY_EXISTS) { | 159 if (GetLastError() == ERROR_ALREADY_EXISTS) { |
155 // If the file already existed, set requested_size_ to 0 to show that | 160 // If the file already existed, set requested_size_ to 0 to show that |
156 // we don't know the size. | 161 // we don't know the size. |
157 requested_size_ = 0; | 162 requested_size_ = 0; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 void SharedMemory::UnlockDeprecated() { | 279 void SharedMemory::UnlockDeprecated() { |
275 DCHECK(lock_ != NULL); | 280 DCHECK(lock_ != NULL); |
276 ReleaseMutex(lock_); | 281 ReleaseMutex(lock_); |
277 } | 282 } |
278 | 283 |
279 SharedMemoryHandle SharedMemory::handle() const { | 284 SharedMemoryHandle SharedMemory::handle() const { |
280 return mapped_file_; | 285 return mapped_file_; |
281 } | 286 } |
282 | 287 |
283 } // namespace base | 288 } // namespace base |
OLD | NEW |