1 #include <stdio.h> 2 #include <mach/mach.h> 3 #include <mach/message.h> 4 #include <unistd.h> 5 #include <assert.h> 6 #include <string.h> 7 #include <stdlib.h> 8 9 static inline mach_port_type_t get_port_type(mach_port_t mp)10get_port_type(mach_port_t mp) 11 { 12 mach_port_type_t type = 0; 13 mach_port_type(mach_task_self(), mp, &type); 14 return type; 15 } 16 17 int main()18main() 19 { 20 mach_port_t port = MACH_PORT_NULL; 21 kern_return_t retval = KERN_SUCCESS; 22 23 mach_port_t task = mach_task_self(); 24 25 printf("Starting the receive right allocation loop\n"); 26 int i = 0; 27 while (!retval) { 28 retval = mach_port_allocate(task, MACH_PORT_RIGHT_RECEIVE, &port); 29 assert(retval == 0); 30 //printf("%d. allocate a port=[%d]\n", i, port); 31 assert(get_port_type(port) == MACH_PORT_TYPE_RECEIVE); 32 i++; 33 } 34 35 exit(1); 36 } 37