2222#include " sanitizer_common/sanitizer_allocator_report.h"
2323#include " sanitizer_common/sanitizer_errno.h"
2424
25- namespace __dfsan {
25+ using namespace __dfsan ;
26+
27+ namespace {
2628
2729struct Metadata {
2830 uptr requested_size;
@@ -67,8 +69,9 @@ static AllocatorCache fallback_allocator_cache;
6769static StaticSpinMutex fallback_mutex;
6870
6971static uptr max_malloc_size;
72+ } // namespace
7073
71- void dfsan_allocator_init () {
74+ void __dfsan:: dfsan_allocator_init () {
7275 SetAllocatorMayReturnNull (common_flags ()->allocator_may_return_null );
7376 allocator.Init (common_flags ()->allocator_release_to_os_interval_ms );
7477 if (common_flags ()->max_allocation_size_mb )
@@ -78,7 +81,7 @@ void dfsan_allocator_init() {
7881 max_malloc_size = kMaxAllowedMallocSize ;
7982}
8083
81- AllocatorCache *GetAllocatorCache (DFsanThreadLocalMallocStorage *ms) {
84+ static AllocatorCache *GetAllocatorCache (DFsanThreadLocalMallocStorage *ms) {
8285 CHECK (ms);
8386 CHECK_LE (sizeof (AllocatorCache), sizeof (ms->allocator_cache ));
8487 return reinterpret_cast <AllocatorCache *>(ms->allocator_cache );
@@ -133,7 +136,7 @@ static void *DFsanAllocate(uptr size, uptr alignment, bool zeroise) {
133136 return allocated;
134137}
135138
136- void dfsan_deallocate (void *p) {
139+ void __dfsan:: dfsan_deallocate (void *p) {
137140 CHECK (p);
138141 Metadata *meta = reinterpret_cast <Metadata *>(allocator.GetMetaData (p));
139142 uptr size = meta->requested_size ;
@@ -151,7 +154,7 @@ void dfsan_deallocate(void *p) {
151154 }
152155}
153156
154- void *DFsanReallocate (void *old_p, uptr new_size, uptr alignment) {
157+ static void *DFsanReallocate (void *old_p, uptr new_size, uptr alignment) {
155158 Metadata *meta = reinterpret_cast <Metadata *>(allocator.GetMetaData (old_p));
156159 uptr old_size = meta->requested_size ;
157160 uptr actually_allocated_size = allocator.GetActuallyAllocatedSize (old_p);
@@ -171,7 +174,7 @@ void *DFsanReallocate(void *old_p, uptr new_size, uptr alignment) {
171174 return new_p;
172175}
173176
174- void *DFsanCalloc (uptr nmemb, uptr size) {
177+ static void *DFsanCalloc (uptr nmemb, uptr size) {
175178 if (UNLIKELY (CheckForCallocOverflow (size, nmemb))) {
176179 if (AllocatorMayReturnNull ())
177180 return nullptr ;
@@ -209,15 +212,15 @@ static uptr AllocationSizeFast(const void *p) {
209212 return reinterpret_cast <Metadata *>(allocator.GetMetaData (p))->requested_size ;
210213}
211214
212- void *dfsan_malloc (uptr size) {
215+ void *__dfsan:: dfsan_malloc (uptr size) {
213216 return SetErrnoOnNull (DFsanAllocate (size, sizeof (u64 ), false /* zeroise*/ ));
214217}
215218
216- void *dfsan_calloc (uptr nmemb, uptr size) {
219+ void *__dfsan:: dfsan_calloc (uptr nmemb, uptr size) {
217220 return SetErrnoOnNull (DFsanCalloc (nmemb, size));
218221}
219222
220- void *dfsan_realloc (void *ptr, uptr size) {
223+ void *__dfsan:: dfsan_realloc (void *ptr, uptr size) {
221224 if (!ptr)
222225 return SetErrnoOnNull (DFsanAllocate (size, sizeof (u64 ), false /* zeroise*/ ));
223226 if (size == 0 ) {
@@ -227,7 +230,7 @@ void *dfsan_realloc(void *ptr, uptr size) {
227230 return SetErrnoOnNull (DFsanReallocate (ptr, size, sizeof (u64 )));
228231}
229232
230- void *dfsan_reallocarray (void *ptr, uptr nmemb, uptr size) {
233+ void *__dfsan:: dfsan_reallocarray (void *ptr, uptr nmemb, uptr size) {
231234 if (UNLIKELY (CheckForCallocOverflow (size, nmemb))) {
232235 errno = errno_ENOMEM;
233236 if (AllocatorMayReturnNull ())
@@ -238,12 +241,12 @@ void *dfsan_reallocarray(void *ptr, uptr nmemb, uptr size) {
238241 return dfsan_realloc (ptr, nmemb * size);
239242}
240243
241- void *dfsan_valloc (uptr size) {
244+ void *__dfsan:: dfsan_valloc (uptr size) {
242245 return SetErrnoOnNull (
243246 DFsanAllocate (size, GetPageSizeCached (), false /* zeroise*/ ));
244247}
245248
246- void *dfsan_pvalloc (uptr size) {
249+ void *__dfsan:: dfsan_pvalloc (uptr size) {
247250 uptr PageSize = GetPageSizeCached ();
248251 if (UNLIKELY (CheckForPvallocOverflow (size, PageSize))) {
249252 errno = errno_ENOMEM;
@@ -257,7 +260,7 @@ void *dfsan_pvalloc(uptr size) {
257260 return SetErrnoOnNull (DFsanAllocate (size, PageSize, false /* zeroise*/ ));
258261}
259262
260- void *dfsan_aligned_alloc (uptr alignment, uptr size) {
263+ void *__dfsan:: dfsan_aligned_alloc (uptr alignment, uptr size) {
261264 if (UNLIKELY (!CheckAlignedAllocAlignmentAndSize (alignment, size))) {
262265 errno = errno_EINVAL;
263266 if (AllocatorMayReturnNull ())
@@ -268,7 +271,7 @@ void *dfsan_aligned_alloc(uptr alignment, uptr size) {
268271 return SetErrnoOnNull (DFsanAllocate (size, alignment, false /* zeroise*/ ));
269272}
270273
271- void *dfsan_memalign (uptr alignment, uptr size) {
274+ void *__dfsan:: dfsan_memalign (uptr alignment, uptr size) {
272275 if (UNLIKELY (!IsPowerOfTwo (alignment))) {
273276 errno = errno_EINVAL;
274277 if (AllocatorMayReturnNull ())
@@ -279,7 +282,7 @@ void *dfsan_memalign(uptr alignment, uptr size) {
279282 return SetErrnoOnNull (DFsanAllocate (size, alignment, false /* zeroise*/ ));
280283}
281284
282- int dfsan_posix_memalign (void **memptr, uptr alignment, uptr size) {
285+ int __dfsan:: dfsan_posix_memalign (void **memptr, uptr alignment, uptr size) {
283286 if (UNLIKELY (!CheckPosixMemalignAlignment (alignment))) {
284287 if (AllocatorMayReturnNull ())
285288 return errno_EINVAL;
@@ -295,10 +298,7 @@ int dfsan_posix_memalign(void **memptr, uptr alignment, uptr size) {
295298 return 0 ;
296299}
297300
298- } // namespace __dfsan
299-
300- using namespace __dfsan ;
301-
301+ extern " C" {
302302uptr __sanitizer_get_current_allocated_bytes () {
303303 uptr stats[AllocatorStatCount];
304304 allocator.GetStats (stats);
@@ -331,3 +331,4 @@ uptr __sanitizer_get_allocated_size_fast(const void *p) {
331331 DCHECK_EQ (ret, __sanitizer_get_allocated_size (p));
332332 return ret;
333333}
334+ }
0 commit comments