1 #include <sys/wait.h> 2 #include <spawn.h> 3 #include <spawn_private.h> 4 5 #include <mach/mach_init.h> 6 #include <mach/mach_vm.h> 7 8 #include <darwintest.h> 9 #include <darwintest_utils.h> 10 11 T_GLOBAL_META( 12 T_META_NAMESPACE("xnu.vm"), 13 T_META_RADAR_COMPONENT_NAME("xnu"), 14 T_META_RADAR_COMPONENT_VERSION("VM"), 15 T_META_RUN_CONCURRENTLY(true)); 16 17 extern char * testpath; 18 19 T_DECL(set_max_addr, 20 "Description", 21 T_META_CHECK_LEAKS(false), T_META_TAG_VM_PREFERRED) 22 { 23 #if (!defined(TARGET_OS_MAC) && defined(__arm64__) && defined(__LP64__)) 24 int result = 0; 25 int code = 0; 26 int child_pid = 0; 27 int status = 0; 28 char * command_path = "./vm_set_max_addr_helper"; 29 char * command_args[] = { command_path, NULL }; 30 posix_spawnattr_t attrp; 31 32 result = posix_spawnattr_init(&attrp); 33 T_ASSERT_POSIX_SUCCESS(result, "posix_spawnattr_init"); 34 35 result = posix_spawn(&child_pid, command_path, NULL, &attrp, command_args, NULL); 36 T_ASSERT_POSIX_SUCCESS(result, "posix_spawn"); 37 38 result = waitpid(child_pid, &status, 0); 39 T_ASSERT_POSIX_SUCCESS(result, "waitpid"); 40 41 code = WEXITSTATUS(status); 42 T_ASSERT_NE_INT(code, 0, "Child should have failed"); 43 44 result = posix_spawnattr_set_max_addr_np(&attrp, ~0ULL); 45 T_ASSERT_POSIX_SUCCESS(result, "posix_spawnattr_set_max_addr_np"); 46 47 result = posix_spawn(&child_pid, command_path, NULL, &attrp, command_args, NULL); 48 T_ASSERT_POSIX_SUCCESS(result, "posix_spawn"); 49 50 result = waitpid(child_pid, &status, 0); 51 T_ASSERT_POSIX_SUCCESS(result, "waitpid"); 52 53 code = WEXITSTATUS(status); 54 T_ASSERT_EQ_INT(code, 0, "Child should have succeeded"); 55 56 posix_spawnattr_destroy(&attrp); 57 T_ASSERT_POSIX_SUCCESS(result, "posix_spawnattr_destroy"); 58 #else /* !defined(__arm64__) || !defined(__LP64__) */ 59 T_SKIP("Not supported on this architecture"); 60 #endif /* (defined(__arm64__) && defined(__LP64__)) */ 61 } 62