// These two byte values match tcmalloc.
static const unsigned char kUninitializedByte = 0xAB;
static const unsigned char kFreedByte = 0xCD;
-#if CPU(64BIT)
-static const uintptr_t kCookieValue = 0xDEADBEEFDEADBEEFul;
-#else
-static const uintptr_t kCookieValue = 0xDEADBEEFu;
-#endif
+static const uint32_t kCookieValue = 0xDEADBEEFu;
+static const size_t kCookieSize = 16; // Handles alignment up to XMM instructions on Intel.
#endif
struct PartitionBucket;
{
#ifndef NDEBUG
// Add space for cookies, checking for integer overflow.
- ASSERT(size + (2 * sizeof(uintptr_t)) > size);
- size += 2 * sizeof(uintptr_t);
+ ASSERT(size + (2 * kCookieSize) > size);
+ size += 2 * kCookieSize;
#endif
return size;
}
{
#ifndef NDEBUG
// Remove space for cookies.
- ASSERT(size >= 2 * sizeof(uintptr_t));
- size -= 2 * sizeof(uintptr_t);
+ ASSERT(size >= 2 * kCookieSize);
+ size -= 2 * kCookieSize;
#endif
return size;
}
{
#ifndef NDEBUG
// The value given to the application is actually just after the cookie.
- ptr = static_cast<uintptr_t*>(ptr) - 1;
+ ptr = static_cast<char*>(ptr) - kCookieSize;
#endif
return ptr;
}
+ALWAYS_INLINE void partitionCookieWriteValue(void* ptr)
+{
+#ifndef NDEBUG
+ uint32_t* cookiePtr = reinterpret_cast<uint32_t*>(ptr);
+ for (size_t i = 0; i < kCookieSize / sizeof(kCookieValue); ++i, ++cookiePtr)
+ *cookiePtr = kCookieValue;
+#endif
+}
+
+ALWAYS_INLINE void partitionCookieCheckValue(void* ptr)
+{
+#ifndef NDEBUG
+ uint32_t* cookiePtr = reinterpret_cast<uint32_t*>(ptr);
+ for (size_t i = 0; i < kCookieSize / sizeof(kCookieValue); ++i, ++cookiePtr)
+ ASSERT(*cookiePtr == kCookieValue);
+#endif
+}
+
ALWAYS_INLINE char* partitionSuperPageToMetadataArea(char* ptr)
{
uintptr_t pointerAsUint = reinterpret_cast<uintptr_t>(ptr);
page = partitionPointerToPage(ret);
size_t bucketSize = page->bucket->slotSize;
memset(ret, kUninitializedByte, bucketSize);
- *(static_cast<uintptr_t*>(ret)) = kCookieValue;
- void* retEnd = static_cast<char*>(ret) + bucketSize;
- *(static_cast<uintptr_t*>(retEnd) - 1) = kCookieValue;
+ partitionCookieWriteValue(ret);
+ partitionCookieWriteValue(reinterpret_cast<char*>(ret) + bucketSize - kCookieSize);
// The value given to the application is actually just after the cookie.
- ret = static_cast<uintptr_t*>(ret) + 1;
+ ret = static_cast<char*>(ret) + kCookieSize;
#endif
return ret;
}
// If these asserts fire, you probably corrupted memory.
#ifndef NDEBUG
size_t bucketSize = page->bucket->slotSize;
- void* ptrEnd = static_cast<char*>(ptr) + bucketSize;
- ASSERT(*(static_cast<uintptr_t*>(ptr)) == kCookieValue);
- ASSERT(*(static_cast<uintptr_t*>(ptrEnd) - 1) == kCookieValue);
+ partitionCookieCheckValue(ptr);
+ partitionCookieCheckValue(reinterpret_cast<char*>(ptr) + bucketSize - kCookieSize);
memset(ptr, kFreedByte, bucketSize);
#endif
ASSERT(page->numAllocatedSlots);