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

Unified Diff: base/shared_memory_posix.cc

Issue 12537014: Make SharedMemory track the size that was actually mapped (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
Index: base/shared_memory_posix.cc
===================================================================
--- base/shared_memory_posix.cc (revision 188553)
+++ base/shared_memory_posix.cc (working copy)
@@ -42,20 +42,20 @@
SharedMemory::SharedMemory()
: mapped_file_(-1),
+ inode_(0),
mapped_size_(0),
- inode_(0),
memory_(NULL),
read_only_(false),
- created_size_(0) {
+ requested_size_(0) {
}
SharedMemory::SharedMemory(SharedMemoryHandle handle, bool read_only)
: mapped_file_(handle.fd),
+ inode_(0),
mapped_size_(0),
- inode_(0),
memory_(NULL),
read_only_(read_only),
- created_size_(0) {
+ requested_size_(0) {
struct stat st;
if (fstat(handle.fd, &st) == 0) {
// If fstat fails, then the file descriptor is invalid and we'll learn this
@@ -67,11 +67,11 @@
SharedMemory::SharedMemory(SharedMemoryHandle handle, bool read_only,
ProcessHandle process)
: mapped_file_(handle.fd),
+ inode_(0),
mapped_size_(0),
- inode_(0),
memory_(NULL),
read_only_(read_only),
- created_size_(0) {
+ requested_size_(0) {
// We don't handle this case yet (note the ignored parameter); let's die if
// someone comes calling.
NOTREACHED();
@@ -164,7 +164,7 @@
return false;
}
}
- created_size_ = options.size;
+ requested_size_ = options.size;
}
if (fp == NULL) {
#if !defined(OS_MACOSX)
@@ -223,28 +223,28 @@
if (bytes > static_cast<size_t>(std::numeric_limits<int>::max()))
return false;
-#if defined(OS_ANDROID)
- if (bytes == 0) {
- int ashmem_bytes = ashmem_get_size_region(mapped_file_);
- if (ashmem_bytes < 0)
- return false;
-
- DCHECK_GE(static_cast<uint32>(ashmem_bytes), bytes);
- // The caller wants to determine the map region size from ashmem.
- bytes = ashmem_bytes - offset;
- // TODO(port): we set the created size here so that it is available in
- // transport_dib_android.cc. We should use ashmem_get_size_region()
- // in transport_dib_android.cc.
- created_size_ = ashmem_bytes;
- }
-#endif
-
memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE),
MAP_SHARED, mapped_file_, offset);
bool mmap_succeeded = memory_ != (void*)-1 && memory_ != NULL;
if (mmap_succeeded) {
mapped_size_ = bytes;
+#if defined(OS_ANDROID)
+ if (bytes == 0) {
+ int ashmem_bytes = ashmem_get_size_region(mapped_file_);
+ if (ashmem_bytes < 0)
+ return false;
+
+ DCHECK_GE(static_cast<uint32>(ashmem_bytes), bytes);
+ // The caller wants to determine the map region size from ashmem.
+ bytes = ashmem_bytes - offset;
+ // TODO(port): we set the created size here so that it is available in
+ // transport_dib_android.cc. We should use ashmem_get_size_region()
+ // in transport_dib_android.cc.
+ mapped_size_ = ashmem_bytes;
+ }
+#endif
+
DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) &
(SharedMemory::MAP_MINIMUM_ALIGNMENT - 1));
} else {

Powered by Google App Engine
This is Rietveld 408576698