Skip to content

Commit eea627e

Browse files
authored
[NFC][msan] Switch allocator interface to use BufferedStackTrace (#77363)
We will need it to unwind for fatal errors.
1 parent 7173ae9 commit eea627e

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

compiler-rt/lib/msan/msan.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,18 +255,19 @@ char *GetProcSelfMaps();
255255
void InitializeInterceptors();
256256

257257
void MsanAllocatorInit();
258-
void MsanDeallocate(StackTrace *stack, void *ptr);
259-
260-
void *msan_malloc(uptr size, StackTrace *stack);
261-
void *msan_calloc(uptr nmemb, uptr size, StackTrace *stack);
262-
void *msan_realloc(void *ptr, uptr size, StackTrace *stack);
263-
void *msan_reallocarray(void *ptr, uptr nmemb, uptr size, StackTrace *stack);
264-
void *msan_valloc(uptr size, StackTrace *stack);
265-
void *msan_pvalloc(uptr size, StackTrace *stack);
266-
void *msan_aligned_alloc(uptr alignment, uptr size, StackTrace *stack);
267-
void *msan_memalign(uptr alignment, uptr size, StackTrace *stack);
258+
void MsanDeallocate(BufferedStackTrace *stack, void *ptr);
259+
260+
void *msan_malloc(uptr size, BufferedStackTrace *stack);
261+
void *msan_calloc(uptr nmemb, uptr size, BufferedStackTrace *stack);
262+
void *msan_realloc(void *ptr, uptr size, BufferedStackTrace *stack);
263+
void *msan_reallocarray(void *ptr, uptr nmemb, uptr size,
264+
BufferedStackTrace *stack);
265+
void *msan_valloc(uptr size, BufferedStackTrace *stack);
266+
void *msan_pvalloc(uptr size, BufferedStackTrace *stack);
267+
void *msan_aligned_alloc(uptr alignment, uptr size, BufferedStackTrace *stack);
268+
void *msan_memalign(uptr alignment, uptr size, BufferedStackTrace *stack);
268269
int msan_posix_memalign(void **memptr, uptr alignment, uptr size,
269-
StackTrace *stack);
270+
BufferedStackTrace *stack);
270271

271272
void InstallTrapHandler();
272273
void InstallAtExitHandler();

compiler-rt/lib/msan/msan_allocator.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void MsanThreadLocalMallocStorage::CommitBack() {
178178
allocator.DestroyCache(GetAllocatorCache(this));
179179
}
180180

181-
static void *MsanAllocate(StackTrace *stack, uptr size, uptr alignment,
181+
static void *MsanAllocate(BufferedStackTrace *stack, uptr size, uptr alignment,
182182
bool zeroise) {
183183
if (size > max_malloc_size) {
184184
if (AllocatorMayReturnNull()) {
@@ -229,7 +229,7 @@ static void *MsanAllocate(StackTrace *stack, uptr size, uptr alignment,
229229
return allocated;
230230
}
231231

232-
void MsanDeallocate(StackTrace *stack, void *p) {
232+
void MsanDeallocate(BufferedStackTrace *stack, void *p) {
233233
CHECK(p);
234234
UnpoisonParam(1);
235235
RunFreeHooks(p);
@@ -259,8 +259,8 @@ void MsanDeallocate(StackTrace *stack, void *p) {
259259
}
260260
}
261261

262-
static void *MsanReallocate(StackTrace *stack, void *old_p, uptr new_size,
263-
uptr alignment) {
262+
static void *MsanReallocate(BufferedStackTrace *stack, void *old_p,
263+
uptr new_size, uptr alignment) {
264264
Metadata *meta = reinterpret_cast<Metadata*>(allocator.GetMetaData(old_p));
265265
uptr old_size = meta->requested_size;
266266
uptr actually_allocated_size = allocator.GetActuallyAllocatedSize(old_p);
@@ -284,7 +284,7 @@ static void *MsanReallocate(StackTrace *stack, void *old_p, uptr new_size,
284284
return new_p;
285285
}
286286

287-
static void *MsanCalloc(StackTrace *stack, uptr nmemb, uptr size) {
287+
static void *MsanCalloc(BufferedStackTrace *stack, uptr nmemb, uptr size) {
288288
if (UNLIKELY(CheckForCallocOverflow(size, nmemb))) {
289289
if (AllocatorMayReturnNull())
290290
return nullptr;
@@ -320,15 +320,15 @@ static uptr AllocationSizeFast(const void *p) {
320320
return reinterpret_cast<Metadata *>(allocator.GetMetaData(p))->requested_size;
321321
}
322322

323-
void *msan_malloc(uptr size, StackTrace *stack) {
323+
void *msan_malloc(uptr size, BufferedStackTrace *stack) {
324324
return SetErrnoOnNull(MsanAllocate(stack, size, sizeof(u64), false));
325325
}
326326

327-
void *msan_calloc(uptr nmemb, uptr size, StackTrace *stack) {
327+
void *msan_calloc(uptr nmemb, uptr size, BufferedStackTrace *stack) {
328328
return SetErrnoOnNull(MsanCalloc(stack, nmemb, size));
329329
}
330330

331-
void *msan_realloc(void *ptr, uptr size, StackTrace *stack) {
331+
void *msan_realloc(void *ptr, uptr size, BufferedStackTrace *stack) {
332332
if (!ptr)
333333
return SetErrnoOnNull(MsanAllocate(stack, size, sizeof(u64), false));
334334
if (size == 0) {
@@ -338,7 +338,8 @@ void *msan_realloc(void *ptr, uptr size, StackTrace *stack) {
338338
return SetErrnoOnNull(MsanReallocate(stack, ptr, size, sizeof(u64)));
339339
}
340340

341-
void *msan_reallocarray(void *ptr, uptr nmemb, uptr size, StackTrace *stack) {
341+
void *msan_reallocarray(void *ptr, uptr nmemb, uptr size,
342+
BufferedStackTrace *stack) {
342343
if (UNLIKELY(CheckForCallocOverflow(size, nmemb))) {
343344
errno = errno_ENOMEM;
344345
if (AllocatorMayReturnNull())
@@ -348,11 +349,11 @@ void *msan_reallocarray(void *ptr, uptr nmemb, uptr size, StackTrace *stack) {
348349
return msan_realloc(ptr, nmemb * size, stack);
349350
}
350351

351-
void *msan_valloc(uptr size, StackTrace *stack) {
352+
void *msan_valloc(uptr size, BufferedStackTrace *stack) {
352353
return SetErrnoOnNull(MsanAllocate(stack, size, GetPageSizeCached(), false));
353354
}
354355

355-
void *msan_pvalloc(uptr size, StackTrace *stack) {
356+
void *msan_pvalloc(uptr size, BufferedStackTrace *stack) {
356357
uptr PageSize = GetPageSizeCached();
357358
if (UNLIKELY(CheckForPvallocOverflow(size, PageSize))) {
358359
errno = errno_ENOMEM;
@@ -365,7 +366,7 @@ void *msan_pvalloc(uptr size, StackTrace *stack) {
365366
return SetErrnoOnNull(MsanAllocate(stack, size, PageSize, false));
366367
}
367368

368-
void *msan_aligned_alloc(uptr alignment, uptr size, StackTrace *stack) {
369+
void *msan_aligned_alloc(uptr alignment, uptr size, BufferedStackTrace *stack) {
369370
if (UNLIKELY(!CheckAlignedAllocAlignmentAndSize(alignment, size))) {
370371
errno = errno_EINVAL;
371372
if (AllocatorMayReturnNull())
@@ -375,7 +376,7 @@ void *msan_aligned_alloc(uptr alignment, uptr size, StackTrace *stack) {
375376
return SetErrnoOnNull(MsanAllocate(stack, size, alignment, false));
376377
}
377378

378-
void *msan_memalign(uptr alignment, uptr size, StackTrace *stack) {
379+
void *msan_memalign(uptr alignment, uptr size, BufferedStackTrace *stack) {
379380
if (UNLIKELY(!IsPowerOfTwo(alignment))) {
380381
errno = errno_EINVAL;
381382
if (AllocatorMayReturnNull())
@@ -386,7 +387,7 @@ void *msan_memalign(uptr alignment, uptr size, StackTrace *stack) {
386387
}
387388

388389
int msan_posix_memalign(void **memptr, uptr alignment, uptr size,
389-
StackTrace *stack) {
390+
BufferedStackTrace *stack) {
390391
if (UNLIKELY(!CheckPosixMemalignAlignment(alignment))) {
391392
if (AllocatorMayReturnNull())
392393
return errno_EINVAL;

0 commit comments

Comments
 (0)