@@ -180,16 +180,18 @@ void MsanThreadLocalMallocStorage::CommitBack() {
180
180
181
181
static void *MsanAllocate (BufferedStackTrace *stack, uptr size, uptr alignment,
182
182
bool zeroise) {
183
- if (size > max_malloc_size) {
183
+ if (UNLIKELY ( size > max_malloc_size) ) {
184
184
if (AllocatorMayReturnNull ()) {
185
185
Report (" WARNING: MemorySanitizer failed to allocate 0x%zx bytes\n " , size);
186
186
return nullptr ;
187
187
}
188
+ GET_FATAL_STACK_TRACE_AGAIN_IF_EMPTY (stack);
188
189
ReportAllocationSizeTooBig (size, max_malloc_size, stack);
189
190
}
190
191
if (UNLIKELY (IsRssLimitExceeded ())) {
191
192
if (AllocatorMayReturnNull ())
192
193
return nullptr ;
194
+ GET_FATAL_STACK_TRACE_AGAIN_IF_EMPTY (stack);
193
195
ReportRssLimitExceeded (stack);
194
196
}
195
197
MsanThread *t = GetCurrentThread ();
@@ -206,6 +208,7 @@ static void *MsanAllocate(BufferedStackTrace *stack, uptr size, uptr alignment,
206
208
SetAllocatorOutOfMemory ();
207
209
if (AllocatorMayReturnNull ())
208
210
return nullptr ;
211
+ GET_FATAL_STACK_TRACE_AGAIN_IF_EMPTY (stack);
209
212
ReportOutOfMemory (size, stack);
210
213
}
211
214
Metadata *meta =
@@ -288,6 +291,7 @@ static void *MsanCalloc(BufferedStackTrace *stack, uptr nmemb, uptr size) {
288
291
if (UNLIKELY (CheckForCallocOverflow (size, nmemb))) {
289
292
if (AllocatorMayReturnNull ())
290
293
return nullptr ;
294
+ GET_FATAL_STACK_TRACE_AGAIN_IF_EMPTY (stack);
291
295
ReportCallocOverflow (nmemb, size, stack);
292
296
}
293
297
return MsanAllocate (stack, nmemb * size, sizeof (u64 ), true );
@@ -344,6 +348,7 @@ void *msan_reallocarray(void *ptr, uptr nmemb, uptr size,
344
348
errno = errno_ENOMEM;
345
349
if (AllocatorMayReturnNull ())
346
350
return nullptr ;
351
+ GET_FATAL_STACK_TRACE_AGAIN_IF_EMPTY (stack);
347
352
ReportReallocArrayOverflow (nmemb, size, stack);
348
353
}
349
354
return msan_realloc (ptr, nmemb * size, stack);
@@ -359,6 +364,7 @@ void *msan_pvalloc(uptr size, BufferedStackTrace *stack) {
359
364
errno = errno_ENOMEM;
360
365
if (AllocatorMayReturnNull ())
361
366
return nullptr ;
367
+ GET_FATAL_STACK_TRACE_AGAIN_IF_EMPTY (stack);
362
368
ReportPvallocOverflow (size, stack);
363
369
}
364
370
// pvalloc(0) should allocate one page.
@@ -371,6 +377,7 @@ void *msan_aligned_alloc(uptr alignment, uptr size, BufferedStackTrace *stack) {
371
377
errno = errno_EINVAL;
372
378
if (AllocatorMayReturnNull ())
373
379
return nullptr ;
380
+ GET_FATAL_STACK_TRACE_AGAIN_IF_EMPTY (stack);
374
381
ReportInvalidAlignedAllocAlignment (size, alignment, stack);
375
382
}
376
383
return SetErrnoOnNull (MsanAllocate (stack, size, alignment, false ));
@@ -381,6 +388,7 @@ void *msan_memalign(uptr alignment, uptr size, BufferedStackTrace *stack) {
381
388
errno = errno_EINVAL;
382
389
if (AllocatorMayReturnNull ())
383
390
return nullptr ;
391
+ GET_FATAL_STACK_TRACE_AGAIN_IF_EMPTY (stack);
384
392
ReportInvalidAllocationAlignment (alignment, stack);
385
393
}
386
394
return SetErrnoOnNull (MsanAllocate (stack, size, alignment, false ));
@@ -391,6 +399,7 @@ int msan_posix_memalign(void **memptr, uptr alignment, uptr size,
391
399
if (UNLIKELY (!CheckPosixMemalignAlignment (alignment))) {
392
400
if (AllocatorMayReturnNull ())
393
401
return errno_EINVAL;
402
+ GET_FATAL_STACK_TRACE_AGAIN_IF_EMPTY (stack);
394
403
ReportInvalidPosixMemalignAlignment (alignment, stack);
395
404
}
396
405
void *ptr = MsanAllocate (stack, size, alignment, false );
0 commit comments