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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/zone/zone.h" 5 #include "src/zone/zone.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 8
9 #include "src/v8.h" 9 #include "src/v8.h"
10 10
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } else { 84 } else {
85 position_ += size_with_redzone; 85 position_ += size_with_redzone;
86 } 86 }
87 87
88 Address redzone_position = result + size; 88 Address redzone_position = result + size;
89 DCHECK(redzone_position + kASanRedzoneBytes == position_); 89 DCHECK(redzone_position + kASanRedzoneBytes == position_);
90 ASAN_POISON_MEMORY_REGION(redzone_position, kASanRedzoneBytes); 90 ASAN_POISON_MEMORY_REGION(redzone_position, kASanRedzoneBytes);
91 91
92 // Check that the result has the proper alignment and return it. 92 // Check that the result has the proper alignment and return it.
93 DCHECK(IsAddressAligned(result, kAlignment, 0)); 93 DCHECK(IsAddressAligned(result, kAlignment, 0));
94 if (kPointerSize == 4 && kAlignment == 4) {
95 DCHECK((size & 4) || IsAddressAligned(result, 8, 0));
96 }
94 allocation_size_ += size; 97 allocation_size_ += size;
95 return reinterpret_cast<void*>(result); 98 return reinterpret_cast<void*>(result);
96 } 99 }
97 100
98 void Zone::DeleteAll() { 101 void Zone::DeleteAll() {
99 // Traverse the chained list of segments and return them all to the allocator. 102 // Traverse the chained list of segments and return them all to the allocator.
100 for (Segment* current = segment_head_; current;) { 103 for (Segment* current = segment_head_; current;) {
101 Segment* next = current->next(); 104 Segment* next = current->next();
102 size_t size = current->size(); 105 size_t size = current->size();
103 106
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return nullptr; 169 return nullptr;
167 } 170 }
168 Segment* segment = NewSegment(new_size); 171 Segment* segment = NewSegment(new_size);
169 if (segment == nullptr) { 172 if (segment == nullptr) {
170 V8::FatalProcessOutOfMemory("Zone"); 173 V8::FatalProcessOutOfMemory("Zone");
171 return nullptr; 174 return nullptr;
172 } 175 }
173 176
174 // Recompute 'top' and 'limit' based on the new segment. 177 // Recompute 'top' and 'limit' based on the new segment.
175 Address result = RoundUp(segment->start(), kAlignment); 178 Address result = RoundUp(segment->start(), kAlignment);
179 if (kPointerSize == 4 && kAlignment == 4) {
180 result += ((~size) & 4) & (reinterpret_cast<intptr_t>(result) & 4);
181 }
176 position_ = result + size; 182 position_ = result + size;
177 // Check for address overflow. 183 // Check for address overflow.
178 // (Should not happen since the segment is guaranteed to accomodate 184 // (Should not happen since the segment is guaranteed to accomodate
179 // size bytes + header and alignment padding) 185 // size bytes + header and alignment padding)
180 DCHECK(reinterpret_cast<uintptr_t>(position_) >= 186 DCHECK(reinterpret_cast<uintptr_t>(position_) >=
181 reinterpret_cast<uintptr_t>(result)); 187 reinterpret_cast<uintptr_t>(result));
182 limit_ = segment->end(); 188 limit_ = segment->end();
183 DCHECK(position_ <= limit_); 189 DCHECK(position_ <= limit_);
184 return result; 190 return result;
185 } 191 }
186 192
187 } // namespace internal 193 } // namespace internal
188 } // namespace v8 194 } // namespace v8
OLDNEW
« 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