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