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