1*fdd8201dSApple OSS Distributions #include <mach/mach.h>
2*fdd8201dSApple OSS Distributions #include <stdlib.h>
3*fdd8201dSApple OSS Distributions #include <pthread.h>
4*fdd8201dSApple OSS Distributions #include <unistd.h>
5*fdd8201dSApple OSS Distributions #include <stdio.h>
6*fdd8201dSApple OSS Distributions #include <assert.h>
7*fdd8201dSApple OSS Distributions #include <mach/task.h>
8*fdd8201dSApple OSS Distributions
9*fdd8201dSApple OSS Distributions /*
10*fdd8201dSApple OSS Distributions * DO NOT run this test file by itself.
11*fdd8201dSApple OSS Distributions * This test is meant to be invoked by control_port_options darwintest.
12*fdd8201dSApple OSS Distributions *
13*fdd8201dSApple OSS Distributions * If hard enforcement for pinned control port is on, pinned tests are
14*fdd8201dSApple OSS Distributions * expected to generate fatal EXC_GUARD.
15*fdd8201dSApple OSS Distributions *
16*fdd8201dSApple OSS Distributions * If hard enforcement for immovable control port is on, immovable tests are
17*fdd8201dSApple OSS Distributions * expected to generate fatal EXC_GUARD.
18*fdd8201dSApple OSS Distributions *
19*fdd8201dSApple OSS Distributions * The type of exception raised (if any) is checked on control_port_options side.
20*fdd8201dSApple OSS Distributions */
21*fdd8201dSApple OSS Distributions #define MAX_TEST_NUM 17
22*fdd8201dSApple OSS Distributions
23*fdd8201dSApple OSS Distributions static int
attempt_send_immovable_port(mach_port_name_t port,mach_msg_type_name_t disp)24*fdd8201dSApple OSS Distributions attempt_send_immovable_port(mach_port_name_t port, mach_msg_type_name_t disp)
25*fdd8201dSApple OSS Distributions {
26*fdd8201dSApple OSS Distributions mach_port_t server;
27*fdd8201dSApple OSS Distributions kern_return_t kr;
28*fdd8201dSApple OSS Distributions kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &server);
29*fdd8201dSApple OSS Distributions assert(kr == 0);
30*fdd8201dSApple OSS Distributions
31*fdd8201dSApple OSS Distributions kr = mach_port_insert_right(mach_task_self(), server, server, MACH_MSG_TYPE_MAKE_SEND);
32*fdd8201dSApple OSS Distributions assert(kr == 0);
33*fdd8201dSApple OSS Distributions
34*fdd8201dSApple OSS Distributions struct {
35*fdd8201dSApple OSS Distributions mach_msg_header_t header;
36*fdd8201dSApple OSS Distributions mach_msg_body_t body;
37*fdd8201dSApple OSS Distributions mach_msg_port_descriptor_t desc;
38*fdd8201dSApple OSS Distributions } msg;
39*fdd8201dSApple OSS Distributions
40*fdd8201dSApple OSS Distributions msg.header.msgh_remote_port = server;
41*fdd8201dSApple OSS Distributions msg.header.msgh_local_port = MACH_PORT_NULL;
42*fdd8201dSApple OSS Distributions msg.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0) | MACH_MSGH_BITS_COMPLEX;
43*fdd8201dSApple OSS Distributions msg.header.msgh_size = sizeof msg;
44*fdd8201dSApple OSS Distributions
45*fdd8201dSApple OSS Distributions msg.body.msgh_descriptor_count = 1;
46*fdd8201dSApple OSS Distributions
47*fdd8201dSApple OSS Distributions msg.desc.name = port;
48*fdd8201dSApple OSS Distributions msg.desc.disposition = disp;
49*fdd8201dSApple OSS Distributions msg.desc.type = MACH_MSG_PORT_DESCRIPTOR;
50*fdd8201dSApple OSS Distributions
51*fdd8201dSApple OSS Distributions return mach_msg_send(&msg.header);
52*fdd8201dSApple OSS Distributions }
53*fdd8201dSApple OSS Distributions
54*fdd8201dSApple OSS Distributions static void
pinned_test_main_thread_mod_ref(void)55*fdd8201dSApple OSS Distributions pinned_test_main_thread_mod_ref(void)
56*fdd8201dSApple OSS Distributions {
57*fdd8201dSApple OSS Distributions printf("[Crasher]: Mod refs main thread's self port to 0\n");
58*fdd8201dSApple OSS Distributions mach_port_t thread_self = mach_thread_self();
59*fdd8201dSApple OSS Distributions kern_return_t kr = mach_port_mod_refs(mach_task_self(), thread_self, MACH_PORT_RIGHT_SEND, -2);
60*fdd8201dSApple OSS Distributions
61*fdd8201dSApple OSS Distributions printf("[Crasher pinned_test_main_thread_mod_ref] mach_port_mod_refs returned %s \n.", mach_error_string(kr));
62*fdd8201dSApple OSS Distributions }
63*fdd8201dSApple OSS Distributions
64*fdd8201dSApple OSS Distributions static void*
pthread_run(void)65*fdd8201dSApple OSS Distributions pthread_run(void)
66*fdd8201dSApple OSS Distributions {
67*fdd8201dSApple OSS Distributions printf("[Crasher]: Deallocate pthread_self\n");
68*fdd8201dSApple OSS Distributions mach_port_t th_self = pthread_mach_thread_np(pthread_self());
69*fdd8201dSApple OSS Distributions kern_return_t kr = mach_port_deallocate(mach_task_self(), th_self);
70*fdd8201dSApple OSS Distributions
71*fdd8201dSApple OSS Distributions printf("[Crasher pinned_test_pthread_dealloc] mach_port_deallocate returned %s \n.", mach_error_string(kr));
72*fdd8201dSApple OSS Distributions return NULL;
73*fdd8201dSApple OSS Distributions }
74*fdd8201dSApple OSS Distributions
75*fdd8201dSApple OSS Distributions static void
pinned_test_pthread_dealloc(void)76*fdd8201dSApple OSS Distributions pinned_test_pthread_dealloc(void)
77*fdd8201dSApple OSS Distributions {
78*fdd8201dSApple OSS Distributions printf("[Crasher]: Create a pthread and deallocate its self port\n");
79*fdd8201dSApple OSS Distributions pthread_t thread;
80*fdd8201dSApple OSS Distributions int ret = pthread_create(&thread, NULL, pthread_run, NULL);
81*fdd8201dSApple OSS Distributions assert(ret == 0);
82*fdd8201dSApple OSS Distributions ret = pthread_join(thread, NULL);
83*fdd8201dSApple OSS Distributions assert(ret == 0);
84*fdd8201dSApple OSS Distributions }
85*fdd8201dSApple OSS Distributions
86*fdd8201dSApple OSS Distributions static void
pinned_test_task_self_dealloc(void)87*fdd8201dSApple OSS Distributions pinned_test_task_self_dealloc(void)
88*fdd8201dSApple OSS Distributions {
89*fdd8201dSApple OSS Distributions printf("[Crasher]: Deallocate mach_task_self twice\n");
90*fdd8201dSApple OSS Distributions mach_port_t task_self = mach_task_self();
91*fdd8201dSApple OSS Distributions kern_return_t kr = mach_port_deallocate(task_self, task_self);
92*fdd8201dSApple OSS Distributions assert(kr == 0);
93*fdd8201dSApple OSS Distributions kr = mach_port_deallocate(task_self, task_self);
94*fdd8201dSApple OSS Distributions
95*fdd8201dSApple OSS Distributions printf("[Crasher pinned_test_task_self_dealloc] mach_port_deallocate returned %s \n.", mach_error_string(kr));
96*fdd8201dSApple OSS Distributions }
97*fdd8201dSApple OSS Distributions
98*fdd8201dSApple OSS Distributions static void
pinned_test_task_self_mod_ref(void)99*fdd8201dSApple OSS Distributions pinned_test_task_self_mod_ref(void)
100*fdd8201dSApple OSS Distributions {
101*fdd8201dSApple OSS Distributions printf("[Crasher]: Mod refs mach_task_self() to 0\n");
102*fdd8201dSApple OSS Distributions kern_return_t kr = mach_port_mod_refs(mach_task_self(), mach_task_self(), MACH_PORT_RIGHT_SEND, -2);
103*fdd8201dSApple OSS Distributions
104*fdd8201dSApple OSS Distributions printf("[Crasher pinned_test_task_self_mod_ref] mach_port_mod_refs returned %s \n.", mach_error_string(kr));
105*fdd8201dSApple OSS Distributions }
106*fdd8201dSApple OSS Distributions
107*fdd8201dSApple OSS Distributions static void
pinned_test_task_threads_mod_ref(void)108*fdd8201dSApple OSS Distributions pinned_test_task_threads_mod_ref(void)
109*fdd8201dSApple OSS Distributions {
110*fdd8201dSApple OSS Distributions printf("[Crasher]: task_threads should return pinned thread ports. Mod refs them to 0\n");
111*fdd8201dSApple OSS Distributions thread_array_t th_list;
112*fdd8201dSApple OSS Distributions mach_msg_type_number_t th_cnt;
113*fdd8201dSApple OSS Distributions kern_return_t kr;
114*fdd8201dSApple OSS Distributions mach_port_t th_kp = mach_thread_self();
115*fdd8201dSApple OSS Distributions mach_port_deallocate(mach_task_self(), th_kp);
116*fdd8201dSApple OSS Distributions
117*fdd8201dSApple OSS Distributions kr = task_threads(mach_task_self(), &th_list, &th_cnt);
118*fdd8201dSApple OSS Distributions mach_port_deallocate(mach_task_self(), th_list[0]);
119*fdd8201dSApple OSS Distributions
120*fdd8201dSApple OSS Distributions kr = mach_port_mod_refs(mach_task_self(), th_list[0], MACH_PORT_RIGHT_SEND, -1);
121*fdd8201dSApple OSS Distributions
122*fdd8201dSApple OSS Distributions printf("[Crasher pinned_test_task_threads_mod_ref] mach_port_mod_refs returned %s \n.", mach_error_string(kr));
123*fdd8201dSApple OSS Distributions }
124*fdd8201dSApple OSS Distributions
125*fdd8201dSApple OSS Distributions static void
pinned_test_mach_port_destroy(void)126*fdd8201dSApple OSS Distributions pinned_test_mach_port_destroy(void)
127*fdd8201dSApple OSS Distributions {
128*fdd8201dSApple OSS Distributions kern_return_t kr = mach_port_destroy(mach_task_self(), mach_task_self());
129*fdd8201dSApple OSS Distributions printf("[Crasher pinned_test_mach_port_destroy] mach_port_destroy returned %s \n.", mach_error_string(kr));
130*fdd8201dSApple OSS Distributions }
131*fdd8201dSApple OSS Distributions
132*fdd8201dSApple OSS Distributions static void
pinned_test_move_send_as_remote_port(void)133*fdd8201dSApple OSS Distributions pinned_test_move_send_as_remote_port(void)
134*fdd8201dSApple OSS Distributions {
135*fdd8201dSApple OSS Distributions struct {
136*fdd8201dSApple OSS Distributions mach_msg_header_t header;
137*fdd8201dSApple OSS Distributions } msg;
138*fdd8201dSApple OSS Distributions
139*fdd8201dSApple OSS Distributions kern_return_t kr = mach_port_deallocate(mach_task_self(), mach_task_self());
140*fdd8201dSApple OSS Distributions assert(kr == 0);
141*fdd8201dSApple OSS Distributions
142*fdd8201dSApple OSS Distributions /*
143*fdd8201dSApple OSS Distributions * We allow move send on remote kobject port but this should trip on pinning on last ref.
144*fdd8201dSApple OSS Distributions * See: IPC_OBJECT_COPYIN_FLAGS_ALLOW_IMMOVABLE_SEND.
145*fdd8201dSApple OSS Distributions */
146*fdd8201dSApple OSS Distributions msg.header.msgh_remote_port = mach_task_self();
147*fdd8201dSApple OSS Distributions msg.header.msgh_local_port = MACH_PORT_NULL;
148*fdd8201dSApple OSS Distributions msg.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MOVE_SEND, 0);
149*fdd8201dSApple OSS Distributions msg.header.msgh_id = 2000;
150*fdd8201dSApple OSS Distributions msg.header.msgh_size = sizeof msg;
151*fdd8201dSApple OSS Distributions
152*fdd8201dSApple OSS Distributions kr = mach_msg_send(&msg.header);
153*fdd8201dSApple OSS Distributions
154*fdd8201dSApple OSS Distributions printf("[Crasher pinned_test_move_send_as_remote_port] mach_msg_send returned %s \n.", mach_error_string(kr));
155*fdd8201dSApple OSS Distributions }
156*fdd8201dSApple OSS Distributions
157*fdd8201dSApple OSS Distributions static void
immovable_test_move_send_as_remote_port(void)158*fdd8201dSApple OSS Distributions immovable_test_move_send_as_remote_port(void)
159*fdd8201dSApple OSS Distributions {
160*fdd8201dSApple OSS Distributions struct {
161*fdd8201dSApple OSS Distributions mach_msg_header_t header;
162*fdd8201dSApple OSS Distributions } msg;
163*fdd8201dSApple OSS Distributions
164*fdd8201dSApple OSS Distributions /* Local port cannot be immovable. See: ipc_right_copyin_check_reply() */
165*fdd8201dSApple OSS Distributions msg.header.msgh_remote_port = mach_task_self();
166*fdd8201dSApple OSS Distributions msg.header.msgh_local_port = mach_task_self();
167*fdd8201dSApple OSS Distributions msg.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MOVE_SEND, MACH_MSG_TYPE_MOVE_SEND);
168*fdd8201dSApple OSS Distributions msg.header.msgh_id = 2000;
169*fdd8201dSApple OSS Distributions msg.header.msgh_size = sizeof msg;
170*fdd8201dSApple OSS Distributions
171*fdd8201dSApple OSS Distributions kern_return_t kr = mach_msg_send(&msg.header);
172*fdd8201dSApple OSS Distributions
173*fdd8201dSApple OSS Distributions printf("[Crasher immovable_test_move_send_as_remote_port] mach_msg_send returned %s \n.", mach_error_string(kr));
174*fdd8201dSApple OSS Distributions }
175*fdd8201dSApple OSS Distributions
176*fdd8201dSApple OSS Distributions static void
immovable_test_move_send_task_self(void)177*fdd8201dSApple OSS Distributions immovable_test_move_send_task_self(void)
178*fdd8201dSApple OSS Distributions {
179*fdd8201dSApple OSS Distributions kern_return_t kr;
180*fdd8201dSApple OSS Distributions printf("[Crasher]: Move send mach_task_self_\n");
181*fdd8201dSApple OSS Distributions kr = attempt_send_immovable_port(mach_task_self(), MACH_MSG_TYPE_MOVE_SEND);
182*fdd8201dSApple OSS Distributions
183*fdd8201dSApple OSS Distributions printf("[Crasher immovable_test_move_send_task_self] attempt_send_immovable_port returned %s \n.", mach_error_string(kr));
184*fdd8201dSApple OSS Distributions }
185*fdd8201dSApple OSS Distributions
186*fdd8201dSApple OSS Distributions static void
immovable_test_copy_send_task_self(void)187*fdd8201dSApple OSS Distributions immovable_test_copy_send_task_self(void)
188*fdd8201dSApple OSS Distributions {
189*fdd8201dSApple OSS Distributions kern_return_t kr;
190*fdd8201dSApple OSS Distributions printf("[Crasher]: Copy send mach_task_self_\n");
191*fdd8201dSApple OSS Distributions kr = attempt_send_immovable_port(mach_task_self(), MACH_MSG_TYPE_COPY_SEND);
192*fdd8201dSApple OSS Distributions
193*fdd8201dSApple OSS Distributions printf("[Crasher immovable_test_copy_send_task_self] attempt_send_immovable_port returned %s \n.", mach_error_string(kr));
194*fdd8201dSApple OSS Distributions }
195*fdd8201dSApple OSS Distributions
196*fdd8201dSApple OSS Distributions static void
immovable_test_move_send_thread_self(void)197*fdd8201dSApple OSS Distributions immovable_test_move_send_thread_self(void)
198*fdd8201dSApple OSS Distributions {
199*fdd8201dSApple OSS Distributions kern_return_t kr;
200*fdd8201dSApple OSS Distributions printf("[Crasher]: Move send main thread's self port\n");
201*fdd8201dSApple OSS Distributions kr = attempt_send_immovable_port(mach_thread_self(), MACH_MSG_TYPE_MOVE_SEND);
202*fdd8201dSApple OSS Distributions
203*fdd8201dSApple OSS Distributions printf("[Crasher immovable_test_move_send_thread_self] attempt_send_immovable_port returned %s \n.", mach_error_string(kr));
204*fdd8201dSApple OSS Distributions }
205*fdd8201dSApple OSS Distributions
206*fdd8201dSApple OSS Distributions static void
immovable_test_copy_send_thread_self(void)207*fdd8201dSApple OSS Distributions immovable_test_copy_send_thread_self(void)
208*fdd8201dSApple OSS Distributions {
209*fdd8201dSApple OSS Distributions kern_return_t kr;
210*fdd8201dSApple OSS Distributions mach_port_t port;
211*fdd8201dSApple OSS Distributions printf("[Crasher]: Copy send main thread's self port\n");
212*fdd8201dSApple OSS Distributions port = mach_thread_self();
213*fdd8201dSApple OSS Distributions kr = attempt_send_immovable_port(port, MACH_MSG_TYPE_COPY_SEND);
214*fdd8201dSApple OSS Distributions printf("[Crasher immovable_test_copy_send_thread_self] attempt_send_immovable_port returned %s \n.", mach_error_string(kr));
215*fdd8201dSApple OSS Distributions
216*fdd8201dSApple OSS Distributions mach_port_deallocate(mach_task_self(), port);
217*fdd8201dSApple OSS Distributions }
218*fdd8201dSApple OSS Distributions
219*fdd8201dSApple OSS Distributions static void
immovable_test_copy_send_task_read(void)220*fdd8201dSApple OSS Distributions immovable_test_copy_send_task_read(void)
221*fdd8201dSApple OSS Distributions {
222*fdd8201dSApple OSS Distributions kern_return_t kr;
223*fdd8201dSApple OSS Distributions mach_port_t port;
224*fdd8201dSApple OSS Distributions printf("[Crasher]: Copy send task read port\n");
225*fdd8201dSApple OSS Distributions kr = task_get_special_port(mach_task_self(), TASK_READ_PORT, &port);
226*fdd8201dSApple OSS Distributions assert(kr == 0);
227*fdd8201dSApple OSS Distributions kr = attempt_send_immovable_port(port, MACH_MSG_TYPE_COPY_SEND);
228*fdd8201dSApple OSS Distributions printf("[Crasher immovable_test_copy_send_task_read] attempt_send_immovable_port returned %s \n.", mach_error_string(kr));
229*fdd8201dSApple OSS Distributions
230*fdd8201dSApple OSS Distributions mach_port_deallocate(mach_task_self(), port);
231*fdd8201dSApple OSS Distributions }
232*fdd8201dSApple OSS Distributions
233*fdd8201dSApple OSS Distributions static void
immovable_test_copy_send_task_inspect(void)234*fdd8201dSApple OSS Distributions immovable_test_copy_send_task_inspect(void)
235*fdd8201dSApple OSS Distributions {
236*fdd8201dSApple OSS Distributions kern_return_t kr;
237*fdd8201dSApple OSS Distributions mach_port_t port;
238*fdd8201dSApple OSS Distributions printf("[Crasher]: Move send task inspect port\n");
239*fdd8201dSApple OSS Distributions kr = task_get_special_port(mach_task_self(), TASK_INSPECT_PORT, &port);
240*fdd8201dSApple OSS Distributions assert(kr == 0);
241*fdd8201dSApple OSS Distributions kr = attempt_send_immovable_port(port, MACH_MSG_TYPE_MOVE_SEND);
242*fdd8201dSApple OSS Distributions printf("[Crasher immovable_test_copy_send_task_inspect] attempt_send_immovable_port returned %s \n.", mach_error_string(kr));
243*fdd8201dSApple OSS Distributions }
244*fdd8201dSApple OSS Distributions
245*fdd8201dSApple OSS Distributions static void
immovable_test_move_send_thread_inspect(void)246*fdd8201dSApple OSS Distributions immovable_test_move_send_thread_inspect(void)
247*fdd8201dSApple OSS Distributions {
248*fdd8201dSApple OSS Distributions kern_return_t kr;
249*fdd8201dSApple OSS Distributions mach_port_t port;
250*fdd8201dSApple OSS Distributions mach_port_t th_port = mach_thread_self();
251*fdd8201dSApple OSS Distributions
252*fdd8201dSApple OSS Distributions printf("[Crasher]: Move send thread inspect port\n");
253*fdd8201dSApple OSS Distributions kr = thread_get_special_port(th_port, THREAD_INSPECT_PORT, &port);
254*fdd8201dSApple OSS Distributions assert(kr == 0);
255*fdd8201dSApple OSS Distributions kr = attempt_send_immovable_port(port, MACH_MSG_TYPE_MOVE_SEND);
256*fdd8201dSApple OSS Distributions printf("[Crasher immovable_test_move_send_thread_inspect] attempt_send_immovable_port returned %s \n.", mach_error_string(kr));
257*fdd8201dSApple OSS Distributions
258*fdd8201dSApple OSS Distributions mach_port_deallocate(mach_task_self(), th_port);
259*fdd8201dSApple OSS Distributions }
260*fdd8201dSApple OSS Distributions
261*fdd8201dSApple OSS Distributions static void
immovable_test_move_send_raw_thread(void)262*fdd8201dSApple OSS Distributions immovable_test_move_send_raw_thread(void)
263*fdd8201dSApple OSS Distributions {
264*fdd8201dSApple OSS Distributions kern_return_t kr;
265*fdd8201dSApple OSS Distributions mach_port_t port;
266*fdd8201dSApple OSS Distributions
267*fdd8201dSApple OSS Distributions kr = thread_create(mach_task_self(), &port);
268*fdd8201dSApple OSS Distributions assert(kr == 0);
269*fdd8201dSApple OSS Distributions kr = mach_port_deallocate(mach_task_self(), port); /* not pinned, should not crash */
270*fdd8201dSApple OSS Distributions
271*fdd8201dSApple OSS Distributions kr = thread_create(mach_task_self(), &port);
272*fdd8201dSApple OSS Distributions assert(kr == 0);
273*fdd8201dSApple OSS Distributions kr = attempt_send_immovable_port(port, MACH_MSG_TYPE_MOVE_SEND); /* immovable, should crash here */
274*fdd8201dSApple OSS Distributions printf("[Crasher immovable_test_move_send_raw_thread] attempt_send_immovable_port returned %s \n.", mach_error_string(kr));
275*fdd8201dSApple OSS Distributions
276*fdd8201dSApple OSS Distributions kr = thread_terminate(port);
277*fdd8201dSApple OSS Distributions assert(kr == 0);
278*fdd8201dSApple OSS Distributions }
279*fdd8201dSApple OSS Distributions
280*fdd8201dSApple OSS Distributions static void
immovable_test_copy_send_thread_read(void)281*fdd8201dSApple OSS Distributions immovable_test_copy_send_thread_read(void)
282*fdd8201dSApple OSS Distributions {
283*fdd8201dSApple OSS Distributions kern_return_t kr;
284*fdd8201dSApple OSS Distributions mach_port_t port;
285*fdd8201dSApple OSS Distributions mach_port_t th_port = mach_thread_self();
286*fdd8201dSApple OSS Distributions
287*fdd8201dSApple OSS Distributions printf("[Crasher]: Copy send thread read port\n");
288*fdd8201dSApple OSS Distributions kr = thread_get_special_port(th_port, THREAD_READ_PORT, &port);
289*fdd8201dSApple OSS Distributions assert(kr == 0);
290*fdd8201dSApple OSS Distributions kr = attempt_send_immovable_port(port, MACH_MSG_TYPE_COPY_SEND);
291*fdd8201dSApple OSS Distributions printf("[Crasher immovable_test_copy_send_thread_read] attempt_send_immovable_port returned %s \n.", mach_error_string(kr));
292*fdd8201dSApple OSS Distributions
293*fdd8201dSApple OSS Distributions mach_port_deallocate(mach_task_self(), port);
294*fdd8201dSApple OSS Distributions mach_port_deallocate(mach_task_self(), th_port);
295*fdd8201dSApple OSS Distributions }
296*fdd8201dSApple OSS Distributions
297*fdd8201dSApple OSS Distributions int
main(int argc,char * argv[])298*fdd8201dSApple OSS Distributions main(int argc, char *argv[])
299*fdd8201dSApple OSS Distributions {
300*fdd8201dSApple OSS Distributions void (*tests[MAX_TEST_NUM])(void) = {
301*fdd8201dSApple OSS Distributions pinned_test_main_thread_mod_ref,
302*fdd8201dSApple OSS Distributions pinned_test_pthread_dealloc,
303*fdd8201dSApple OSS Distributions pinned_test_task_self_dealloc,
304*fdd8201dSApple OSS Distributions pinned_test_task_self_mod_ref,
305*fdd8201dSApple OSS Distributions pinned_test_task_threads_mod_ref,
306*fdd8201dSApple OSS Distributions pinned_test_mach_port_destroy,
307*fdd8201dSApple OSS Distributions pinned_test_move_send_as_remote_port,
308*fdd8201dSApple OSS Distributions
309*fdd8201dSApple OSS Distributions immovable_test_move_send_task_self,
310*fdd8201dSApple OSS Distributions immovable_test_copy_send_task_self,
311*fdd8201dSApple OSS Distributions immovable_test_move_send_thread_self,
312*fdd8201dSApple OSS Distributions immovable_test_copy_send_thread_self,
313*fdd8201dSApple OSS Distributions immovable_test_copy_send_task_read,
314*fdd8201dSApple OSS Distributions immovable_test_copy_send_task_inspect,
315*fdd8201dSApple OSS Distributions immovable_test_move_send_thread_inspect,
316*fdd8201dSApple OSS Distributions immovable_test_copy_send_thread_read,
317*fdd8201dSApple OSS Distributions immovable_test_move_send_as_remote_port,
318*fdd8201dSApple OSS Distributions immovable_test_move_send_raw_thread
319*fdd8201dSApple OSS Distributions };
320*fdd8201dSApple OSS Distributions printf("[Crasher]: My Pid: %d\n", getpid());
321*fdd8201dSApple OSS Distributions
322*fdd8201dSApple OSS Distributions if (argc < 2) {
323*fdd8201dSApple OSS Distributions printf("[Crasher]: Specify a test to run.");
324*fdd8201dSApple OSS Distributions exit(-1);
325*fdd8201dSApple OSS Distributions }
326*fdd8201dSApple OSS Distributions
327*fdd8201dSApple OSS Distributions int test_num = atoi(argv[1]);
328*fdd8201dSApple OSS Distributions
329*fdd8201dSApple OSS Distributions if (test_num >= 0 && test_num < MAX_TEST_NUM) {
330*fdd8201dSApple OSS Distributions (*tests[test_num])();
331*fdd8201dSApple OSS Distributions } else {
332*fdd8201dSApple OSS Distributions printf("[Crasher]: Invalid test num. Exiting...\n");
333*fdd8201dSApple OSS Distributions exit(-1);
334*fdd8201dSApple OSS Distributions }
335*fdd8201dSApple OSS Distributions
336*fdd8201dSApple OSS Distributions exit(0);
337*fdd8201dSApple OSS Distributions }
338