Loading...
src/purgeable_malloc.c libmalloc-283.40.1 libmalloc-657.60.21
--- libmalloc/libmalloc-283.40.1/src/purgeable_malloc.c
+++ libmalloc/libmalloc-657.60.21/src/purgeable_malloc.c
@@ -80,7 +80,7 @@
 	entry = large_entry_for_pointer_no_lock(szone, ptr);
 	SZONE_UNLOCK(szone);
 	if (entry) {
-		return free_large(szone, ptr);
+		return (void)free_large(szone, ptr, false);
 	} else {
 		return szone_free(szone->helper_zone, ptr);
 	}
@@ -214,9 +214,7 @@
 	szone_t *szone;
 	kern_return_t err;
 
-	if (!reader) {
-		reader = _malloc_default_reader;
-	}
+	reader = reader_or_in_memory_fallback(reader, task);
 
 	err = reader(task, zone_address, sizeof(szone_t), (void **)&szone);
 	if (err) {
@@ -354,7 +352,7 @@
 	uint64_t hw_memsize = 0;
 
 	/* get memory for the zone. */
-	szone = mvm_allocate_pages(SZONE_PAGED_SIZE, 0, 0, VM_MEMORY_MALLOC);
+	szone = mvm_allocate_pages(SZONE_PAGED_SIZE, 0, DISABLE_ASLR, VM_MEMORY_MALLOC);
 	if (!szone) {
 		return NULL;
 	}
@@ -377,15 +375,17 @@
 	rack_init(&szone->small_rack, RACK_TYPE_SMALL, 0, debug_flags | MALLOC_PURGEABLE);
 
 #if CONFIG_LARGE_CACHE
-	// madvise(..., MADV_REUSABLE) death-row arrivals above this threshold [~0.1%]
-	szone->large_entry_cache_reserve_limit = (size_t)(hw_memsize >> 10);
-
-	/* <rdar://problem/6610904> Reset protection when returning a previous large allocation? */
-	int32_t libSystemVersion = NSVersionOfLinkTimeLibrary("System");
-	if ((-1 != libSystemVersion) && ((libSystemVersion >> 16) < 112) /* CFSystemVersionSnowLeopard */) {
-		szone->large_legacy_reset_mprotect = TRUE;
-	} else {
-		szone->large_legacy_reset_mprotect = FALSE;
+	if (large_cache_enabled) {
+		// madvise(..., MADV_REUSABLE) death-row arrivals above this threshold [~0.1%]
+		szone->large_entry_cache_reserve_limit = (size_t)(hw_memsize >> 10);
+
+		/* <rdar://problem/6610904> Reset protection when returning a previous large allocation? */
+		int32_t libSystemVersion = NSVersionOfLinkTimeLibrary("System");
+		if ((-1 != libSystemVersion) && ((libSystemVersion >> 16) < 112) /* CFSystemVersionSnowLeopard */) {
+			szone->large_legacy_reset_mprotect = TRUE;
+		} else {
+			szone->large_legacy_reset_mprotect = FALSE;
+		}
 	}
 #endif
 
@@ -412,11 +412,13 @@
 	szone->debug_flags = debug_flags | MALLOC_PURGEABLE;
 
 	/* Purgeable zone does not support MALLOC_ADD_GUARD_PAGES. */
-	if (szone->debug_flags & MALLOC_ADD_GUARD_PAGES) {
-		malloc_report(ASL_LEVEL_INFO, "purgeable zone does not support guard pages\n");
-		szone->debug_flags &= ~MALLOC_ADD_GUARD_PAGES;
-	}
-
+	if (szone->debug_flags & MALLOC_ALL_GUARD_PAGE_FLAGS) {
+		if (!(szone->debug_flags & MALLOC_GUARD_ALL)) {
+			// Don't report when MallocGuardEdges == "all".
+			malloc_report(ASL_LEVEL_INFO, "purgeable zone does not support guard pages\n");
+		}
+		szone->debug_flags &= ~MALLOC_ALL_GUARD_PAGE_FLAGS;
+	}
 	_malloc_lock_init(&szone->large_szone_lock);
 
 	szone->helper_zone = (struct szone_s *)malloc_default_zone;