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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 return false; | 139 return false; |
140 if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) | 140 if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) |
141 return false; | 141 return false; |
142 if (!SetSecurityDescriptorDacl(&sd, TRUE, &dacl, FALSE)) | 142 if (!SetSecurityDescriptorDacl(&sd, TRUE, &dacl, FALSE)) |
143 return false; | 143 return false; |
144 | 144 |
145 // Windows ignores DACLs on certain unnamed objects (like shared sections). | 145 // Windows ignores DACLs on certain unnamed objects (like shared sections). |
146 // So, we generate a random name when we need to enforce read-only. | 146 // So, we generate a random name when we need to enforce read-only. |
147 uint64_t rand_values[4]; | 147 uint64_t rand_values[4]; |
148 RandBytes(&rand_values, sizeof(rand_values)); | 148 RandBytes(&rand_values, sizeof(rand_values)); |
149 name_ = StringPrintf(L"CrSharedMem_%016x%016x%016x%016x", | 149 name_ = StringPrintf(L"CrSharedMem_%016llx%016llx%016llx%016llx", |
150 rand_values[0], rand_values[1], | 150 rand_values[0], rand_values[1], |
151 rand_values[2], rand_values[3]); | 151 rand_values[2], rand_values[3]); |
152 } | 152 } |
153 mapped_file_ = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, | 153 mapped_file_ = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, |
154 PAGE_READWRITE, 0, static_cast<DWORD>(rounded_size), | 154 PAGE_READWRITE, 0, static_cast<DWORD>(rounded_size), |
155 name_.empty() ? nullptr : name_.c_str()); | 155 name_.empty() ? nullptr : name_.c_str()); |
156 if (!mapped_file_) | 156 if (!mapped_file_) |
157 return false; | 157 return false; |
158 | 158 |
159 requested_size_ = options.size; | 159 requested_size_ = options.size; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 ::CloseHandle(mapped_file_); | 263 ::CloseHandle(mapped_file_); |
264 mapped_file_ = NULL; | 264 mapped_file_ = NULL; |
265 } | 265 } |
266 } | 266 } |
267 | 267 |
268 SharedMemoryHandle SharedMemory::handle() const { | 268 SharedMemoryHandle SharedMemory::handle() const { |
269 return SharedMemoryHandle(mapped_file_, base::GetCurrentProcId()); | 269 return SharedMemoryHandle(mapped_file_, base::GetCurrentProcId()); |
270 } | 270 } |
271 | 271 |
272 } // namespace base | 272 } // namespace base |
OLD | NEW |