| 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 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include "base/debug/alias.h" | |
| 12 #include "base/debug/dump_without_crashing.h" | |
| 13 #include "base/logging.h" | 11 #include "base/logging.h" |
| 14 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 16 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 18 | 16 |
| 19 namespace { | 17 namespace { |
| 20 | 18 |
| 21 // Errors that can occur during Shared Memory construction. | 19 // Errors that can occur during Shared Memory construction. |
| 22 // These match tools/metrics/histograms/histograms.xml. | 20 // These match tools/metrics/histograms/histograms.xml. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // | 101 // |
| 104 // By removing all access control permissions of a file mapping immediately | 102 // By removing all access control permissions of a file mapping immediately |
| 105 // after creation, ::DuplicateHandle() effectively only copies the file | 103 // after creation, ::DuplicateHandle() effectively only copies the file |
| 106 // permissions. | 104 // permissions. |
| 107 HANDLE CreateFileMappingWithReducedPermissions(SECURITY_ATTRIBUTES* sa, | 105 HANDLE CreateFileMappingWithReducedPermissions(SECURITY_ATTRIBUTES* sa, |
| 108 size_t rounded_size, | 106 size_t rounded_size, |
| 109 LPCWSTR name) { | 107 LPCWSTR name) { |
| 110 HANDLE h = CreateFileMapping(INVALID_HANDLE_VALUE, sa, PAGE_READWRITE, 0, | 108 HANDLE h = CreateFileMapping(INVALID_HANDLE_VALUE, sa, PAGE_READWRITE, 0, |
| 111 static_cast<DWORD>(rounded_size), name); | 109 static_cast<DWORD>(rounded_size), name); |
| 112 if (!h) { | 110 if (!h) { |
| 113 // Debugging to help track down https://crbug.com/585013 | |
| 114 DWORD last_error = ::GetLastError(); | |
| 115 base::debug::Alias(&last_error); | |
| 116 base::debug::DumpWithoutCrashing(); | |
| 117 | |
| 118 LogError(CREATE_FILE_MAPPING_FAILURE); | 111 LogError(CREATE_FILE_MAPPING_FAILURE); |
| 119 return nullptr; | 112 return nullptr; |
| 120 } | 113 } |
| 121 | 114 |
| 122 HANDLE h2; | 115 HANDLE h2; |
| 123 BOOL success = ::DuplicateHandle( | 116 BOOL success = ::DuplicateHandle( |
| 124 GetCurrentProcess(), h, GetCurrentProcess(), &h2, | 117 GetCurrentProcess(), h, GetCurrentProcess(), &h2, |
| 125 FILE_MAP_READ | FILE_MAP_WRITE | SECTION_QUERY, FALSE, 0); | 118 FILE_MAP_READ | FILE_MAP_WRITE | SECTION_QUERY, FALSE, 0); |
| 126 BOOL rv = ::CloseHandle(h); | 119 BOOL rv = ::CloseHandle(h); |
| 127 DCHECK(rv); | 120 DCHECK(rv); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 ::CloseHandle(mapped_file_); | 383 ::CloseHandle(mapped_file_); |
| 391 mapped_file_ = NULL; | 384 mapped_file_ = NULL; |
| 392 } | 385 } |
| 393 } | 386 } |
| 394 | 387 |
| 395 SharedMemoryHandle SharedMemory::handle() const { | 388 SharedMemoryHandle SharedMemory::handle() const { |
| 396 return SharedMemoryHandle(mapped_file_, base::GetCurrentProcId()); | 389 return SharedMemoryHandle(mapped_file_, base::GetCurrentProcId()); |
| 397 } | 390 } |
| 398 | 391 |
| 399 } // namespace base | 392 } // namespace base |
| OLD | NEW |