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

Unified Diff: src/zone/zone.cc

Issue 2615533007: Ensure Zone returns correctly aligned pointers for allocations with
Patch Set: Created 3 years, 11 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/zone/zone.cc
diff --git a/src/zone/zone.cc b/src/zone/zone.cc
index 7228081d7d75825d362229d5a28c4f2312700373..bd20032680067e191a1651d1460849fab5ae6aa6 100644
--- a/src/zone/zone.cc
+++ b/src/zone/zone.cc
@@ -91,6 +91,9 @@ void* Zone::New(size_t size) {
// Check that the result has the proper alignment and return it.
DCHECK(IsAddressAligned(result, kAlignment, 0));
+ if (kPointerSize == 4 && kAlignment == 4) {
+ DCHECK((size & 4) || IsAddressAligned(result, 8, 0));
+ }
allocation_size_ += size;
return reinterpret_cast<void*>(result);
}
@@ -173,6 +176,9 @@ Address Zone::NewExpand(size_t size) {
// Recompute 'top' and 'limit' based on the new segment.
Address result = RoundUp(segment->start(), kAlignment);
+ if (kPointerSize == 4 && kAlignment == 4) {
+ result += ((~size) & 4) & (reinterpret_cast<intptr_t>(result) & 4);
+ }
position_ = result + size;
// Check for address overflow.
// (Should not happen since the segment is guaranteed to accomodate
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698