Loading...
tests/malloc_claimed_address_tests.c libmalloc-521.100.59 libmalloc-792.80.2
--- libmalloc/libmalloc-521.100.59/tests/malloc_claimed_address_tests.c
+++ libmalloc/libmalloc-792.80.2/tests/malloc_claimed_address_tests.c
@@ -8,20 +8,21 @@
 #include <darwintest.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <mach/mach.h>
-#include <mach/mach_vm.h>
 #include <malloc/malloc.h>
 #include <malloc_private.h>
 #include <sys/mman.h>
 #include "base.h"
 
+#if !MALLOC_TARGET_EXCLAVES
+#include <mach/mach.h>
+#include <mach/mach_vm.h>
+#endif // !MALLOC_TARGET_EXCLAVES
+
 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
 
 T_DECL(malloc_claimed_address_default_zone_test,
 		"Tests for malloc_claimed_address, default zone only",
-#if TARGET_OS_IPHONE
-		T_META_TAG_XZONE,
-#endif // TARGET_OS_IPHONE
+		T_META_TAG_ALL_ALLOCATORS, T_META_TAG_VM_PREFERRED,
 		T_META_ENVVAR("MallocNanoZone=0"))
 {
 	// NULL is never a possible pointer.
@@ -58,6 +59,7 @@
 	T_EXPECT_TRUE(result, "allocation from large with offset");
 	free(ptr);
 
+#if !MALLOC_TARGET_EXCLAVES
 	// Allocate some memory with vm_allocate() and make sure it's not claimed.
 	mach_vm_address_t addr;
 	kern_return_t kr = mach_vm_allocate(mach_task_self(), &addr, 1024, VM_FLAGS_ANYWHERE);
@@ -65,15 +67,17 @@
 	result = malloc_claimed_address((void *)addr);
 	T_EXPECT_FALSE(result, "address in VM allocated memory");
 	mach_vm_deallocate(mach_task_self(), addr, 1024);
-}
-
-
+#endif // !MALLOC_TARGET_EXCLAVES
+}
+
+
+#if !MALLOC_TARGET_EXCLAVES
+// Don't test on xzones because non-default xzones can claim allocations
+// from the main zone
 T_DECL(malloc_zone_claimed_address_test,
 		"Tests for malloc_zone_claimed_address",
-#if TARGET_OS_IPHONE
-		T_META_TAG_XZONE,
-#endif // TARGET_OS_IPHONE
-		T_META_ENVVAR("MallocNanoZone=0"))
+		T_META_ENVVAR("MallocNanoZone=0"),
+		T_META_TAG_MAGAZINE_ONLY, T_META_TAG_VM_PREFERRED)
 {
 	malloc_zone_t *zone = malloc_create_zone(0, 0);
 
@@ -145,13 +149,14 @@
 
 	malloc_destroy_zone(zone);
 }
-
+#endif // !MALLOC_TARGET_EXCLAVES
+
+#if !MALLOC_TARGET_EXCLAVES
 T_DECL(malloc_claimed_address_zone_test,
 		"Tests for malloc_claimed_address with another zone",
-#if TARGET_OS_IPHONE
-		T_META_TAG_XZONE,
-#endif // TARGET_OS_IPHONE
-		T_META_ENVVAR("MallocNanoZone=0"))
+		T_META_TAG_ALL_ALLOCATORS,
+		T_META_ENVVAR("MallocNanoZone=0"),
+	    T_META_TAG_VM_PREFERRED)
 {
 	// Allocate in a custom zone, check that we can still use
 	// malloc_claimed_address() to check whether an address is claimed.
@@ -189,10 +194,12 @@
 
 	malloc_destroy_zone(zone);
 }
+#endif // !MALLOC_TARGET_EXCLAVES
 
 T_DECL(malloc_claimed_address_nanozone_test,
 		"Tests for malloc_claimed_address with nano",
-		T_META_ENVVAR("MallocNanoZone=1"))
+		T_META_ENVVAR("MallocNanoZone=1"),
+	    T_META_TAG_VM_PREFERRED, T_META_TAG_MAGAZINE_ONLY)
 {
 	// NULL is never a possible pointer.
 	boolean_t result = malloc_claimed_address(NULL);
@@ -219,6 +226,7 @@
 	T_EXPECT_TRUE(result, "Above nano pointer check via default zone");
 	free(ptr);
 
+#if !MALLOC_TARGET_EXCLAVES
 	// Allocate some memory with vm_allocate() and make sure it's not claimed.
 	mach_vm_address_t addr;
 	kern_return_t kr = mach_vm_allocate(mach_task_self(), &addr, 1024, VM_FLAGS_ANYWHERE);
@@ -226,15 +234,16 @@
 	result = malloc_claimed_address((void *)addr);
 	T_EXPECT_FALSE(result, "address in VM allocated memory");
 	mach_vm_deallocate(mach_task_self(), addr, 1024);
-}
-
-
+#endif // !MALLOC_TARGET_EXCLAVES
+}
+
+#if !MALLOC_TARGET_EXCLAVES
+// Don't run this test on xzone malloc, since the test assumes that it's safe
+// to mprotect the zone returned by malloc_create_zone
 T_DECL(malloc_claimed_address_custom_zone_test,
 		"Tests for malloc_claimed_address in a zone that does not implement it",
-#if TARGET_OS_IPHONE
-		T_META_TAG_XZONE,
-#endif // TARGET_OS_IPHONE
-		T_META_ENVVAR("MallocNanoZone=0"))
+		T_META_ENVVAR("MallocNanoZone=0"), T_META_TAG_VM_PREFERRED,
+		T_META_TAG_MAGAZINE_ONLY)
 {
 	// Custom zones that do not support claimed_address must always appear
 	// to return true.
@@ -280,12 +289,11 @@
 
 	malloc_destroy_zone(zone);
 }
-
-#if TARGET_OS_IPHONE
+#endif // !MALLOC_TARGET_EXCLAVES
+
 T_DECL(malloc_claimed_address_xzone_test,
 		"Specific xzone malloc tests for malloc_claimed_address",
-		T_META_TAG_XZONE_ONLY,
-		T_META_ENVVAR("MallocProbGuard=0"))
+		T_META_TAG_XZONE_ONLY, T_META_TAG_VM_PREFERRED)
 {
 	// Allocate a HUGE buffer, and then check that both the start and end of it
 	// are claimed by malloc
@@ -295,4 +303,3 @@
 			"end of HUGE allocation");
 	free(ptr);
 }
-#endif // TARGET_OS_IPHONE