Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(963)

Side by Side Diff: base/memory/shared_memory_win.cc

Issue 2849243002: Get rid of all pid references from base::SharedMemoryHandle. (Closed)
Patch Set: fix invalid handle Chrome IPC. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/memory/shared_memory_unittest.cc ('k') | base/metrics/field_trial.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 memory_(NULL), 149 memory_(NULL),
150 read_only_(false), 150 read_only_(false),
151 requested_size_(0) {} 151 requested_size_(0) {}
152 152
153 SharedMemory::SharedMemory(const SharedMemoryHandle& handle, bool read_only) 153 SharedMemory::SharedMemory(const SharedMemoryHandle& handle, bool read_only)
154 : external_section_(true), 154 : external_section_(true),
155 mapped_size_(0), 155 mapped_size_(0),
156 memory_(NULL), 156 memory_(NULL),
157 read_only_(read_only), 157 read_only_(read_only),
158 requested_size_(0) { 158 requested_size_(0) {
159 DCHECK(!handle.IsValid() || handle.BelongsToCurrentProcess());
160 mapped_file_.Set(handle.GetHandle()); 159 mapped_file_.Set(handle.GetHandle());
161 } 160 }
162 161
163 SharedMemory::~SharedMemory() { 162 SharedMemory::~SharedMemory() {
164 Unmap(); 163 Unmap();
165 Close(); 164 Close();
166 } 165 }
167 166
168 // static 167 // static
169 bool SharedMemory::IsHandleValid(const SharedMemoryHandle& handle) { 168 bool SharedMemory::IsHandleValid(const SharedMemoryHandle& handle) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 return true; 326 return true;
328 } 327 }
329 328
330 SharedMemoryHandle SharedMemory::GetReadOnlyHandle() { 329 SharedMemoryHandle SharedMemory::GetReadOnlyHandle() {
331 HANDLE result; 330 HANDLE result;
332 ProcessHandle process = GetCurrentProcess(); 331 ProcessHandle process = GetCurrentProcess();
333 if (!::DuplicateHandle(process, mapped_file_.Get(), process, &result, 332 if (!::DuplicateHandle(process, mapped_file_.Get(), process, &result,
334 FILE_MAP_READ | SECTION_QUERY, FALSE, 0)) { 333 FILE_MAP_READ | SECTION_QUERY, FALSE, 0)) {
335 return SharedMemoryHandle(); 334 return SharedMemoryHandle();
336 } 335 }
337 SharedMemoryHandle handle = 336 SharedMemoryHandle handle = SharedMemoryHandle(result);
338 SharedMemoryHandle(result, base::GetProcId(process));
339 handle.SetOwnershipPassesToIPC(true); 337 handle.SetOwnershipPassesToIPC(true);
340 return handle; 338 return handle;
341 } 339 }
342 340
343 void SharedMemory::Close() { 341 void SharedMemory::Close() {
344 mapped_file_.Close(); 342 mapped_file_.Close();
345 } 343 }
346 344
347 SharedMemoryHandle SharedMemory::handle() const { 345 SharedMemoryHandle SharedMemory::handle() const {
348 return SharedMemoryHandle(mapped_file_.Get(), base::GetCurrentProcId()); 346 return SharedMemoryHandle(mapped_file_.Get());
349 } 347 }
350 348
351 SharedMemoryHandle SharedMemory::TakeHandle() { 349 SharedMemoryHandle SharedMemory::TakeHandle() {
352 SharedMemoryHandle handle(mapped_file_.Take(), base::GetCurrentProcId()); 350 SharedMemoryHandle handle(mapped_file_.Take());
353 handle.SetOwnershipPassesToIPC(true); 351 handle.SetOwnershipPassesToIPC(true);
354 memory_ = nullptr; 352 memory_ = nullptr;
355 mapped_size_ = 0; 353 mapped_size_ = 0;
356 return handle; 354 return handle;
357 } 355 }
358 356
359 } // namespace base 357 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory_unittest.cc ('k') | base/metrics/field_trial.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698