Loading...
src/purgeable_malloc.c libmalloc-792.41.1 libmalloc-166.251.2
--- libmalloc/libmalloc-792.41.1/src/purgeable_malloc.c
+++ libmalloc/libmalloc-166.251.2/src/purgeable_malloc.c
@@ -80,7 +80,7 @@
 	entry = large_entry_for_pointer_no_lock(szone, ptr);
 	SZONE_UNLOCK(szone);
 	if (entry) {
-		return (void)free_large(szone, ptr, false);
+		return free_large(szone, ptr);
 	} else {
 		return szone_free(szone->helper_zone, ptr);
 	}
@@ -214,16 +214,17 @@
 	szone_t *szone;
 	kern_return_t err;
 
-	reader = reader_or_in_memory_fallback(reader, task);
+	if (!reader) {
+		reader = _szone_default_reader;
+	}
 
 	err = reader(task, zone_address, sizeof(szone_t), (void **)&szone);
 	if (err) {
 		return err;
 	}
 
-	err = large_in_use_enumerator(task, context, type_mask,
-			(vm_address_t)szone->large_entries, szone->num_large_entries,
-			reader, recorder);
+	err = large_in_use_enumerator(
+								  task, context, type_mask, (vm_address_t)szone->large_entries, szone->num_large_entries, reader, recorder);
 	return err;
 }
 
@@ -244,31 +245,10 @@
 }
 
 static void
-purgeable_print(task_t task, unsigned level MALLOC_UNUSED,
-		vm_address_t zone_address, memory_reader_t reader,
-		print_task_printer_t printer)
-{
-	szone_t *szone;
-	if (reader(task, zone_address, sizeof(szone_t), (void **)&szone)) {
-		printer("Purgeable zone %p: inUse=%u(%y) flags=%d\n", zone_address,
-				szone->num_large_objects_in_use,
-				(int)szone->num_bytes_in_large_objects,
-				szone->debug_flags);
-	}
-}
-
-static void
-purgeable_print_self(szone_t *szone, boolean_t verbose)
-{
-	purgeable_print(mach_task_self(), verbose ? MALLOC_VERBOSE_PRINT_LEVEL : 0,
-			(vm_address_t)szone, _malloc_default_reader, malloc_report_simple);
-}
-
-static void
-purgeable_print_task(task_t task, unsigned level, vm_address_t zone_address,
-		memory_reader_t reader, print_task_printer_t printer)
-{
-	purgeable_print(task, level, zone_address, reader, printer);
+purgeable_print(szone_t *szone, boolean_t verbose)
+{
+	malloc_report(MALLOC_REPORT_NOLOG | MALLOC_REPORT_NOPREFIX, "Scalable zone %p: inUse=%u(%y) flags=%d\n", szone,
+				   szone->num_large_objects_in_use, (int)szone->num_bytes_in_large_objects, szone->debug_flags);
 }
 
 static void
@@ -324,18 +304,10 @@
 }
 
 static const struct malloc_introspection_t purgeable_introspect = {
-	(void *)purgeable_ptr_in_use_enumerator,
-	(void *)purgeable_good_size,
-	(void *)purgeable_check,
-	(void *)purgeable_print_self,
-	(void *)purgeable_log,
-	(void *)purgeable_force_lock,
-	(void *)purgeable_force_unlock,
-	(void *)purgeable_statistics,
-	(void *)purgeable_locked,
-	NULL, NULL, NULL, NULL, /* Zone enumeration version 7 and forward. */
-	(void *)purgeable_reinit_lock, // reinit_lock version 9 and forward
-	(void *)purgeable_print_task,  // print_task version 11 and forward
+	(void *)purgeable_ptr_in_use_enumerator, (void *)purgeable_good_size, (void *)purgeable_check, (void *)purgeable_print,
+	purgeable_log, (void *)purgeable_force_lock, (void *)purgeable_force_unlock, (void *)purgeable_statistics,
+	(void *)purgeable_locked, NULL, NULL, NULL, NULL, /* Zone enumeration version 7 and forward. */
+	(void *)purgeable_reinit_lock, // reinit_lock version 9 and foward
 }; // marked as const to spare the DATA section
 
 
@@ -352,7 +324,7 @@
 	uint64_t hw_memsize = 0;
 
 	/* get memory for the zone. */
-	szone = mvm_allocate_pages(SZONE_PAGED_SIZE, 0, DISABLE_ASLR, VM_MEMORY_MALLOC);
+	szone = mvm_allocate_pages(SZONE_PAGED_SIZE, 0, 0, VM_MEMORY_MALLOC);
 	if (!szone) {
 		return NULL;
 	}
@@ -375,21 +347,19 @@
 	rack_init(&szone->small_rack, RACK_TYPE_SMALL, 0, debug_flags | MALLOC_PURGEABLE);
 
 #if CONFIG_LARGE_CACHE
-	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;
-		}
+	// 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
 
-	szone->basic_zone.version = 11;
+	szone->basic_zone.version = 10;
 	szone->basic_zone.size = (void *)purgeable_size;
 	szone->basic_zone.malloc = (void *)purgeable_malloc;
 	szone->basic_zone.calloc = (void *)purgeable_calloc;
@@ -412,13 +382,11 @@
 	szone->debug_flags = debug_flags | MALLOC_PURGEABLE;
 
 	/* Purgeable zone does not support 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;
-	}
+	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;
+	}
+
 	_malloc_lock_init(&szone->large_szone_lock);
 
 	szone->helper_zone = (struct szone_s *)malloc_default_zone;