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

Unified Diff: base/metrics/persistent_memory_allocator.cc

Issue 2534643002: Add support for turning pointers back to references. (Closed)
Patch Set: added underflow check Created 4 years, 1 month 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 672ef974634700343a4be0505c349029a6ec4a0d..4e6b7ef4d2191d6c939a3aa99b0e657ee202b292 100644
--- a/base/metrics/persistent_memory_allocator.cc
+++ b/base/metrics/persistent_memory_allocator.cc
@@ -453,6 +453,24 @@ size_t PersistentMemoryAllocator::used() const {
mem_size_);
}
+PersistentMemoryAllocator::Reference PersistentMemoryAllocator::GetAsReference(
+ const void* memory,
+ uint32_t type_id) const {
+ uintptr_t address = reinterpret_cast<uintptr_t>(memory);
+ if (address < reinterpret_cast<uintptr_t>(mem_base_))
+ return kReferenceNull;
+
+ uintptr_t offset = address - reinterpret_cast<uintptr_t>(mem_base_);
+ if (offset >= mem_size_ || offset < sizeof(BlockHeader))
+ return kReferenceNull;
+
+ Reference ref = static_cast<Reference>(offset) - sizeof(BlockHeader);
+ if (!GetBlockData(ref, type_id, kSizeAny))
+ return kReferenceNull;
+
+ return ref;
+}
+
size_t PersistentMemoryAllocator::GetAllocSize(Reference ref) const {
const volatile BlockHeader* const block = GetBlock(ref, 0, 0, false, false);
if (!block)
« 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