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

Unified Diff: Source/wtf/PartitionAlloc.h

Issue 169523004: Add partitionAllocGetSize() for determining actual size of allocation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: adjust test sizes, and reword/fix comments Created 6 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 | « no previous file | Source/wtf/PartitionAllocTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/PartitionAlloc.h
diff --git a/Source/wtf/PartitionAlloc.h b/Source/wtf/PartitionAlloc.h
index b1354777c6686b1566ab0a8cb56722ce9aedc7d8..3da9adcfe90b9004e0f144cede94e9c4074d84d4 100644
--- a/Source/wtf/PartitionAlloc.h
+++ b/Source/wtf/PartitionAlloc.h
@@ -565,6 +565,27 @@ ALWAYS_INLINE void partitionFreeGeneric(PartitionRootGeneric* root, void* ptr)
#endif
}
+ALWAYS_INLINE bool partitionAllocSupportsGetSize()
+{
+#if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
+ return false;
+#else
+ return true;
+#endif
+}
+
+ALWAYS_INLINE size_t partitionAllocGetSize(void* ptr)
+{
+ // No need to lock here. Only 'ptr' being freed by another thread could
+ // cause trouble, and the caller is responsible for that not happening.
+ ASSERT(partitionAllocSupportsGetSize());
+ ptr = partitionCookieFreePointerAdjust(ptr);
+ ASSERT(partitionPointerIsValid(ptr));
+ PartitionPage* page = partitionPointerToPage(ptr);
+ size_t size = page->bucket->slotSize;
+ return partitionCookieSizeAdjustSubtract(size);
+}
+
// N (or more accurately, N - sizeof(void*)) represents the largest size in
// bytes that will be handled by a SizeSpecificPartitionAllocator.
// Attempts to partitionAlloc() more than this amount will fail.
@@ -602,5 +623,7 @@ using WTF::partitionFree;
using WTF::partitionAllocGeneric;
using WTF::partitionFreeGeneric;
using WTF::partitionReallocGeneric;
+using WTF::partitionAllocSupportsGetSize;
+using WTF::partitionAllocGetSize;
#endif // WTF_PartitionAlloc_h
« no previous file with comments | « no previous file | Source/wtf/PartitionAllocTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698