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

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

Issue 812543002: Update from https://crrev.com/308331 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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_nacl.cc ('k') | base/memory/shared_memory_unittest.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/mman.h> 9 #include <sys/mman.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 mapped_size_(0), 73 mapped_size_(0),
74 memory_(NULL), 74 memory_(NULL),
75 read_only_(read_only), 75 read_only_(read_only),
76 requested_size_(0) { 76 requested_size_(0) {
77 // We don't handle this case yet (note the ignored parameter); let's die if 77 // We don't handle this case yet (note the ignored parameter); let's die if
78 // someone comes calling. 78 // someone comes calling.
79 NOTREACHED(); 79 NOTREACHED();
80 } 80 }
81 81
82 SharedMemory::~SharedMemory() { 82 SharedMemory::~SharedMemory() {
83 Unmap();
83 Close(); 84 Close();
84 } 85 }
85 86
86 // static 87 // static
87 bool SharedMemory::IsHandleValid(const SharedMemoryHandle& handle) { 88 bool SharedMemory::IsHandleValid(const SharedMemoryHandle& handle) {
88 return handle.fd >= 0; 89 return handle.fd >= 0;
89 } 90 }
90 91
91 // static 92 // static
92 SharedMemoryHandle SharedMemory::NULLHandle() { 93 SharedMemoryHandle SharedMemory::NULLHandle() {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 memory_ = NULL; 325 memory_ = NULL;
325 mapped_size_ = 0; 326 mapped_size_ = 0;
326 return true; 327 return true;
327 } 328 }
328 329
329 SharedMemoryHandle SharedMemory::handle() const { 330 SharedMemoryHandle SharedMemory::handle() const {
330 return FileDescriptor(mapped_file_, false); 331 return FileDescriptor(mapped_file_, false);
331 } 332 }
332 333
333 void SharedMemory::Close() { 334 void SharedMemory::Close() {
334 Unmap();
335
336 if (mapped_file_ > 0) { 335 if (mapped_file_ > 0) {
337 if (close(mapped_file_) < 0) 336 if (close(mapped_file_) < 0)
338 PLOG(ERROR) << "close"; 337 PLOG(ERROR) << "close";
339 mapped_file_ = -1; 338 mapped_file_ = -1;
340 } 339 }
341 if (readonly_mapped_file_ > 0) { 340 if (readonly_mapped_file_ > 0) {
342 if (close(readonly_mapped_file_) < 0) 341 if (close(readonly_mapped_file_) < 0)
343 PLOG(ERROR) << "close"; 342 PLOG(ERROR) << "close";
344 readonly_mapped_file_ = -1; 343 readonly_mapped_file_ = -1;
345 } 344 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 460
462 const int new_fd = dup(handle_to_dup); 461 const int new_fd = dup(handle_to_dup);
463 if (new_fd < 0) { 462 if (new_fd < 0) {
464 DPLOG(ERROR) << "dup() failed."; 463 DPLOG(ERROR) << "dup() failed.";
465 return false; 464 return false;
466 } 465 }
467 466
468 new_handle->fd = new_fd; 467 new_handle->fd = new_fd;
469 new_handle->auto_close = true; 468 new_handle->auto_close = true;
470 469
471 if (close_self) 470 if (close_self) {
471 Unmap();
472 Close(); 472 Close();
473 }
473 474
474 return true; 475 return true;
475 } 476 }
476 477
477 } // namespace base 478 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory_nacl.cc ('k') | base/memory/shared_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698