1*2c2f96dcSApple OSS Distributions #include <servers/bootstrap.h> 2*2c2f96dcSApple OSS Distributions #include <mach/mach.h> 3*2c2f96dcSApple OSS Distributions #include <mach/message.h> 4*2c2f96dcSApple OSS Distributions #include <stdlib.h> 5*2c2f96dcSApple OSS Distributions #include <sys/sysctl.h> 6*2c2f96dcSApple OSS Distributions #include <unistd.h> 7*2c2f96dcSApple OSS Distributions #include <pthread.h> 8*2c2f96dcSApple OSS Distributions 9*2c2f96dcSApple OSS Distributions #ifdef T_NAMESPACE 10*2c2f96dcSApple OSS Distributions #undef T_NAMESPACE 11*2c2f96dcSApple OSS Distributions #endif 12*2c2f96dcSApple OSS Distributions 13*2c2f96dcSApple OSS Distributions #include <darwintest.h> 14*2c2f96dcSApple OSS Distributions #include <darwintest_utils.h> 15*2c2f96dcSApple OSS Distributions #include <darwintest_multiprocess.h> 16*2c2f96dcSApple OSS Distributions 17*2c2f96dcSApple OSS Distributions T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true), 18*2c2f96dcSApple OSS Distributions T_META_NAMESPACE("xnu.ipc"), 19*2c2f96dcSApple OSS Distributions T_META_RADAR_COMPONENT_NAME("xnu"), 20*2c2f96dcSApple OSS Distributions T_META_RADAR_COMPONENT_VERSION("IPC")); 21*2c2f96dcSApple OSS Distributions 22*2c2f96dcSApple OSS Distributions 23*2c2f96dcSApple OSS Distributions T_DECL(task_fatal_port, "Create a child and kill it using the task fatal port") 24*2c2f96dcSApple OSS Distributions { 25*2c2f96dcSApple OSS Distributions mach_port_name_t old_port_name = 0, new_port_name = 1; 26*2c2f96dcSApple OSS Distributions int port_name_size, status, ret; 27*2c2f96dcSApple OSS Distributions pid_t child, pid; 28*2c2f96dcSApple OSS Distributions 29*2c2f96dcSApple OSS Distributions #if TARGET_OS_BRIDGE 30*2c2f96dcSApple OSS Distributions T_SKIP("Skip this test on 32 bit kernels and bridgeos"); 31*2c2f96dcSApple OSS Distributions #endif 32*2c2f96dcSApple OSS Distributions 33*2c2f96dcSApple OSS Distributions child = fork(); 34*2c2f96dcSApple OSS Distributions if (child == 0) { 35*2c2f96dcSApple OSS Distributions port_name_size = sizeof(old_port_name); 36*2c2f96dcSApple OSS Distributions ret = sysctlbyname("machdep.task_get_fatal_port", &old_port_name, &port_name_size, &new_port_name, sizeof(new_port_name)); 37*2c2f96dcSApple OSS Distributions if (ret < 0) { 38*2c2f96dcSApple OSS Distributions printf("sysctlbyname failed"); 39*2c2f96dcSApple OSS Distributions exit(2); 40*2c2f96dcSApple OSS Distributions } 41*2c2f96dcSApple OSS Distributions printf("old_port_name = %d \n", old_port_name); 42*2c2f96dcSApple OSS Distributions mach_port_deallocate(mach_task_self(), old_port_name); 43*2c2f96dcSApple OSS Distributions 44*2c2f96dcSApple OSS Distributions while (1) { 45*2c2f96dcSApple OSS Distributions sleep(1); 46*2c2f96dcSApple OSS Distributions } 47*2c2f96dcSApple OSS Distributions } 48*2c2f96dcSApple OSS Distributions 49*2c2f96dcSApple OSS Distributions pid = waitpid(child, &status, 0); 50*2c2f96dcSApple OSS Distributions T_ASSERT_EQ(pid, child, "waitpid returns correct pid"); 51*2c2f96dcSApple OSS Distributions T_EXPECT_EQ(WIFSIGNALED(status), true, "child was signaled"); 52*2c2f96dcSApple OSS Distributions T_EXPECT_EQ(WTERMSIG(status), SIGKILL, "child was sent SIGKILL"); 53*2c2f96dcSApple OSS Distributions } 54