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