Chromium Code Reviews| 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..599e0de2984b04179380b4b00b626f914c444341 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> shmem, |
|
Alexei Svitkine (slow)
2016/02/05 21:54:02
Nit: Make param consistent with header.
bcwhite
2016/02/06 04:26:11
Done.
|
| + uint64_t id, |
| + const std::string& name, |
| + bool read_only) |
| + : PersistentMemoryAllocator(static_cast<uint8_t*>(shmem->memory()), |
| + shmem->mapped_size(), 0, id, name, read_only), |
| + shared_memory_(std::move(shmem)) {} |
| + |
| +SharedPersistentMemoryAllocator::~SharedPersistentMemoryAllocator() { |
| +} |
| + |
| +// static |
| +bool SharedPersistentMemoryAllocator::IsSharedMemoryAcceptable( |
| + const SharedMemory& shmem) { |
| + return IsMemoryAcceptable(shmem.memory(), shmem.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() { |
| } |