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