summaryrefslogtreecommitdiff
path: root/chromium/base/allocator/partition_allocator/partition_cookie.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/base/allocator/partition_allocator/partition_cookie.h')
-rw-r--r--chromium/base/allocator/partition_allocator/partition_cookie.h57
1 files changed, 41 insertions, 16 deletions
diff --git a/chromium/base/allocator/partition_allocator/partition_cookie.h b/chromium/base/allocator/partition_allocator/partition_cookie.h
index 750ac6154f8..ca29ab64f73 100644
--- a/chromium/base/allocator/partition_allocator/partition_cookie.h
+++ b/chromium/base/allocator/partition_allocator/partition_cookie.h
@@ -5,65 +5,90 @@
#ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_COOKIE_H_
#define BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_COOKIE_H_
+#include "base/allocator/buildflags.h"
+#include "base/allocator/partition_allocator/partition_alloc_check.h"
#include "base/compiler_specific.h"
-#include "base/logging.h"
namespace base {
namespace internal {
-#if DCHECK_IS_ON()
// Handles alignment up to XMM instructions on Intel.
static constexpr size_t kCookieSize = 16;
+// Cookies are enabled for debug builds, unless PartitionAlloc is used as the
+// malloc() implementation. This is a temporary workaround the alignment issues
+// caused by cookies. With them, PartitionAlloc cannot support posix_memalign(),
+// which is required.
+//
+// TODO(lizeb): Support cookies when used as the malloc() implementation.
+#if DCHECK_IS_ON() && !BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
+
static constexpr unsigned char kCookieValue[kCookieSize] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE, 0xD0, 0x0D,
0x13, 0x37, 0xF0, 0x05, 0xBA, 0x11, 0xAB, 0x1E};
-#endif
ALWAYS_INLINE void PartitionCookieCheckValue(void* ptr) {
-#if DCHECK_IS_ON()
unsigned char* cookie_ptr = reinterpret_cast<unsigned char*>(ptr);
for (size_t i = 0; i < kCookieSize; ++i, ++cookie_ptr)
- DCHECK(*cookie_ptr == kCookieValue[i]);
-#endif
+ PA_DCHECK(*cookie_ptr == kCookieValue[i]);
}
ALWAYS_INLINE size_t PartitionCookieSizeAdjustAdd(size_t size) {
-#if DCHECK_IS_ON()
// Add space for cookies, checking for integer overflow. TODO(palmer):
// Investigate the performance and code size implications of using
// CheckedNumeric throughout PA.
- DCHECK(size + (2 * kCookieSize) > size);
+ PA_DCHECK(size + (2 * kCookieSize) > size);
size += 2 * kCookieSize;
-#endif
return size;
}
ALWAYS_INLINE void* PartitionCookieFreePointerAdjust(void* ptr) {
-#if DCHECK_IS_ON()
// The value given to the application is actually just after the cookie.
ptr = static_cast<char*>(ptr) - kCookieSize;
-#endif
return ptr;
}
ALWAYS_INLINE size_t PartitionCookieSizeAdjustSubtract(size_t size) {
-#if DCHECK_IS_ON()
// Remove space for cookies.
- DCHECK(size >= 2 * kCookieSize);
+ PA_DCHECK(size >= 2 * kCookieSize);
size -= 2 * kCookieSize;
-#endif
return size;
}
-ALWAYS_INLINE void PartitionCookieWriteValue(void* ptr) {
+ALWAYS_INLINE size_t PartitionCookieOffsetSubtract(size_t offset) {
#if DCHECK_IS_ON()
+ // Convert offset from the beginning of the allocated slot to offset from
+ // the value given to the application, which is just after the cookie.
+ offset -= kCookieSize;
+#endif
+ return offset;
+}
+
+ALWAYS_INLINE void PartitionCookieWriteValue(void* ptr) {
unsigned char* cookie_ptr = reinterpret_cast<unsigned char*>(ptr);
for (size_t i = 0; i < kCookieSize; ++i, ++cookie_ptr)
*cookie_ptr = kCookieValue[i];
-#endif
}
+#else
+
+ALWAYS_INLINE void PartitionCookieCheckValue(void* ptr) {}
+
+ALWAYS_INLINE size_t PartitionCookieSizeAdjustAdd(size_t size) {
+ return size;
+}
+
+ALWAYS_INLINE void* PartitionCookieFreePointerAdjust(void* ptr) {
+ return ptr;
+}
+
+ALWAYS_INLINE size_t PartitionCookieSizeAdjustSubtract(size_t size) {
+ return size;
+}
+
+ALWAYS_INLINE void PartitionCookieWriteValue(void* ptr) {}
+#endif // DCHECK_IS_ON() && !BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
+
} // namespace internal
} // namespace base