]>
Commit | Line | Data |
---|---|---|
5ba3f43e A |
1 | #ifdef T_NAMESPACE |
2 | #undef T_NAMESPACE | |
3 | #endif | |
4 | #define T_NAMESPACE "xnu.ipc" | |
5 | #include <darwintest.h> | |
6 | #include <mach/mach.h> | |
7 | #include <stdlib.h> | |
8 | #include <stdio.h> | |
9 | ||
cb323159 | 10 | T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true)); |
5ba3f43e A |
11 | |
12 | T_DECL(mach_port_mod_refs, "mach_port_mod_refs"){ | |
13 | mach_port_t port_set; | |
14 | mach_port_t port; | |
15 | int ret; | |
16 | ||
17 | ret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_PORT_SET, &port_set); | |
18 | T_ASSERT_MACH_SUCCESS(ret, "mach_port_allocate MACH_PORT_RIGHT_PORT_SET"); | |
19 | ||
20 | ret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port); | |
21 | T_ASSERT_MACH_SUCCESS(ret, "mach_port_allocate MACH_PORT_RIGHT_RECEIVE"); | |
22 | ||
23 | ||
24 | /* | |
25 | * Test all known variants of port rights on each type of port | |
26 | */ | |
27 | ||
28 | /* can't subtract a send right if it doesn't exist */ | |
29 | ret = mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_SEND, -1); | |
30 | T_ASSERT_EQ(ret, KERN_INVALID_RIGHT, "mach_port_mod_refs SEND: -1 on a RECV right"); | |
31 | ||
32 | /* can't subtract a send once right if it doesn't exist */ | |
33 | ret = mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_SEND_ONCE, -1); | |
34 | T_ASSERT_EQ(ret, KERN_INVALID_RIGHT, "mach_port_mod_refs SEND_ONCE: -1 on a RECV right"); | |
35 | ||
36 | /* can't subtract a PORT SET right if it's not a port set */ | |
37 | ret = mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_PORT_SET, -1); | |
38 | T_ASSERT_EQ(ret, KERN_INVALID_RIGHT, "mach_port_mod_refs PORT_SET: -1 on a RECV right"); | |
39 | ||
40 | /* can't subtract a dead name right if it doesn't exist */ | |
41 | ret = mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_DEAD_NAME, -1); | |
42 | T_ASSERT_EQ(ret, KERN_INVALID_RIGHT, "mach_port_mod_refs DEAD_NAME: -1 on a RECV right"); | |
43 | ||
44 | /* can't subtract a LABELH right if it doesn't exist */ | |
45 | ret = mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_LABELH, -1); | |
46 | T_ASSERT_EQ(ret, KERN_INVALID_RIGHT, "mach_port_mod_refs LABELH: -1 on a RECV right"); | |
47 | ||
48 | /* can't subtract an invalid right-type */ | |
49 | ret = mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_NUMBER, -1); | |
50 | T_ASSERT_EQ(ret, KERN_INVALID_VALUE, "mach_port_mod_refs NUMBER: -1 on a RECV right"); | |
51 | ||
52 | /* can't subtract an invalid right-type */ | |
53 | ret = mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_NUMBER + 1, -1); | |
54 | T_ASSERT_EQ(ret, KERN_INVALID_VALUE, "mach_port_mod_refs NUMBER+1: -1 on a RECV right"); | |
55 | ||
56 | ||
57 | /* can't subtract a send right if it doesn't exist */ | |
58 | ret = mach_port_mod_refs(mach_task_self(), port_set, MACH_PORT_RIGHT_SEND, -1); | |
59 | T_ASSERT_EQ(ret, KERN_INVALID_RIGHT, "mach_port_mod_refs SEND: -1 on a PORT_SET right"); | |
60 | ||
61 | /* can't subtract a send once right if it doesn't exist */ | |
62 | ret = mach_port_mod_refs(mach_task_self(), port_set, MACH_PORT_RIGHT_SEND_ONCE, -1); | |
63 | T_ASSERT_EQ(ret, KERN_INVALID_RIGHT, "mach_port_mod_refs SEND_ONCE: -1 on a PORT_SET right"); | |
64 | ||
65 | /* can't subtract a receive right if it's a port set */ | |
66 | ret = mach_port_mod_refs(mach_task_self(), port_set, MACH_PORT_RIGHT_RECEIVE, -1); | |
67 | T_ASSERT_EQ(ret, KERN_INVALID_RIGHT, "mach_port_mod_refs RECV: -1 on a PORT_SET right"); | |
68 | ||
69 | /* can't subtract a dead name right if it doesn't exist */ | |
70 | ret = mach_port_mod_refs(mach_task_self(), port_set, MACH_PORT_RIGHT_DEAD_NAME, -1); | |
71 | T_ASSERT_EQ(ret, KERN_INVALID_RIGHT, "mach_port_mod_refs DEAD_NAME: -1 on a PORT_SET right"); | |
72 | ||
73 | /* can't subtract a LABELH right if it doesn't exist */ | |
74 | ret = mach_port_mod_refs(mach_task_self(), port_set, MACH_PORT_RIGHT_LABELH, -1); | |
75 | T_ASSERT_EQ(ret, KERN_INVALID_RIGHT, "mach_port_mod_refs LABELH: -1 on a PORT_SET right"); | |
76 | ||
77 | /* can't subtract an invalid right-type */ | |
78 | ret = mach_port_mod_refs(mach_task_self(), port_set, MACH_PORT_RIGHT_NUMBER, -1); | |
79 | T_ASSERT_EQ(ret, KERN_INVALID_VALUE, "mach_port_mod_refs NUMBER: -1 on a PORT_SET right"); | |
80 | ||
81 | /* can't subtract an invalid right-type */ | |
82 | ret = mach_port_mod_refs(mach_task_self(), port_set, MACH_PORT_RIGHT_NUMBER + 1, -1); | |
83 | T_ASSERT_EQ(ret, KERN_INVALID_VALUE, "mach_port_mod_refs NUMBER+1: -1 on a PORT_SET right"); | |
84 | ||
85 | /* | |
86 | * deallocate the ports/sets | |
87 | */ | |
0a7de745 | 88 | ret = mach_port_mod_refs(mach_task_self(), port_set, MACH_PORT_RIGHT_PORT_SET, -1); |
5ba3f43e A |
89 | T_ASSERT_MACH_SUCCESS(ret, "mach_port_mod_refs(PORT_SET, -1)"); |
90 | ||
0a7de745 | 91 | ret = mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_RECEIVE, -1); |
5ba3f43e A |
92 | T_ASSERT_MACH_SUCCESS(ret, "mach_port_mod_refs(RECV_RIGHT, -1)"); |
93 | } |