Index: base/metrics/persistent_memory_allocator.cc |
diff --git a/base/metrics/persistent_memory_allocator.cc b/base/metrics/persistent_memory_allocator.cc |
index 8b4c4a4cd759758d64623d19e36f1067f24adeb8..a7766a4fcea786e4734fd9a557dbc57d4176fd28 100644 |
--- a/base/metrics/persistent_memory_allocator.cc |
+++ b/base/metrics/persistent_memory_allocator.cc |
@@ -9,6 +9,7 @@ |
#include "base/files/memory_mapped_file.h" |
#include "base/logging.h" |
+#include "base/memory/shared_memory.h" |
#include "base/metrics/histogram_macros.h" |
namespace { |
@@ -207,6 +208,15 @@ PersistentMemoryAllocator::PersistentMemoryAllocator(void* base, |
strcpy(name_cstr, name.c_str()); |
} |
} else { |
+ if (shared_meta()->size == 0 || |
+ shared_meta()->version == 0 || |
+ shared_meta()->freeptr.load() == 0 || |
+ shared_meta()->tailptr == 0 || |
+ shared_meta()->queue.cookie == 0 || |
+ shared_meta()->queue.next.load() == 0) { |
+ NOTREACHED(); |
+ SetCorrupt(); |
+ } |
if (readonly) { |
// For read-only access, validate reasonable ctor parameters. |
DCHECK_GE(mem_size_, shared_meta()->freeptr.load()); |
@@ -648,15 +658,36 @@ LocalPersistentMemoryAllocator::~LocalPersistentMemoryAllocator() { |
} |
+//----- SharedPersistentMemoryAllocator ---------------------------------------- |
+ |
+SharedPersistentMemoryAllocator::SharedPersistentMemoryAllocator( |
+ scoped_ptr<SharedMemory> memory, |
+ uint64_t id, |
+ const std::string& name, |
+ bool read_only) |
+ : PersistentMemoryAllocator(static_cast<uint8_t*>(memory->memory()), |
+ memory->mapped_size(), 0, id, name, read_only), |
+ shared_memory_(std::move(memory)) {} |
+ |
+SharedPersistentMemoryAllocator::~SharedPersistentMemoryAllocator() { |
+} |
Alexei Svitkine (slow)
2016/02/09 19:58:44
Nit: run git cl format?
I am assuming whatever it
bcwhite
2016/02/10 16:43:53
Done.
|
+ |
+// static |
+bool SharedPersistentMemoryAllocator::IsSharedMemoryAcceptable( |
+ const SharedMemory& memory) { |
+ return IsMemoryAcceptable(memory.memory(), memory.mapped_size(), 0, true); |
+} |
+ |
+ |
//----- FilePersistentMemoryAllocator ------------------------------------------ |
FilePersistentMemoryAllocator::FilePersistentMemoryAllocator( |
- MemoryMappedFile* file, |
+ scoped_ptr<MemoryMappedFile> file, |
uint64_t id, |
const std::string& name) |
: PersistentMemoryAllocator(const_cast<uint8_t*>(file->data()), |
file->length(), 0, id, name, true), |
- mapped_file_(file) {} |
+ mapped_file_(std::move(file)) {} |
FilePersistentMemoryAllocator::~FilePersistentMemoryAllocator() { |
} |