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