OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 12 matching lines...) Expand all Loading... | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_ZONE_INL_H_ | 28 #ifndef V8_ZONE_INL_H_ |
29 #define V8_ZONE_INL_H_ | 29 #define V8_ZONE_INL_H_ |
30 | 30 |
31 #include "zone.h" | 31 #include "zone.h" |
32 | 32 |
33 #ifdef ADDRESS_SANITIZER | |
34 #include <sanitizer/asan_interface.h> | |
kcc1
2014/03/26 06:43:41
A style nit. I would do
#ifdef ADDRESS_SANITIZER
Jakob Kummerow
2014/03/26 09:59:12
Good idea, done for ASAN_UNPOISON_MEMORY_REGION, k
| |
35 #endif | |
36 | |
33 #include "counters.h" | 37 #include "counters.h" |
34 #include "isolate.h" | 38 #include "isolate.h" |
35 #include "utils.h" | 39 #include "utils.h" |
36 #include "v8-counters.h" | 40 #include "v8-counters.h" |
37 | 41 |
38 namespace v8 { | 42 namespace v8 { |
39 namespace internal { | 43 namespace internal { |
40 | 44 |
41 | 45 |
46 static const int kASanRedzoneBytes = 24; // Must be a multiple of 8. | |
47 | |
48 | |
42 inline void* Zone::New(int size) { | 49 inline void* Zone::New(int size) { |
43 // Round up the requested size to fit the alignment. | 50 // Round up the requested size to fit the alignment. |
44 size = RoundUp(size, kAlignment); | 51 size = RoundUp(size, kAlignment); |
45 | 52 |
46 // If the allocation size is divisible by 8 then we return an 8-byte aligned | 53 // If the allocation size is divisible by 8 then we return an 8-byte aligned |
47 // address. | 54 // address. |
48 if (kPointerSize == 4 && kAlignment == 4) { | 55 if (kPointerSize == 4 && kAlignment == 4) { |
49 position_ += ((~size) & 4) & (reinterpret_cast<intptr_t>(position_) & 4); | 56 position_ += ((~size) & 4) & (reinterpret_cast<intptr_t>(position_) & 4); |
50 } else { | 57 } else { |
51 ASSERT(kAlignment >= kPointerSize); | 58 ASSERT(kAlignment >= kPointerSize); |
52 } | 59 } |
53 | 60 |
54 // Check if the requested size is available without expanding. | 61 // Check if the requested size is available without expanding. |
55 Address result = position_; | 62 Address result = position_; |
56 | 63 |
57 if (size > limit_ - position_) { | 64 int size_with_redzone = |
58 result = NewExpand(size); | 65 #ifdef ADDRESS_SANITIZER |
66 size + kASanRedzoneBytes; | |
67 #else | |
68 size; | |
69 #endif | |
70 | |
71 if (size_with_redzone > limit_ - position_) { | |
72 result = NewExpand(size_with_redzone); | |
59 } else { | 73 } else { |
60 position_ += size; | 74 position_ += size_with_redzone; |
61 } | 75 } |
62 | 76 |
77 #ifdef ADDRESS_SANITIZER | |
78 Address redzone_position = result + size; | |
79 ASSERT(redzone_position + kASanRedzoneBytes == position_); | |
80 ASAN_POISON_MEMORY_REGION(redzone_position, kASanRedzoneBytes); | |
81 #endif | |
82 | |
63 // Check that the result has the proper alignment and return it. | 83 // Check that the result has the proper alignment and return it. |
64 ASSERT(IsAddressAligned(result, kAlignment, 0)); | 84 ASSERT(IsAddressAligned(result, kAlignment, 0)); |
65 allocation_size_ += size; | 85 allocation_size_ += size; |
66 return reinterpret_cast<void*>(result); | 86 return reinterpret_cast<void*>(result); |
67 } | 87 } |
68 | 88 |
69 | 89 |
70 template <typename T> | 90 template <typename T> |
71 T* Zone::NewArray(int length) { | 91 T* Zone::NewArray(int length) { |
92 CHECK(std::numeric_limits<int>::max() / static_cast<int>(sizeof(T)) > length); | |
72 return static_cast<T*>(New(length * sizeof(T))); | 93 return static_cast<T*>(New(length * sizeof(T))); |
73 } | 94 } |
74 | 95 |
75 | 96 |
76 bool Zone::excess_allocation() { | 97 bool Zone::excess_allocation() { |
77 return segment_bytes_allocated_ > kExcessLimit; | 98 return segment_bytes_allocated_ > kExcessLimit; |
78 } | 99 } |
79 | 100 |
80 | 101 |
81 void Zone::adjust_segment_bytes_allocated(int delta) { | 102 void Zone::adjust_segment_bytes_allocated(int delta) { |
(...skipping 29 matching lines...) Expand all Loading... | |
111 | 132 |
112 template <typename T> | 133 template <typename T> |
113 void* ZoneSplayTree<T>::operator new(size_t size, Zone* zone) { | 134 void* ZoneSplayTree<T>::operator new(size_t size, Zone* zone) { |
114 return zone->New(static_cast<int>(size)); | 135 return zone->New(static_cast<int>(size)); |
115 } | 136 } |
116 | 137 |
117 | 138 |
118 } } // namespace v8::internal | 139 } } // namespace v8::internal |
119 | 140 |
120 #endif // V8_ZONE_INL_H_ | 141 #endif // V8_ZONE_INL_H_ |
OLD | NEW |