1*d8b80295SApple OSS Distributions #include <darwintest.h> 2*d8b80295SApple OSS Distributions #include <mach/mach.h> 3*d8b80295SApple OSS Distributions #include <stdlib.h> 4*d8b80295SApple OSS Distributions #include <stdio.h> 5*d8b80295SApple OSS Distributions 6*d8b80295SApple OSS Distributions T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true), 7*d8b80295SApple OSS Distributions T_META_NAMESPACE("xnu.ipc"), 8*d8b80295SApple OSS Distributions T_META_RADAR_COMPONENT_NAME("xnu"), 9*d8b80295SApple OSS Distributions T_META_RADAR_COMPONENT_VERSION("IPC")); 10*d8b80295SApple OSS Distributions 11*d8b80295SApple OSS Distributions #define NR_PORTS 4 12*d8b80295SApple OSS Distributions 13*d8b80295SApple OSS Distributions T_DECL(mach_port_deallocate, "mach_port_deallocate deallocates also PORT_SET"){ 14*d8b80295SApple OSS Distributions mach_port_t port_set; 15*d8b80295SApple OSS Distributions mach_port_t port[NR_PORTS]; 16*d8b80295SApple OSS Distributions int i, ret; 17*d8b80295SApple OSS Distributions 18*d8b80295SApple OSS Distributions ret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_PORT_SET, &port_set); 19*d8b80295SApple OSS Distributions T_ASSERT_MACH_SUCCESS(ret, "mach_port_allocate MACH_PORT_RIGHT_PORT_SET"); 20*d8b80295SApple OSS Distributions 21*d8b80295SApple OSS Distributions for (i = 0; i < NR_PORTS; i++) { 22*d8b80295SApple OSS Distributions ret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port[i]); 23*d8b80295SApple OSS Distributions T_ASSERT_MACH_SUCCESS(ret, "mach_port_allocate MACH_PORT_RIGHT_RECEIVE"); 24*d8b80295SApple OSS Distributions 25*d8b80295SApple OSS Distributions ret = mach_port_move_member(mach_task_self(), port[i], port_set); 26*d8b80295SApple OSS Distributions T_ASSERT_MACH_SUCCESS(ret, "mach_port_move_member"); 27*d8b80295SApple OSS Distributions } 28*d8b80295SApple OSS Distributions 29*d8b80295SApple OSS Distributions T_LOG("Ports created"); 30*d8b80295SApple OSS Distributions 31*d8b80295SApple OSS Distributions /* do something */ 32*d8b80295SApple OSS Distributions 33*d8b80295SApple OSS Distributions for (i = 0; i < NR_PORTS; i++) { 34*d8b80295SApple OSS Distributions ret = mach_port_mod_refs(mach_task_self(), port[i], MACH_PORT_RIGHT_RECEIVE, -1); 35*d8b80295SApple OSS Distributions T_ASSERT_MACH_SUCCESS(ret, "mach_port_mod_refs -1 RIGHT_RECEIVE"); 36*d8b80295SApple OSS Distributions } 37*d8b80295SApple OSS Distributions 38*d8b80295SApple OSS Distributions ret = mach_port_deallocate(mach_task_self(), port_set); 39*d8b80295SApple OSS Distributions T_ASSERT_MACH_SUCCESS(ret, "mach_port_deallocate PORT_SET"); 40*d8b80295SApple OSS Distributions 41*d8b80295SApple OSS Distributions T_LOG("Ports erased"); 42*d8b80295SApple OSS Distributions } 43