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

Side by Side Diff: base/memory/shared_memory_posix.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_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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 272
273 #endif // !defined(OS_ANDROID) 273 #endif // !defined(OS_ANDROID)
274 274
275 bool SharedMemory::MapAt(off_t offset, size_t bytes) { 275 bool SharedMemory::MapAt(off_t offset, size_t bytes) {
276 if (mapped_file_ == -1) 276 if (mapped_file_ == -1)
277 return false; 277 return false;
278 278
279 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max())) 279 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max()))
280 return false; 280 return false;
281 281
282 if (memory_)
283 return false;
284
282 #if defined(OS_ANDROID) 285 #if defined(OS_ANDROID)
283 // On Android, Map can be called with a size and offset of zero to use the 286 // On Android, Map can be called with a size and offset of zero to use the
284 // ashmem-determined size. 287 // ashmem-determined size.
285 if (bytes == 0) { 288 if (bytes == 0) {
286 DCHECK_EQ(0, offset); 289 DCHECK_EQ(0, offset);
287 int ashmem_bytes = ashmem_get_size_region(mapped_file_); 290 int ashmem_bytes = ashmem_get_size_region(mapped_file_);
288 if (ashmem_bytes < 0) 291 if (ashmem_bytes < 0)
289 return false; 292 return false;
290 bytes = ashmem_bytes; 293 bytes = ashmem_bytes;
291 } 294 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 new_handle->fd = new_fd; 458 new_handle->fd = new_fd;
456 new_handle->auto_close = true; 459 new_handle->auto_close = true;
457 460
458 if (close_self) 461 if (close_self)
459 Close(); 462 Close();
460 463
461 return true; 464 return true;
462 } 465 }
463 466
464 } // namespace base 467 } // 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