]>
Commit | Line | Data |
---|---|---|
c3c9b80d A |
1 | #include <darwintest.h> |
2 | #include <darwintest_utils.h> | |
3 | #include <errno.h> | |
4 | #include <mach/mach.h> | |
5 | #include <mach/mach_types.h> | |
6 | #include <mach/task.h> | |
7 | #include <mach/mach_error.h> | |
8 | #include <mach/task_special_ports.h> | |
9 | ||
10 | #include <signal.h> | |
11 | #include <stdio.h> | |
12 | #include <stdlib.h> | |
13 | #include <unistd.h> | |
14 | ||
15 | T_DECL(task_ident, "test task identity token") | |
16 | { | |
17 | kern_return_t kr; | |
18 | task_id_token_t token; | |
19 | mach_port_t port1, port2; | |
20 | ||
21 | kr = task_create_identity_token(mach_task_self(), &token); | |
22 | T_ASSERT_MACH_SUCCESS(kr, "task_create_identity_token()"); | |
23 | ||
24 | port1 = mach_task_self(); | |
25 | kr = task_identity_token_get_task_port(token, TASK_FLAVOR_CONTROL, &port2); /* Immovable control port for self */ | |
26 | T_ASSERT_MACH_SUCCESS(kr, "task_identity_token_get_task_port() - CONTROL"); | |
27 | T_EXPECT_EQ(port1, port2, "Control port does not match!"); | |
28 | ||
29 | mach_port_deallocate(mach_task_self(), port2); | |
30 | ||
31 | kr = task_get_special_port(mach_task_self(), TASK_READ_PORT, &port1); | |
32 | T_ASSERT_MACH_SUCCESS(kr, "task_get_special_port() - READ"); | |
33 | kr = task_identity_token_get_task_port(token, TASK_FLAVOR_READ, &port2); | |
34 | T_ASSERT_MACH_SUCCESS(kr, "task_identity_token_get_task_port() - read"); | |
35 | T_EXPECT_EQ(port1, port2, "Read port does not match!"); | |
36 | ||
37 | mach_port_deallocate(mach_task_self(), port1); | |
38 | mach_port_deallocate(mach_task_self(), port2); | |
39 | ||
40 | kr = task_get_special_port(mach_task_self(), TASK_INSPECT_PORT, &port1); | |
41 | T_ASSERT_MACH_SUCCESS(kr, "task_get_special_port() - INSPECT"); | |
42 | kr = task_identity_token_get_task_port(token, TASK_FLAVOR_INSPECT, &port2); | |
43 | T_ASSERT_MACH_SUCCESS(kr, "task_identity_token_get_task_port() - inspect"); | |
44 | T_EXPECT_EQ(port1, port2, "Inspect port does not match!"); | |
45 | ||
46 | mach_port_deallocate(mach_task_self(), port1); | |
47 | mach_port_deallocate(mach_task_self(), port2); | |
48 | ||
49 | kr = task_get_special_port(mach_task_self(), TASK_NAME_PORT, &port1); | |
50 | T_ASSERT_MACH_SUCCESS(kr, "task_get_special_port() - NAME"); | |
51 | kr = task_identity_token_get_task_port(token, TASK_FLAVOR_NAME, &port2); | |
52 | T_ASSERT_MACH_SUCCESS(kr, "task_identity_token_get_task_port() - name"); | |
53 | T_EXPECT_EQ(port1, port2, "Name port does not match!"); | |
54 | ||
55 | mach_port_deallocate(mach_task_self(), port1); | |
56 | mach_port_deallocate(mach_task_self(), port2); | |
57 | ||
58 | kr = task_identity_token_get_task_port(mach_thread_self(), TASK_FLAVOR_NAME, &port2); | |
59 | T_EXPECT_NE(kr, KERN_SUCCESS, "task_identity_token_get_task_port() should fail on non-token port"); | |
60 | ||
61 | mach_port_deallocate(mach_task_self(), token); | |
62 | } |