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