22
22
#include " sanitizer_common/sanitizer_allocator_report.h"
23
23
#include " sanitizer_common/sanitizer_errno.h"
24
24
25
- namespace __dfsan {
25
+ using namespace __dfsan ;
26
+
27
+ namespace {
26
28
27
29
struct Metadata {
28
30
uptr requested_size;
@@ -67,8 +69,9 @@ static AllocatorCache fallback_allocator_cache;
67
69
static StaticSpinMutex fallback_mutex;
68
70
69
71
static uptr max_malloc_size;
72
+ } // namespace
70
73
71
- void dfsan_allocator_init () {
74
+ void __dfsan:: dfsan_allocator_init () {
72
75
SetAllocatorMayReturnNull (common_flags ()->allocator_may_return_null );
73
76
allocator.Init (common_flags ()->allocator_release_to_os_interval_ms );
74
77
if (common_flags ()->max_allocation_size_mb )
@@ -78,7 +81,7 @@ void dfsan_allocator_init() {
78
81
max_malloc_size = kMaxAllowedMallocSize ;
79
82
}
80
83
81
- AllocatorCache *GetAllocatorCache (DFsanThreadLocalMallocStorage *ms) {
84
+ static AllocatorCache *GetAllocatorCache (DFsanThreadLocalMallocStorage *ms) {
82
85
CHECK (ms);
83
86
CHECK_LE (sizeof (AllocatorCache), sizeof (ms->allocator_cache ));
84
87
return reinterpret_cast <AllocatorCache *>(ms->allocator_cache );
@@ -133,7 +136,7 @@ static void *DFsanAllocate(uptr size, uptr alignment, bool zeroise) {
133
136
return allocated;
134
137
}
135
138
136
- void dfsan_deallocate (void *p) {
139
+ void __dfsan:: dfsan_deallocate (void *p) {
137
140
CHECK (p);
138
141
Metadata *meta = reinterpret_cast <Metadata *>(allocator.GetMetaData (p));
139
142
uptr size = meta->requested_size ;
@@ -151,7 +154,7 @@ void dfsan_deallocate(void *p) {
151
154
}
152
155
}
153
156
154
- void *DFsanReallocate (void *old_p, uptr new_size, uptr alignment) {
157
+ static void *DFsanReallocate (void *old_p, uptr new_size, uptr alignment) {
155
158
Metadata *meta = reinterpret_cast <Metadata *>(allocator.GetMetaData (old_p));
156
159
uptr old_size = meta->requested_size ;
157
160
uptr actually_allocated_size = allocator.GetActuallyAllocatedSize (old_p);
@@ -171,7 +174,7 @@ void *DFsanReallocate(void *old_p, uptr new_size, uptr alignment) {
171
174
return new_p;
172
175
}
173
176
174
- void *DFsanCalloc (uptr nmemb, uptr size) {
177
+ static void *DFsanCalloc (uptr nmemb, uptr size) {
175
178
if (UNLIKELY (CheckForCallocOverflow (size, nmemb))) {
176
179
if (AllocatorMayReturnNull ())
177
180
return nullptr ;
@@ -209,15 +212,15 @@ static uptr AllocationSizeFast(const void *p) {
209
212
return reinterpret_cast <Metadata *>(allocator.GetMetaData (p))->requested_size ;
210
213
}
211
214
212
- void *dfsan_malloc (uptr size) {
215
+ void *__dfsan:: dfsan_malloc (uptr size) {
213
216
return SetErrnoOnNull (DFsanAllocate (size, sizeof (u64), false /* zeroise*/ ));
214
217
}
215
218
216
- void *dfsan_calloc (uptr nmemb, uptr size) {
219
+ void *__dfsan:: dfsan_calloc (uptr nmemb, uptr size) {
217
220
return SetErrnoOnNull (DFsanCalloc (nmemb, size));
218
221
}
219
222
220
- void *dfsan_realloc (void *ptr, uptr size) {
223
+ void *__dfsan:: dfsan_realloc (void *ptr, uptr size) {
221
224
if (!ptr)
222
225
return SetErrnoOnNull (DFsanAllocate (size, sizeof (u64), false /* zeroise*/ ));
223
226
if (size == 0 ) {
@@ -227,7 +230,7 @@ void *dfsan_realloc(void *ptr, uptr size) {
227
230
return SetErrnoOnNull (DFsanReallocate (ptr, size, sizeof (u64)));
228
231
}
229
232
230
- void *dfsan_reallocarray (void *ptr, uptr nmemb, uptr size) {
233
+ void *__dfsan:: dfsan_reallocarray (void *ptr, uptr nmemb, uptr size) {
231
234
if (UNLIKELY (CheckForCallocOverflow (size, nmemb))) {
232
235
errno = errno_ENOMEM;
233
236
if (AllocatorMayReturnNull ())
@@ -238,12 +241,12 @@ void *dfsan_reallocarray(void *ptr, uptr nmemb, uptr size) {
238
241
return dfsan_realloc (ptr, nmemb * size);
239
242
}
240
243
241
- void *dfsan_valloc (uptr size) {
244
+ void *__dfsan:: dfsan_valloc (uptr size) {
242
245
return SetErrnoOnNull (
243
246
DFsanAllocate (size, GetPageSizeCached (), false /* zeroise*/ ));
244
247
}
245
248
246
- void *dfsan_pvalloc (uptr size) {
249
+ void *__dfsan:: dfsan_pvalloc (uptr size) {
247
250
uptr PageSize = GetPageSizeCached ();
248
251
if (UNLIKELY (CheckForPvallocOverflow (size, PageSize))) {
249
252
errno = errno_ENOMEM;
@@ -257,7 +260,7 @@ void *dfsan_pvalloc(uptr size) {
257
260
return SetErrnoOnNull (DFsanAllocate (size, PageSize, false /* zeroise*/ ));
258
261
}
259
262
260
- void *dfsan_aligned_alloc (uptr alignment, uptr size) {
263
+ void *__dfsan:: dfsan_aligned_alloc (uptr alignment, uptr size) {
261
264
if (UNLIKELY (!CheckAlignedAllocAlignmentAndSize (alignment, size))) {
262
265
errno = errno_EINVAL;
263
266
if (AllocatorMayReturnNull ())
@@ -268,7 +271,7 @@ void *dfsan_aligned_alloc(uptr alignment, uptr size) {
268
271
return SetErrnoOnNull (DFsanAllocate (size, alignment, false /* zeroise*/ ));
269
272
}
270
273
271
- void *dfsan_memalign (uptr alignment, uptr size) {
274
+ void *__dfsan:: dfsan_memalign (uptr alignment, uptr size) {
272
275
if (UNLIKELY (!IsPowerOfTwo (alignment))) {
273
276
errno = errno_EINVAL;
274
277
if (AllocatorMayReturnNull ())
@@ -279,7 +282,7 @@ void *dfsan_memalign(uptr alignment, uptr size) {
279
282
return SetErrnoOnNull (DFsanAllocate (size, alignment, false /* zeroise*/ ));
280
283
}
281
284
282
- int dfsan_posix_memalign (void **memptr, uptr alignment, uptr size) {
285
+ int __dfsan:: dfsan_posix_memalign (void **memptr, uptr alignment, uptr size) {
283
286
if (UNLIKELY (!CheckPosixMemalignAlignment (alignment))) {
284
287
if (AllocatorMayReturnNull ())
285
288
return errno_EINVAL;
@@ -295,10 +298,7 @@ int dfsan_posix_memalign(void **memptr, uptr alignment, uptr size) {
295
298
return 0 ;
296
299
}
297
300
298
- } // namespace __dfsan
299
-
300
- using namespace __dfsan ;
301
-
301
+ extern " C" {
302
302
uptr __sanitizer_get_current_allocated_bytes () {
303
303
uptr stats[AllocatorStatCount];
304
304
allocator.GetStats (stats);
@@ -331,3 +331,4 @@ uptr __sanitizer_get_allocated_size_fast(const void *p) {
331
331
DCHECK_EQ (ret, __sanitizer_get_allocated_size (p));
332
332
return ret;
333
333
}
334
+ }
0 commit comments