Commit d5d8bc3a authored by Chris Palmer's avatar Chris Palmer Committed by Commit Bot

[PartitionAlloc] Poison memory regions when freeing.

A last-ditch sanity check in case of memory corruption.

Bug: 680657
Change-Id: I79934eceb4fcb6ce64422cee5004f057d40a6cab
Reviewed-on: https://chromium-review.googlesource.com/1134523Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Chris Palmer <palmer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580297}
parent a89b53f6
...@@ -281,17 +281,44 @@ ALWAYS_INLINE void* PartitionRoot::Alloc(size_t size, const char* type_name) { ...@@ -281,17 +281,44 @@ ALWAYS_INLINE void* PartitionRoot::Alloc(size_t size, const char* type_name) {
#endif // defined(MEMORY_TOOL_REPLACES_ALLOCATOR) #endif // defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
} }
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.
DCHECK(PartitionAllocSupportsGetSize());
ptr = internal::PartitionCookieFreePointerAdjust(ptr);
internal::PartitionPage* page = internal::PartitionPage::FromPointer(ptr);
// TODO(palmer): See if we can afford to make this a CHECK.
DCHECK(internal::PartitionRootBase::IsValidPage(page));
size_t size = page->bucket->slot_size;
return internal::PartitionCookieSizeAdjustSubtract(size);
}
ALWAYS_INLINE void PartitionFree(void* ptr) { ALWAYS_INLINE void PartitionFree(void* ptr) {
#if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
free(ptr); free(ptr);
#else #else
void* original_ptr = ptr;
// TODO(palmer): Check ptr alignment before continuing. Shall we do the check // TODO(palmer): Check ptr alignment before continuing. Shall we do the check
// inside PartitionCookieFreePointerAdjust? // inside PartitionCookieFreePointerAdjust?
PartitionAllocHooks::FreeHookIfEnabled(ptr); PartitionAllocHooks::FreeHookIfEnabled(original_ptr);
ptr = internal::PartitionCookieFreePointerAdjust(ptr); ptr = internal::PartitionCookieFreePointerAdjust(ptr);
internal::PartitionPage* page = internal::PartitionPage::FromPointer(ptr); internal::PartitionPage* page = internal::PartitionPage::FromPointer(ptr);
// TODO(palmer): See if we can afford to make this a CHECK. // TODO(palmer): See if we can afford to make this a CHECK.
DCHECK(internal::PartitionRootBase::IsValidPage(page)); DCHECK(internal::PartitionRootBase::IsValidPage(page));
// This is somewhat redundant with |PartitionPage::Free|.
// TODO(crbug.com/680657): Doing this here might? make it OK to not do it
// there.
memset(original_ptr, 0xCD, PartitionAllocGetSize(original_ptr));
page->Free(ptr); page->Free(ptr);
#endif #endif
} }
...@@ -386,26 +413,6 @@ ALWAYS_INLINE size_t PartitionRootGeneric::ActualSize(size_t size) { ...@@ -386,26 +413,6 @@ ALWAYS_INLINE size_t PartitionRootGeneric::ActualSize(size_t size) {
#endif #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.
DCHECK(PartitionAllocSupportsGetSize());
ptr = internal::PartitionCookieFreePointerAdjust(ptr);
internal::PartitionPage* page = internal::PartitionPage::FromPointer(ptr);
// TODO(palmer): See if we can afford to make this a CHECK.
DCHECK(internal::PartitionRootBase::IsValidPage(page));
size_t size = page->bucket->slot_size;
return internal::PartitionCookieSizeAdjustSubtract(size);
}
template <size_t N> template <size_t N>
class SizeSpecificPartitionAllocator { class SizeSpecificPartitionAllocator {
public: public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment