merge from dev

This commit is contained in:
daan 2020-09-14 09:03:52 -07:00
commit d89c23efce
2 changed files with 20 additions and 7 deletions

View file

@ -301,8 +301,12 @@ static void* mi_region_try_alloc(size_t blocks, bool* commit, bool* large, bool*
_mi_bitmap_claim(&region->commit, 1, blocks, bit_idx, &any_uncommitted); _mi_bitmap_claim(&region->commit, 1, blocks, bit_idx, &any_uncommitted);
if (any_uncommitted) { if (any_uncommitted) {
mi_assert_internal(!info.x.is_large && !info.x.is_pinned); mi_assert_internal(!info.x.is_large && !info.x.is_pinned);
bool commit_zero; bool commit_zero = false;
_mi_mem_commit(p, blocks * MI_SEGMENT_SIZE, &commit_zero, tld); if (!_mi_mem_commit(p, blocks * MI_SEGMENT_SIZE, &commit_zero, tld)) {
// failed to commit! unclaim and return
mi_bitmap_unclaim(&region->in_use, 1, blocks, bit_idx);
return NULL;
}
if (commit_zero) *is_zero = true; if (commit_zero) *is_zero = true;
} }
} }

View file

@ -207,11 +207,17 @@ static void mi_segment_protect(mi_segment_t* segment, bool protect, mi_os_tld_t*
mi_assert_internal(MI_SECURE <= 1 || segment->page_kind >= MI_PAGE_LARGE); mi_assert_internal(MI_SECURE <= 1 || segment->page_kind >= MI_PAGE_LARGE);
uint8_t* start = (uint8_t*)segment + segment->segment_size - os_psize; uint8_t* start = (uint8_t*)segment + segment->segment_size - os_psize;
if (protect && !segment->mem_is_committed) { if (protect && !segment->mem_is_committed) {
if (protect) {
// ensure secure page is committed // ensure secure page is committed
_mi_mem_commit(start, os_psize, NULL, tld); if (_mi_mem_commit(start, os_psize, NULL, tld)) { // if this fails that is ok (as it is an unaccessible page)
}
mi_segment_protect_range(start, os_psize, protect); mi_segment_protect_range(start, os_psize, protect);
} }
}
}
else {
mi_segment_protect_range(start, os_psize, protect);
}
}
else { else {
// or protect every page // or protect every page
const size_t page_size = mi_segment_page_size(segment); const size_t page_size = mi_segment_page_size(segment);
@ -606,8 +612,11 @@ static mi_segment_t* mi_segment_init(mi_segment_t* segment, size_t required, mi_
// ensure the initial info is committed // ensure the initial info is committed
if (segment->capacity < capacity) { if (segment->capacity < capacity) {
bool commit_zero = false; bool commit_zero = false;
_mi_mem_commit(segment, pre_size, &commit_zero, tld->os); bool ok = _mi_mem_commit(segment, pre_size, &commit_zero, tld->os);
if (commit_zero) is_zero = true; if (commit_zero) is_zero = true;
if (!ok) {
return NULL;
}
} }
} }
} }