2424#include " sanitizer_common/sanitizer_allocator_report.h"
2525#include " sanitizer_common/sanitizer_errno.h"
2626
27- namespace __msan {
27+ using namespace __msan ;
2828
29+ namespace {
2930struct Metadata {
3031 uptr requested_size;
3132};
@@ -47,7 +48,9 @@ struct MsanMapUnmapCallback {
4748 }
4849 }
4950};
51+ } // namespace
5052
53+ namespace __msan {
5154// Note: to ensure that the allocator is compatible with the application memory
5255// layout (especially with high-entropy ASLR), kSpaceBeg and kSpaceSize must be
5356// duplicated as MappingDesc::ALLOCATOR in msan.h.
@@ -145,14 +148,15 @@ typedef SizeClassAllocator64<AP64> PrimaryAllocator;
145148#endif
146149typedef CombinedAllocator<PrimaryAllocator> Allocator;
147150typedef Allocator::AllocatorCache AllocatorCache;
151+ } // namespace __msan
148152
149153static Allocator allocator;
150154static AllocatorCache fallback_allocator_cache;
151155static StaticSpinMutex fallback_mutex;
152156
153157static uptr max_malloc_size;
154158
155- void MsanAllocatorInit () {
159+ void __msan:: MsanAllocatorInit () {
156160 SetAllocatorMayReturnNull (common_flags ()->allocator_may_return_null );
157161 allocator.Init (common_flags ()->allocator_release_to_os_interval_ms );
158162 if (common_flags ()->max_allocation_size_mb )
@@ -162,9 +166,9 @@ void MsanAllocatorInit() {
162166 max_malloc_size = kMaxAllowedMallocSize ;
163167}
164168
165- void LockAllocator () { allocator.ForceLock (); }
169+ void __msan:: LockAllocator () { allocator.ForceLock (); }
166170
167- void UnlockAllocator () { allocator.ForceUnlock (); }
171+ void __msan:: UnlockAllocator () { allocator.ForceUnlock (); }
168172
169173AllocatorCache *GetAllocatorCache (MsanThreadLocalMallocStorage *ms) {
170174 CHECK (ms);
@@ -235,7 +239,7 @@ static void *MsanAllocate(BufferedStackTrace *stack, uptr size, uptr alignment,
235239 return allocated;
236240}
237241
238- void MsanDeallocate (BufferedStackTrace *stack, void *p) {
242+ void __msan:: MsanDeallocate (BufferedStackTrace *stack, void *p) {
239243 CHECK (p);
240244 UnpoisonParam (1 );
241245 RunFreeHooks (p);
@@ -327,15 +331,15 @@ static uptr AllocationSizeFast(const void *p) {
327331 return reinterpret_cast <Metadata *>(allocator.GetMetaData (p))->requested_size ;
328332}
329333
330- void *msan_malloc (uptr size, BufferedStackTrace *stack) {
334+ void *__msan:: msan_malloc (uptr size, BufferedStackTrace *stack) {
331335 return SetErrnoOnNull (MsanAllocate (stack, size, sizeof (u64 ), false ));
332336}
333337
334- void *msan_calloc (uptr nmemb, uptr size, BufferedStackTrace *stack) {
338+ void *__msan:: msan_calloc (uptr nmemb, uptr size, BufferedStackTrace *stack) {
335339 return SetErrnoOnNull (MsanCalloc (stack, nmemb, size));
336340}
337341
338- void *msan_realloc (void *ptr, uptr size, BufferedStackTrace *stack) {
342+ void *__msan:: msan_realloc (void *ptr, uptr size, BufferedStackTrace *stack) {
339343 if (!ptr)
340344 return SetErrnoOnNull (MsanAllocate (stack, size, sizeof (u64 ), false ));
341345 if (size == 0 ) {
@@ -345,8 +349,8 @@ void *msan_realloc(void *ptr, uptr size, BufferedStackTrace *stack) {
345349 return SetErrnoOnNull (MsanReallocate (stack, ptr, size, sizeof (u64 )));
346350}
347351
348- void *msan_reallocarray (void *ptr, uptr nmemb, uptr size,
349- BufferedStackTrace *stack) {
352+ void *__msan:: msan_reallocarray (void *ptr, uptr nmemb, uptr size,
353+ BufferedStackTrace *stack) {
350354 if (UNLIKELY (CheckForCallocOverflow (size, nmemb))) {
351355 errno = errno_ENOMEM;
352356 if (AllocatorMayReturnNull ())
@@ -357,11 +361,11 @@ void *msan_reallocarray(void *ptr, uptr nmemb, uptr size,
357361 return msan_realloc (ptr, nmemb * size, stack);
358362}
359363
360- void *msan_valloc (uptr size, BufferedStackTrace *stack) {
364+ void *__msan:: msan_valloc (uptr size, BufferedStackTrace *stack) {
361365 return SetErrnoOnNull (MsanAllocate (stack, size, GetPageSizeCached (), false ));
362366}
363367
364- void *msan_pvalloc (uptr size, BufferedStackTrace *stack) {
368+ void *__msan:: msan_pvalloc (uptr size, BufferedStackTrace *stack) {
365369 uptr PageSize = GetPageSizeCached ();
366370 if (UNLIKELY (CheckForPvallocOverflow (size, PageSize))) {
367371 errno = errno_ENOMEM;
@@ -375,7 +379,8 @@ void *msan_pvalloc(uptr size, BufferedStackTrace *stack) {
375379 return SetErrnoOnNull (MsanAllocate (stack, size, PageSize, false ));
376380}
377381
378- void *msan_aligned_alloc (uptr alignment, uptr size, BufferedStackTrace *stack) {
382+ void *__msan::msan_aligned_alloc (uptr alignment, uptr size,
383+ BufferedStackTrace *stack) {
379384 if (UNLIKELY (!CheckAlignedAllocAlignmentAndSize (alignment, size))) {
380385 errno = errno_EINVAL;
381386 if (AllocatorMayReturnNull ())
@@ -386,7 +391,8 @@ void *msan_aligned_alloc(uptr alignment, uptr size, BufferedStackTrace *stack) {
386391 return SetErrnoOnNull (MsanAllocate (stack, size, alignment, false ));
387392}
388393
389- void *msan_memalign (uptr alignment, uptr size, BufferedStackTrace *stack) {
394+ void *__msan::msan_memalign (uptr alignment, uptr size,
395+ BufferedStackTrace *stack) {
390396 if (UNLIKELY (!IsPowerOfTwo (alignment))) {
391397 errno = errno_EINVAL;
392398 if (AllocatorMayReturnNull ())
@@ -397,8 +403,8 @@ void *msan_memalign(uptr alignment, uptr size, BufferedStackTrace *stack) {
397403 return SetErrnoOnNull (MsanAllocate (stack, size, alignment, false ));
398404}
399405
400- int msan_posix_memalign (void **memptr, uptr alignment, uptr size,
401- BufferedStackTrace *stack) {
406+ int __msan:: msan_posix_memalign (void **memptr, uptr alignment, uptr size,
407+ BufferedStackTrace *stack) {
402408 if (UNLIKELY (!CheckPosixMemalignAlignment (alignment))) {
403409 if (AllocatorMayReturnNull ())
404410 return errno_EINVAL;
@@ -414,10 +420,7 @@ int msan_posix_memalign(void **memptr, uptr alignment, uptr size,
414420 return 0 ;
415421}
416422
417- } // namespace __msan
418-
419- using namespace __msan ;
420-
423+ extern " C" {
421424uptr __sanitizer_get_current_allocated_bytes () {
422425 uptr stats[AllocatorStatCount];
423426 allocator.GetStats (stats);
@@ -452,3 +455,4 @@ uptr __sanitizer_get_allocated_size_fast(const void *p) {
452455}
453456
454457void __sanitizer_purge_allocator () { allocator.ForceReleaseToOS (); }
458+ }
0 commit comments