16
16
17
17
#include " asan_allocator.h"
18
18
19
+ #include " asan_internal.h"
19
20
#include " asan_mapping.h"
20
21
#include " asan_poisoning.h"
21
22
#include " asan_report.h"
24
25
#include " lsan/lsan_common.h"
25
26
#include " sanitizer_common/sanitizer_allocator_checks.h"
26
27
#include " sanitizer_common/sanitizer_allocator_interface.h"
28
+ #include " sanitizer_common/sanitizer_common.h"
27
29
#include " sanitizer_common/sanitizer_errno.h"
28
30
#include " sanitizer_common/sanitizer_flags.h"
29
31
#include " sanitizer_common/sanitizer_internal_defs.h"
@@ -196,6 +198,24 @@ struct QuarantineCallback {
196
198
stack_ (stack) {
197
199
}
198
200
201
+ void PreQuarantine (AsanChunk *m) {
202
+ Flags &fl = *flags ();
203
+
204
+ if (fl.max_free_fill_size > 0 ) {
205
+ // We have to skip the chunk header, it contains free_context_id.
206
+ uptr scribble_start = (uptr)m + kChunkHeaderSize + kChunkHeader2Size ;
207
+ if (m->UsedSize () >= kChunkHeader2Size ) { // Skip Header2 in user area.
208
+ uptr size_to_fill = m->UsedSize () - kChunkHeader2Size ;
209
+ size_to_fill = Min (size_to_fill, (uptr)fl.max_free_fill_size );
210
+ REAL (memset)((void *)scribble_start, fl.free_fill_byte , size_to_fill);
211
+ }
212
+ }
213
+
214
+ // Poison the region.
215
+ PoisonShadow (m->Beg (), RoundUpTo (m->UsedSize (), ASAN_SHADOW_GRANULARITY),
216
+ kAsanHeapFreeMagic );
217
+ }
218
+
199
219
void Recycle (AsanChunk *m) {
200
220
void *p = get_allocator ().GetBlockBegin (m);
201
221
if (p != m) {
@@ -221,6 +241,12 @@ struct QuarantineCallback {
221
241
get_allocator ().Deallocate (cache_, p);
222
242
}
223
243
244
+ void RecyclePassThrough (AsanChunk *m) {
245
+ // TODO: We don't need all these here.
246
+ PreQuarantine (m);
247
+ Recycle (m);
248
+ }
249
+
224
250
void *Allocate (uptr size) {
225
251
void *res = get_allocator ().Allocate (cache_, size, 1 );
226
252
// TODO(alekseys): Consider making quarantine OOM-friendly.
@@ -639,21 +665,6 @@ struct Allocator {
639
665
AsanThread *t = GetCurrentThread ();
640
666
m->SetFreeContext (t ? t->tid () : 0 , StackDepotPut (*stack));
641
667
642
- Flags &fl = *flags ();
643
- if (fl.max_free_fill_size > 0 ) {
644
- // We have to skip the chunk header, it contains free_context_id.
645
- uptr scribble_start = (uptr)m + kChunkHeaderSize + kChunkHeader2Size ;
646
- if (m->UsedSize () >= kChunkHeader2Size ) { // Skip Header2 in user area.
647
- uptr size_to_fill = m->UsedSize () - kChunkHeader2Size ;
648
- size_to_fill = Min (size_to_fill, (uptr)fl.max_free_fill_size );
649
- REAL (memset)((void *)scribble_start, fl.free_fill_byte , size_to_fill);
650
- }
651
- }
652
-
653
- // Poison the region.
654
- PoisonShadow (m->Beg (), RoundUpTo (m->UsedSize (), ASAN_SHADOW_GRANULARITY),
655
- kAsanHeapFreeMagic );
656
-
657
668
// Push into quarantine.
658
669
if (t) {
659
670
AsanThreadLocalMallocStorage *ms = &t->malloc_storage ();
0 commit comments