45
45
46
46
// Initialized in HwasanAllocatorInit, an never changed.
47
47
static ALIGNED (16 ) u8 tail_magic[kShadowAlignment - 1];
48
+ static uptr max_malloc_size;
48
49
49
50
bool HwasanChunkView::IsAllocated () const {
50
51
return metadata_ && metadata_->IsAllocated ();
@@ -142,6 +143,12 @@ void HwasanAllocatorInit() {
142
143
GetAliasRegionStart ());
143
144
for (uptr i = 0 ; i < sizeof (tail_magic); i++)
144
145
tail_magic[i] = GetCurrentThread ()->GenerateRandomTag ();
146
+ if (common_flags ()->max_allocation_size_mb ) {
147
+ max_malloc_size = common_flags ()->max_allocation_size_mb << 20 ;
148
+ max_malloc_size = Min (max_malloc_size, kMaxAllowedMallocSize );
149
+ } else {
150
+ max_malloc_size = kMaxAllowedMallocSize ;
151
+ }
145
152
}
146
153
147
154
void HwasanAllocatorLock () { allocator.ForceLock (); }
@@ -164,13 +171,13 @@ static void *HwasanAllocate(StackTrace *stack, uptr orig_size, uptr alignment,
164
171
// Keep this consistent with LSAN and ASAN behavior.
165
172
if (UNLIKELY (orig_size == 0 ))
166
173
orig_size = 1 ;
167
- if (UNLIKELY (orig_size > kMaxAllowedMallocSize )) {
174
+ if (UNLIKELY (orig_size > max_malloc_size )) {
168
175
if (AllocatorMayReturnNull ()) {
169
176
Report (" WARNING: HWAddressSanitizer failed to allocate 0x%zx bytes\n " ,
170
177
orig_size);
171
178
return nullptr ;
172
179
}
173
- ReportAllocationSizeTooBig (orig_size, kMaxAllowedMallocSize , stack);
180
+ ReportAllocationSizeTooBig (orig_size, max_malloc_size , stack);
174
181
}
175
182
if (UNLIKELY (IsRssLimitExceeded ())) {
176
183
if (AllocatorMayReturnNull ())
0 commit comments