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