mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-04 22:49:32 +03:00
improve handling of out-of-memory situations
This commit is contained in:
parent
ff7b6c54bd
commit
840eba2874
2 changed files with 13 additions and 11 deletions
|
@ -298,12 +298,12 @@ static void* mi_region_try_alloc(size_t blocks, bool* commit, bool* is_large, bo
|
||||||
if (any_uncommitted) {
|
if (any_uncommitted) {
|
||||||
mi_assert_internal(!info.x.is_large);
|
mi_assert_internal(!info.x.is_large);
|
||||||
bool commit_zero = false;
|
bool commit_zero = false;
|
||||||
bool ok = _mi_mem_commit(p, blocks * MI_SEGMENT_SIZE, &commit_zero, tld);
|
if (!_mi_mem_commit(p, blocks * MI_SEGMENT_SIZE, &commit_zero, tld)) {
|
||||||
if (commit_zero) *is_zero = true;
|
// failed to commit! unclaim and return
|
||||||
if (!ok)
|
mi_bitmap_unclaim(®ion->in_use, 1, blocks, bit_idx);
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if (commit_zero) *is_zero = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -207,14 +207,16 @@ 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) {
|
||||||
// ensure secure page is committed
|
if (protect) {
|
||||||
#if (MI_DEBUG>1)
|
// ensure secure page is committed
|
||||||
bool ok =
|
if (_mi_mem_commit(start, os_psize, NULL, tld)) { // if this fails that is ok (as it is an unaccessible page)
|
||||||
#endif
|
mi_segment_protect_range(start, os_psize, protect);
|
||||||
_mi_mem_commit(start, os_psize, NULL, tld);
|
}
|
||||||
mi_assert_internal(ok);
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mi_segment_protect_range(start, os_psize, protect);
|
||||||
}
|
}
|
||||||
mi_segment_protect_range(start, os_psize, protect);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// or protect every page
|
// or protect every page
|
||||||
|
|
Loading…
Add table
Reference in a new issue