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

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

Issue 203123009: Disallow calling Map on currently-mapped SharedMemory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « base/memory/shared_memory.h ('k') | base/memory/shared_memory_posix.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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 return false; 84 return false;
85 } 85 }
86 86
87 bool SharedMemory::MapAt(off_t offset, size_t bytes) { 87 bool SharedMemory::MapAt(off_t offset, size_t bytes) {
88 if (mapped_file_ == -1) 88 if (mapped_file_ == -1)
89 return false; 89 return false;
90 90
91 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max())) 91 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max()))
92 return false; 92 return false;
93 93
94 if (memory_)
95 return false;
96
94 memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE), 97 memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE),
95 MAP_SHARED, mapped_file_, offset); 98 MAP_SHARED, mapped_file_, offset);
96 99
97 bool mmap_succeeded = memory_ != MAP_FAILED && memory_ != NULL; 100 bool mmap_succeeded = memory_ != MAP_FAILED && memory_ != NULL;
98 if (mmap_succeeded) { 101 if (mmap_succeeded) {
99 mapped_size_ = bytes; 102 mapped_size_ = bytes;
100 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) & 103 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) &
101 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1)); 104 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1));
102 } else { 105 } else {
103 memory_ = NULL; 106 memory_ = NULL;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 158
156 new_handle->fd = new_fd; 159 new_handle->fd = new_fd;
157 new_handle->auto_close = true; 160 new_handle->auto_close = true;
158 161
159 if (close_self) 162 if (close_self)
160 Close(); 163 Close();
161 return true; 164 return true;
162 } 165 }
163 166
164 } // namespace base 167 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory.h ('k') | base/memory/shared_memory_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698