11fb612d0SJianzhou Zhao //===-- dfsan_allocator.cpp -------------------------- --------------------===// 21fb612d0SJianzhou Zhao // 31fb612d0SJianzhou Zhao // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 41fb612d0SJianzhou Zhao // See https://llvm.org/LICENSE.txt for license information. 51fb612d0SJianzhou Zhao // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 61fb612d0SJianzhou Zhao // 71fb612d0SJianzhou Zhao //===----------------------------------------------------------------------===// 81fb612d0SJianzhou Zhao // 91fb612d0SJianzhou Zhao // This file is a part of DataflowSanitizer. 101fb612d0SJianzhou Zhao // 111fb612d0SJianzhou Zhao // DataflowSanitizer allocator. 121fb612d0SJianzhou Zhao //===----------------------------------------------------------------------===// 131fb612d0SJianzhou Zhao 141fb612d0SJianzhou Zhao #include "dfsan_allocator.h" 151fb612d0SJianzhou Zhao 161fb612d0SJianzhou Zhao #include "dfsan.h" 171fb612d0SJianzhou Zhao #include "dfsan_flags.h" 181fb612d0SJianzhou Zhao #include "dfsan_thread.h" 191fb612d0SJianzhou Zhao #include "sanitizer_common/sanitizer_allocator.h" 201fb612d0SJianzhou Zhao #include "sanitizer_common/sanitizer_allocator_checks.h" 211fb612d0SJianzhou Zhao #include "sanitizer_common/sanitizer_allocator_interface.h" 221fb612d0SJianzhou Zhao #include "sanitizer_common/sanitizer_allocator_report.h" 231fb612d0SJianzhou Zhao #include "sanitizer_common/sanitizer_errno.h" 241fb612d0SJianzhou Zhao 25*80eea015SFangrui Song using namespace __dfsan; 26*80eea015SFangrui Song 27*80eea015SFangrui Song namespace { 281fb612d0SJianzhou Zhao 291fb612d0SJianzhou Zhao struct Metadata { 301fb612d0SJianzhou Zhao uptr requested_size; 311fb612d0SJianzhou Zhao }; 321fb612d0SJianzhou Zhao 331fb612d0SJianzhou Zhao struct DFsanMapUnmapCallback { 341fb612d0SJianzhou Zhao void OnMap(uptr p, uptr size) const { dfsan_set_label(0, (void *)p, size); } 3596928abbSVitaly Buka void OnMapSecondary(uptr p, uptr size, uptr user_begin, 3696928abbSVitaly Buka uptr user_size) const { 3796928abbSVitaly Buka OnMap(p, size); 3896928abbSVitaly Buka } 391fb612d0SJianzhou Zhao void OnUnmap(uptr p, uptr size) const { dfsan_set_label(0, (void *)p, size); } 401fb612d0SJianzhou Zhao }; 411fb612d0SJianzhou Zhao 4262ed009cSThurston Dang // Note: to ensure that the allocator is compatible with the application memory 4362ed009cSThurston Dang // layout (especially with high-entropy ASLR), kSpaceBeg and kSpaceSize must be 4462ed009cSThurston Dang // duplicated as MappingDesc::ALLOCATOR in dfsan_platform.h. 45de5416cbSFangrui Song #if defined(__aarch64__) 46de5416cbSFangrui Song const uptr kAllocatorSpace = 0xE00000000000ULL; 47de5416cbSFangrui Song #else 48de5416cbSFangrui Song const uptr kAllocatorSpace = 0x700000000000ULL; 49de5416cbSFangrui Song #endif 50511077dfSWu Yingcong const uptr kMaxAllowedMallocSize = 1ULL << 40; 511fb612d0SJianzhou Zhao 521fb612d0SJianzhou Zhao struct AP64 { // Allocator64 parameters. Deliberately using a short name. 5345f6d552SAndrew Browne static const uptr kSpaceBeg = kAllocatorSpace; 541fb612d0SJianzhou Zhao static const uptr kSpaceSize = 0x40000000000; // 4T. 551fb612d0SJianzhou Zhao static const uptr kMetadataSize = sizeof(Metadata); 561fb612d0SJianzhou Zhao typedef DefaultSizeClassMap SizeClassMap; 571fb612d0SJianzhou Zhao typedef DFsanMapUnmapCallback MapUnmapCallback; 581fb612d0SJianzhou Zhao static const uptr kFlags = 0; 591fb612d0SJianzhou Zhao using AddressSpaceView = LocalAddressSpaceView; 601fb612d0SJianzhou Zhao }; 611fb612d0SJianzhou Zhao 621fb612d0SJianzhou Zhao typedef SizeClassAllocator64<AP64> PrimaryAllocator; 631fb612d0SJianzhou Zhao 641fb612d0SJianzhou Zhao typedef CombinedAllocator<PrimaryAllocator> Allocator; 651fb612d0SJianzhou Zhao typedef Allocator::AllocatorCache AllocatorCache; 661fb612d0SJianzhou Zhao 671fb612d0SJianzhou Zhao static Allocator allocator; 681fb612d0SJianzhou Zhao static AllocatorCache fallback_allocator_cache; 691fb612d0SJianzhou Zhao static StaticSpinMutex fallback_mutex; 701fb612d0SJianzhou Zhao 711fb612d0SJianzhou Zhao static uptr max_malloc_size; 72*80eea015SFangrui Song } // namespace 731fb612d0SJianzhou Zhao 74*80eea015SFangrui Song void __dfsan::dfsan_allocator_init() { 751fb612d0SJianzhou Zhao SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null); 761fb612d0SJianzhou Zhao allocator.Init(common_flags()->allocator_release_to_os_interval_ms); 771fb612d0SJianzhou Zhao if (common_flags()->max_allocation_size_mb) 781fb612d0SJianzhou Zhao max_malloc_size = Min(common_flags()->max_allocation_size_mb << 20, 791fb612d0SJianzhou Zhao kMaxAllowedMallocSize); 801fb612d0SJianzhou Zhao else 811fb612d0SJianzhou Zhao max_malloc_size = kMaxAllowedMallocSize; 821fb612d0SJianzhou Zhao } 831fb612d0SJianzhou Zhao 84*80eea015SFangrui Song static AllocatorCache *GetAllocatorCache(DFsanThreadLocalMallocStorage *ms) { 851fb612d0SJianzhou Zhao CHECK(ms); 861fb612d0SJianzhou Zhao CHECK_LE(sizeof(AllocatorCache), sizeof(ms->allocator_cache)); 871fb612d0SJianzhou Zhao return reinterpret_cast<AllocatorCache *>(ms->allocator_cache); 881fb612d0SJianzhou Zhao } 891fb612d0SJianzhou Zhao 901fb612d0SJianzhou Zhao void DFsanThreadLocalMallocStorage::CommitBack() { 911fb612d0SJianzhou Zhao allocator.SwallowCache(GetAllocatorCache(this)); 921fb612d0SJianzhou Zhao } 931fb612d0SJianzhou Zhao 941fb612d0SJianzhou Zhao static void *DFsanAllocate(uptr size, uptr alignment, bool zeroise) { 951fb612d0SJianzhou Zhao if (size > max_malloc_size) { 961fb612d0SJianzhou Zhao if (AllocatorMayReturnNull()) { 971fb612d0SJianzhou Zhao Report("WARNING: DataflowSanitizer failed to allocate 0x%zx bytes\n", 981fb612d0SJianzhou Zhao size); 991fb612d0SJianzhou Zhao return nullptr; 1001fb612d0SJianzhou Zhao } 1014cad17deSFlorian Mayer UNINITIALIZED BufferedStackTrace stack; 1021fb612d0SJianzhou Zhao ReportAllocationSizeTooBig(size, max_malloc_size, &stack); 1031fb612d0SJianzhou Zhao } 10463180012SVitaly Buka if (UNLIKELY(IsRssLimitExceeded())) { 10563180012SVitaly Buka if (AllocatorMayReturnNull()) 10663180012SVitaly Buka return nullptr; 1074cad17deSFlorian Mayer UNINITIALIZED BufferedStackTrace stack; 10863180012SVitaly Buka ReportRssLimitExceeded(&stack); 10963180012SVitaly Buka } 1101fb612d0SJianzhou Zhao DFsanThread *t = GetCurrentThread(); 1111fb612d0SJianzhou Zhao void *allocated; 1121fb612d0SJianzhou Zhao if (t) { 1131fb612d0SJianzhou Zhao AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage()); 1141fb612d0SJianzhou Zhao allocated = allocator.Allocate(cache, size, alignment); 1151fb612d0SJianzhou Zhao } else { 1161fb612d0SJianzhou Zhao SpinMutexLock l(&fallback_mutex); 1171fb612d0SJianzhou Zhao AllocatorCache *cache = &fallback_allocator_cache; 1181fb612d0SJianzhou Zhao allocated = allocator.Allocate(cache, size, alignment); 1191fb612d0SJianzhou Zhao } 1201fb612d0SJianzhou Zhao if (UNLIKELY(!allocated)) { 1211fb612d0SJianzhou Zhao SetAllocatorOutOfMemory(); 1221fb612d0SJianzhou Zhao if (AllocatorMayReturnNull()) 1231fb612d0SJianzhou Zhao return nullptr; 1244cad17deSFlorian Mayer UNINITIALIZED BufferedStackTrace stack; 1251fb612d0SJianzhou Zhao ReportOutOfMemory(size, &stack); 1261fb612d0SJianzhou Zhao } 1271fb612d0SJianzhou Zhao Metadata *meta = 1281fb612d0SJianzhou Zhao reinterpret_cast<Metadata *>(allocator.GetMetaData(allocated)); 1291fb612d0SJianzhou Zhao meta->requested_size = size; 1301fb612d0SJianzhou Zhao if (zeroise) { 1311fb612d0SJianzhou Zhao internal_memset(allocated, 0, size); 1321fb612d0SJianzhou Zhao dfsan_set_label(0, allocated, size); 1331fb612d0SJianzhou Zhao } else if (flags().zero_in_malloc) { 1341fb612d0SJianzhou Zhao dfsan_set_label(0, allocated, size); 1351fb612d0SJianzhou Zhao } 1361fb612d0SJianzhou Zhao return allocated; 1371fb612d0SJianzhou Zhao } 1381fb612d0SJianzhou Zhao 139*80eea015SFangrui Song void __dfsan::dfsan_deallocate(void *p) { 1401fb612d0SJianzhou Zhao CHECK(p); 1411fb612d0SJianzhou Zhao Metadata *meta = reinterpret_cast<Metadata *>(allocator.GetMetaData(p)); 1421fb612d0SJianzhou Zhao uptr size = meta->requested_size; 1431fb612d0SJianzhou Zhao meta->requested_size = 0; 1441fb612d0SJianzhou Zhao if (flags().zero_in_free) 1451fb612d0SJianzhou Zhao dfsan_set_label(0, p, size); 1461fb612d0SJianzhou Zhao DFsanThread *t = GetCurrentThread(); 1471fb612d0SJianzhou Zhao if (t) { 1481fb612d0SJianzhou Zhao AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage()); 1491fb612d0SJianzhou Zhao allocator.Deallocate(cache, p); 1501fb612d0SJianzhou Zhao } else { 1511fb612d0SJianzhou Zhao SpinMutexLock l(&fallback_mutex); 1521fb612d0SJianzhou Zhao AllocatorCache *cache = &fallback_allocator_cache; 1531fb612d0SJianzhou Zhao allocator.Deallocate(cache, p); 1541fb612d0SJianzhou Zhao } 1551fb612d0SJianzhou Zhao } 1561fb612d0SJianzhou Zhao 157*80eea015SFangrui Song static void *DFsanReallocate(void *old_p, uptr new_size, uptr alignment) { 1581fb612d0SJianzhou Zhao Metadata *meta = reinterpret_cast<Metadata *>(allocator.GetMetaData(old_p)); 1591fb612d0SJianzhou Zhao uptr old_size = meta->requested_size; 1601fb612d0SJianzhou Zhao uptr actually_allocated_size = allocator.GetActuallyAllocatedSize(old_p); 1611fb612d0SJianzhou Zhao if (new_size <= actually_allocated_size) { 1621fb612d0SJianzhou Zhao // We are not reallocating here. 1631fb612d0SJianzhou Zhao meta->requested_size = new_size; 1641fb612d0SJianzhou Zhao if (new_size > old_size && flags().zero_in_malloc) 1651fb612d0SJianzhou Zhao dfsan_set_label(0, (char *)old_p + old_size, new_size - old_size); 1661fb612d0SJianzhou Zhao return old_p; 1671fb612d0SJianzhou Zhao } 1681fb612d0SJianzhou Zhao uptr memcpy_size = Min(new_size, old_size); 1691fb612d0SJianzhou Zhao void *new_p = DFsanAllocate(new_size, alignment, false /*zeroise*/); 1701fb612d0SJianzhou Zhao if (new_p) { 1711fb612d0SJianzhou Zhao dfsan_copy_memory(new_p, old_p, memcpy_size); 1721fb612d0SJianzhou Zhao dfsan_deallocate(old_p); 1731fb612d0SJianzhou Zhao } 1741fb612d0SJianzhou Zhao return new_p; 1751fb612d0SJianzhou Zhao } 1761fb612d0SJianzhou Zhao 177*80eea015SFangrui Song static void *DFsanCalloc(uptr nmemb, uptr size) { 1781fb612d0SJianzhou Zhao if (UNLIKELY(CheckForCallocOverflow(size, nmemb))) { 1791fb612d0SJianzhou Zhao if (AllocatorMayReturnNull()) 1801fb612d0SJianzhou Zhao return nullptr; 1814cad17deSFlorian Mayer UNINITIALIZED BufferedStackTrace stack; 1821fb612d0SJianzhou Zhao ReportCallocOverflow(nmemb, size, &stack); 1831fb612d0SJianzhou Zhao } 1841fb612d0SJianzhou Zhao return DFsanAllocate(nmemb * size, sizeof(u64), true /*zeroise*/); 1851fb612d0SJianzhou Zhao } 1861fb612d0SJianzhou Zhao 1878c63dc6fSFangrui Song static const void *AllocationBegin(const void *p) { 188415b1cfdSThurston Dang if (!p) 189415b1cfdSThurston Dang return nullptr; 190c81a3224SJie Fu void *beg = allocator.GetBlockBegin(p); 191415b1cfdSThurston Dang if (!beg) 192415b1cfdSThurston Dang return nullptr; 193415b1cfdSThurston Dang Metadata *b = (Metadata *)allocator.GetMetaData(beg); 194415b1cfdSThurston Dang if (!b) 195415b1cfdSThurston Dang return nullptr; 196415b1cfdSThurston Dang if (b->requested_size == 0) 197415b1cfdSThurston Dang return nullptr; 198d644ab02SThurston Dang return (const void *)beg; 199415b1cfdSThurston Dang } 200415b1cfdSThurston Dang 2011fb612d0SJianzhou Zhao static uptr AllocationSize(const void *p) { 2021fb612d0SJianzhou Zhao if (!p) 2031fb612d0SJianzhou Zhao return 0; 2041fb612d0SJianzhou Zhao const void *beg = allocator.GetBlockBegin(p); 2051fb612d0SJianzhou Zhao if (beg != p) 2061fb612d0SJianzhou Zhao return 0; 2071fb612d0SJianzhou Zhao Metadata *b = (Metadata *)allocator.GetMetaData(p); 2081fb612d0SJianzhou Zhao return b->requested_size; 2091fb612d0SJianzhou Zhao } 2101fb612d0SJianzhou Zhao 2117639265aSJin Xin Ng static uptr AllocationSizeFast(const void *p) { 2127639265aSJin Xin Ng return reinterpret_cast<Metadata *>(allocator.GetMetaData(p))->requested_size; 2137639265aSJin Xin Ng } 2147639265aSJin Xin Ng 215*80eea015SFangrui Song void *__dfsan::dfsan_malloc(uptr size) { 2161fb612d0SJianzhou Zhao return SetErrnoOnNull(DFsanAllocate(size, sizeof(u64), false /*zeroise*/)); 2171fb612d0SJianzhou Zhao } 2181fb612d0SJianzhou Zhao 219*80eea015SFangrui Song void *__dfsan::dfsan_calloc(uptr nmemb, uptr size) { 2201fb612d0SJianzhou Zhao return SetErrnoOnNull(DFsanCalloc(nmemb, size)); 2211fb612d0SJianzhou Zhao } 2221fb612d0SJianzhou Zhao 223*80eea015SFangrui Song void *__dfsan::dfsan_realloc(void *ptr, uptr size) { 2241fb612d0SJianzhou Zhao if (!ptr) 2251fb612d0SJianzhou Zhao return SetErrnoOnNull(DFsanAllocate(size, sizeof(u64), false /*zeroise*/)); 2261fb612d0SJianzhou Zhao if (size == 0) { 2271fb612d0SJianzhou Zhao dfsan_deallocate(ptr); 2281fb612d0SJianzhou Zhao return nullptr; 2291fb612d0SJianzhou Zhao } 2301fb612d0SJianzhou Zhao return SetErrnoOnNull(DFsanReallocate(ptr, size, sizeof(u64))); 2311fb612d0SJianzhou Zhao } 2321fb612d0SJianzhou Zhao 233*80eea015SFangrui Song void *__dfsan::dfsan_reallocarray(void *ptr, uptr nmemb, uptr size) { 2341fb612d0SJianzhou Zhao if (UNLIKELY(CheckForCallocOverflow(size, nmemb))) { 2351fb612d0SJianzhou Zhao errno = errno_ENOMEM; 2361fb612d0SJianzhou Zhao if (AllocatorMayReturnNull()) 2371fb612d0SJianzhou Zhao return nullptr; 2384cad17deSFlorian Mayer UNINITIALIZED BufferedStackTrace stack; 2391fb612d0SJianzhou Zhao ReportReallocArrayOverflow(nmemb, size, &stack); 2401fb612d0SJianzhou Zhao } 2411fb612d0SJianzhou Zhao return dfsan_realloc(ptr, nmemb * size); 2421fb612d0SJianzhou Zhao } 2431fb612d0SJianzhou Zhao 244*80eea015SFangrui Song void *__dfsan::dfsan_valloc(uptr size) { 2451fb612d0SJianzhou Zhao return SetErrnoOnNull( 2461fb612d0SJianzhou Zhao DFsanAllocate(size, GetPageSizeCached(), false /*zeroise*/)); 2471fb612d0SJianzhou Zhao } 2481fb612d0SJianzhou Zhao 249*80eea015SFangrui Song void *__dfsan::dfsan_pvalloc(uptr size) { 2501fb612d0SJianzhou Zhao uptr PageSize = GetPageSizeCached(); 2511fb612d0SJianzhou Zhao if (UNLIKELY(CheckForPvallocOverflow(size, PageSize))) { 2521fb612d0SJianzhou Zhao errno = errno_ENOMEM; 2531fb612d0SJianzhou Zhao if (AllocatorMayReturnNull()) 2541fb612d0SJianzhou Zhao return nullptr; 2554cad17deSFlorian Mayer UNINITIALIZED BufferedStackTrace stack; 2561fb612d0SJianzhou Zhao ReportPvallocOverflow(size, &stack); 2571fb612d0SJianzhou Zhao } 2581fb612d0SJianzhou Zhao // pvalloc(0) should allocate one page. 2591fb612d0SJianzhou Zhao size = size ? RoundUpTo(size, PageSize) : PageSize; 2601fb612d0SJianzhou Zhao return SetErrnoOnNull(DFsanAllocate(size, PageSize, false /*zeroise*/)); 2611fb612d0SJianzhou Zhao } 2621fb612d0SJianzhou Zhao 263*80eea015SFangrui Song void *__dfsan::dfsan_aligned_alloc(uptr alignment, uptr size) { 2641fb612d0SJianzhou Zhao if (UNLIKELY(!CheckAlignedAllocAlignmentAndSize(alignment, size))) { 2651fb612d0SJianzhou Zhao errno = errno_EINVAL; 2661fb612d0SJianzhou Zhao if (AllocatorMayReturnNull()) 2671fb612d0SJianzhou Zhao return nullptr; 2684cad17deSFlorian Mayer UNINITIALIZED BufferedStackTrace stack; 2691fb612d0SJianzhou Zhao ReportInvalidAlignedAllocAlignment(size, alignment, &stack); 2701fb612d0SJianzhou Zhao } 2711fb612d0SJianzhou Zhao return SetErrnoOnNull(DFsanAllocate(size, alignment, false /*zeroise*/)); 2721fb612d0SJianzhou Zhao } 2731fb612d0SJianzhou Zhao 274*80eea015SFangrui Song void *__dfsan::dfsan_memalign(uptr alignment, uptr size) { 2751fb612d0SJianzhou Zhao if (UNLIKELY(!IsPowerOfTwo(alignment))) { 2761fb612d0SJianzhou Zhao errno = errno_EINVAL; 2771fb612d0SJianzhou Zhao if (AllocatorMayReturnNull()) 2781fb612d0SJianzhou Zhao return nullptr; 2794cad17deSFlorian Mayer UNINITIALIZED BufferedStackTrace stack; 2801fb612d0SJianzhou Zhao ReportInvalidAllocationAlignment(alignment, &stack); 2811fb612d0SJianzhou Zhao } 2821fb612d0SJianzhou Zhao return SetErrnoOnNull(DFsanAllocate(size, alignment, false /*zeroise*/)); 2831fb612d0SJianzhou Zhao } 2841fb612d0SJianzhou Zhao 285*80eea015SFangrui Song int __dfsan::dfsan_posix_memalign(void **memptr, uptr alignment, uptr size) { 2861fb612d0SJianzhou Zhao if (UNLIKELY(!CheckPosixMemalignAlignment(alignment))) { 2871fb612d0SJianzhou Zhao if (AllocatorMayReturnNull()) 2881fb612d0SJianzhou Zhao return errno_EINVAL; 2894cad17deSFlorian Mayer UNINITIALIZED BufferedStackTrace stack; 2901fb612d0SJianzhou Zhao ReportInvalidPosixMemalignAlignment(alignment, &stack); 2911fb612d0SJianzhou Zhao } 2921fb612d0SJianzhou Zhao void *ptr = DFsanAllocate(size, alignment, false /*zeroise*/); 2931fb612d0SJianzhou Zhao if (UNLIKELY(!ptr)) 2941fb612d0SJianzhou Zhao // OOM error is already taken care of by DFsanAllocate. 2951fb612d0SJianzhou Zhao return errno_ENOMEM; 2961fb612d0SJianzhou Zhao CHECK(IsAligned((uptr)ptr, alignment)); 2971fb612d0SJianzhou Zhao *memptr = ptr; 2981fb612d0SJianzhou Zhao return 0; 2991fb612d0SJianzhou Zhao } 3001fb612d0SJianzhou Zhao 301*80eea015SFangrui Song extern "C" { 3021fb612d0SJianzhou Zhao uptr __sanitizer_get_current_allocated_bytes() { 3031fb612d0SJianzhou Zhao uptr stats[AllocatorStatCount]; 3041fb612d0SJianzhou Zhao allocator.GetStats(stats); 3051fb612d0SJianzhou Zhao return stats[AllocatorStatAllocated]; 3061fb612d0SJianzhou Zhao } 3071fb612d0SJianzhou Zhao 3081fb612d0SJianzhou Zhao uptr __sanitizer_get_heap_size() { 3091fb612d0SJianzhou Zhao uptr stats[AllocatorStatCount]; 3101fb612d0SJianzhou Zhao allocator.GetStats(stats); 3111fb612d0SJianzhou Zhao return stats[AllocatorStatMapped]; 3121fb612d0SJianzhou Zhao } 3131fb612d0SJianzhou Zhao 3141fb612d0SJianzhou Zhao uptr __sanitizer_get_free_bytes() { return 1; } 3151fb612d0SJianzhou Zhao 3161fb612d0SJianzhou Zhao uptr __sanitizer_get_unmapped_bytes() { return 1; } 3171fb612d0SJianzhou Zhao 3181fb612d0SJianzhou Zhao uptr __sanitizer_get_estimated_allocated_size(uptr size) { return size; } 3191fb612d0SJianzhou Zhao 3201fb612d0SJianzhou Zhao int __sanitizer_get_ownership(const void *p) { return AllocationSize(p) != 0; } 3211fb612d0SJianzhou Zhao 322d644ab02SThurston Dang const void *__sanitizer_get_allocated_begin(const void *p) { 323415b1cfdSThurston Dang return AllocationBegin(p); 324415b1cfdSThurston Dang } 325415b1cfdSThurston Dang 3261fb612d0SJianzhou Zhao uptr __sanitizer_get_allocated_size(const void *p) { return AllocationSize(p); } 3277639265aSJin Xin Ng 3287639265aSJin Xin Ng uptr __sanitizer_get_allocated_size_fast(const void *p) { 3297639265aSJin Xin Ng DCHECK_EQ(p, __sanitizer_get_allocated_begin(p)); 3307639265aSJin Xin Ng uptr ret = AllocationSizeFast(p); 3317639265aSJin Xin Ng DCHECK_EQ(ret, __sanitizer_get_allocated_size(p)); 3327639265aSJin Xin Ng return ret; 3337639265aSJin Xin Ng } 334*80eea015SFangrui Song } 335