fix unprotect of guard pages

This commit is contained in:
daan 2020-05-02 10:51:10 -07:00
parent 37b43e4cea
commit b8846f7a27
3 changed files with 8 additions and 3 deletions

View File

@ -33,7 +33,7 @@ terms of the MIT license. A copy of the license can be found in the file
// #define MI_SECURE 4 // checks for double free. (may be more expensive)
#if !defined(MI_SECURE)
#define MI_SECURE 0
#define MI_SECURE 4
#endif
// Define MI_DEBUG for debug mode

View File

@ -210,7 +210,7 @@ static void mi_cache_purge(mi_os_tld_t* tld) {
if (slot->expire != 0 && now >= slot->expire) { // safe read
// still expired, decommit it
slot->expire = 0;
mi_assert_internal(slot->is_committed && !slot->is_large);
mi_assert_internal(slot->is_committed && mi_bitmap_is_claimed(cache_available_large, MI_CACHE_FIELDS, 1, bitidx));
_mi_abandoned_await_readers(); // wait until safe to decommit
_mi_os_decommit(slot->p, MI_SEGMENT_SIZE, tld->stats);
slot->is_committed = false;

View File

@ -273,7 +273,12 @@ static void mi_segment_os_free(mi_segment_t* segment, mi_segments_tld_t* tld) {
mi_segment_map_freed_at(segment);
mi_segments_track_size(-((long)mi_segment_size(segment)),tld);
if (MI_SECURE>0) {
_mi_os_unprotect(segment, mi_segment_size(segment)); // ensure no more guard pages are set
// _mi_os_unprotect(segment, mi_segment_size(segment)); // ensure no more guard pages are set
// unprotect the guard pages; we cannot just unprotect the whole segment size as part may be decommitted
size_t os_page_size = _mi_os_page_size();
_mi_os_unprotect((uint8_t*)segment + mi_segment_info_size(segment) - os_page_size, os_page_size);
uint8_t* end = (uint8_t*)segment + mi_segment_size(segment) - os_page_size;
_mi_os_unprotect(end, os_page_size);
}
// purge delayed decommits now? (no, leave it to the cache)