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

Unified Diff: base/metrics/persistent_memory_allocator.cc

Issue 1660143009: Add SharedMemory version of PersistentMemoryAllocator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 10 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
« no previous file with comments | « base/metrics/persistent_memory_allocator.h ('k') | base/metrics/persistent_memory_allocator_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/persistent_memory_allocator.cc
diff --git a/base/metrics/persistent_memory_allocator.cc b/base/metrics/persistent_memory_allocator.cc
index 120925753802e7a09669389d5b746a85fe64612e..22fa7115a2218b28f2a573c4c429141e73556dd5 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 {
@@ -215,6 +216,14 @@ PersistentMemoryAllocator::PersistentMemoryAllocator(
memcpy(name_cstr, name.data(), name.length());
}
} 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) {
+ SetCorrupt();
+ }
if (!readonly) {
// The allocator is attaching to a previously initialized segment of
// memory. Make sure the embedded data matches what has been passed.
@@ -656,18 +665,37 @@ LocalPersistentMemoryAllocator::~LocalPersistentMemoryAllocator() {
}
+//----- SharedPersistentMemoryAllocator ----------------------------------------
+
+SharedPersistentMemoryAllocator::SharedPersistentMemoryAllocator(
+ scoped_ptr<SharedMemory> memory,
+ uint64_t id,
+ base::StringPiece 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() {}
+
+// 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,
base::StringPiece name)
: PersistentMemoryAllocator(const_cast<uint8_t*>(file->data()),
file->length(), 0, id, name, true),
- mapped_file_(file) {}
+ mapped_file_(std::move(file)) {}
-FilePersistentMemoryAllocator::~FilePersistentMemoryAllocator() {
-}
+FilePersistentMemoryAllocator::~FilePersistentMemoryAllocator() {}
// static
bool FilePersistentMemoryAllocator::IsFileAcceptable(
« no previous file with comments | « base/metrics/persistent_memory_allocator.h ('k') | base/metrics/persistent_memory_allocator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698