fix valid pointer detection on mac

This commit is contained in:
Daan Leijen 2020-09-14 10:42:47 -07:00 committed by daan
parent fba65c440c
commit b1cc3d550c

View file

@ -217,9 +217,15 @@ static _Atomic(uintptr_t)mi_segment_map[MI_SEGMENT_MAP_WSIZE]; // 2KiB per TB w
static size_t mi_segment_map_index_of(const mi_segment_t* segment, size_t* bitidx) { static size_t mi_segment_map_index_of(const mi_segment_t* segment, size_t* bitidx) {
mi_assert_internal(_mi_ptr_segment(segment) == segment); // is it aligned on MI_SEGMENT_SIZE? mi_assert_internal(_mi_ptr_segment(segment) == segment); // is it aligned on MI_SEGMENT_SIZE?
uintptr_t segindex = ((uintptr_t)segment % MI_MAX_ADDRESS) / MI_SEGMENT_SIZE; if ((uintptr_t)segment >= MI_MAX_ADDRESS) {
*bitidx = segindex % (8*MI_INTPTR_SIZE); *bitidx = 0;
return (segindex / (8*MI_INTPTR_SIZE)); return 0;
}
else {
uintptr_t segindex = ((uintptr_t)segment) / MI_SEGMENT_SIZE;
*bitidx = segindex % MI_INTPTR_BITS;
return (segindex / MI_INTPTR_BITS);
}
} }
void _mi_segment_map_allocated_at(const mi_segment_t* segment) { void _mi_segment_map_allocated_at(const mi_segment_t* segment) {
@ -257,6 +263,9 @@ static mi_segment_t* _mi_segment_of(const void* p) {
return segment; // yes, allocated by us return segment; // yes, allocated by us
} }
if (index==0) return NULL; if (index==0) return NULL;
// TODO: maintain max/min allocated range for efficiency for more efficient rejection of invalid pointers?
// search downwards for the first segment in case it is an interior pointer // search downwards for the first segment in case it is an interior pointer
// could be slow but searches in MI_INTPTR_SIZE * MI_SEGMENT_SIZE (512MiB) steps trough // could be slow but searches in MI_INTPTR_SIZE * MI_SEGMENT_SIZE (512MiB) steps trough
// valid huge objects // valid huge objects