mirror of
https://github.com/microsoft/mimalloc.git
synced 2024-12-27 13:33:18 +08:00
fix mem tracking for asan
This commit is contained in:
parent
d4fe700089
commit
c9dd6f6dc9
13
src/os.c
13
src/os.c
@ -204,8 +204,8 @@ static void* mi_os_prim_alloc(size_t size, size_t try_alignment, bool commit, bo
|
|||||||
mi_assert_internal(is_zero != NULL);
|
mi_assert_internal(is_zero != NULL);
|
||||||
mi_assert_internal(is_large != NULL);
|
mi_assert_internal(is_large != NULL);
|
||||||
if (size == 0) return NULL;
|
if (size == 0) return NULL;
|
||||||
if (!commit) allow_large = false;
|
if (!commit) { allow_large = false; }
|
||||||
if (try_alignment == 0) try_alignment = 1; // avoid 0 to ensure there will be no divide by zero when aligning
|
if (try_alignment == 0) { try_alignment = 1; } // avoid 0 to ensure there will be no divide by zero when aligning
|
||||||
|
|
||||||
*is_zero = false;
|
*is_zero = false;
|
||||||
void* p = NULL;
|
void* p = NULL;
|
||||||
@ -216,7 +216,10 @@ static void* mi_os_prim_alloc(size_t size, size_t try_alignment, bool commit, bo
|
|||||||
mi_stat_counter_increase(stats->mmap_calls, 1);
|
mi_stat_counter_increase(stats->mmap_calls, 1);
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
_mi_stat_increase(&stats->reserved, size);
|
_mi_stat_increase(&stats->reserved, size);
|
||||||
if (commit) { _mi_stat_increase(&stats->committed, size); }
|
if (commit) {
|
||||||
|
_mi_stat_increase(&stats->committed, size);
|
||||||
|
mi_track_mem_defined(p,size); // seems needed for asan (or `mimalloc-test-api` fails)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -276,8 +279,8 @@ static void* mi_os_prim_alloc_aligned(size_t size, size_t alignment, bool commit
|
|||||||
size_t mid_size = _mi_align_up(size, _mi_os_page_size());
|
size_t mid_size = _mi_align_up(size, _mi_os_page_size());
|
||||||
size_t post_size = over_size - pre_size - mid_size;
|
size_t post_size = over_size - pre_size - mid_size;
|
||||||
mi_assert_internal(pre_size < over_size&& post_size < over_size&& mid_size >= size);
|
mi_assert_internal(pre_size < over_size&& post_size < over_size&& mid_size >= size);
|
||||||
if (pre_size > 0) mi_os_prim_free(p, pre_size, commit, stats);
|
if (pre_size > 0) { mi_os_prim_free(p, pre_size, commit, stats); }
|
||||||
if (post_size > 0) mi_os_prim_free((uint8_t*)aligned_p + mid_size, post_size, commit, stats);
|
if (post_size > 0) { mi_os_prim_free((uint8_t*)aligned_p + mid_size, post_size, commit, stats); }
|
||||||
// we can return the aligned pointer on `mmap` (and sbrk) systems
|
// we can return the aligned pointer on `mmap` (and sbrk) systems
|
||||||
p = aligned_p;
|
p = aligned_p;
|
||||||
*base = aligned_p; // since we freed the pre part, `*base == p`.
|
*base = aligned_p; // since we freed the pre part, `*base == p`.
|
||||||
|
@ -539,7 +539,7 @@ static mi_segment_t* mi_segment_os_alloc(bool eager_delayed, size_t page_alignme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mi_track_mem_undefined(segment, info_size); MI_UNUSED(info_size);
|
MI_UNUSED(info_size);
|
||||||
segment->memid = memid;
|
segment->memid = memid;
|
||||||
segment->allow_decommit = !memid.is_pinned;
|
segment->allow_decommit = !memid.is_pinned;
|
||||||
segment->allow_purge = segment->allow_decommit && (mi_option_get(mi_option_purge_delay) >= 0);
|
segment->allow_purge = segment->allow_decommit && (mi_option_get(mi_option_purge_delay) >= 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user