]>
Commit | Line | Data |
---|---|---|
d9a64523 A |
1 | #include <stdio.h> |
2 | #include <mach/mach.h> | |
3 | #include <mach/message.h> | |
4 | #include <darwintest.h> | |
5 | ||
cb323159 A |
6 | T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true)); |
7 | ||
8 | static inline mach_port_type_t | |
9 | get_port_type(mach_port_t mp) | |
10 | { | |
11 | mach_port_type_t type; | |
12 | T_QUIET; | |
13 | T_ASSERT_MACH_SUCCESS(mach_port_type(mach_task_self(), mp, &type), | |
14 | "mach_port_type(mP)"); | |
15 | return type; | |
16 | } | |
17 | ||
0a7de745 | 18 | T_DECL(mach_port_insert_right, "insert send right for an existing right", T_META_CHECK_LEAKS(false)) |
d9a64523 A |
19 | { |
20 | mach_port_t port = MACH_PORT_NULL; | |
21 | mach_port_t port2 = MACH_PORT_NULL; | |
22 | kern_return_t retval; | |
23 | ||
24 | mach_port_t task = mach_task_self(); | |
25 | ||
26 | retval = mach_port_allocate(task, MACH_PORT_RIGHT_RECEIVE, &port); | |
27 | T_ASSERT_MACH_SUCCESS(retval, "allocate a port=[%d]", port); | |
28 | ||
cb323159 A |
29 | T_ASSERT_EQ(get_port_type(port), MACH_PORT_TYPE_RECEIVE, |
30 | "0x%x should be a receive right", port); | |
31 | ||
32 | retval = mach_port_insert_right(task, port, port, MACH_MSG_TYPE_MAKE_SEND); | |
33 | T_ASSERT_MACH_SUCCESS(retval, "insert a send right for port=[%d] with name=[%d]", port, port); | |
34 | T_ASSERT_EQ(get_port_type(port), MACH_PORT_TYPE_RECEIVE | MACH_PORT_TYPE_SEND, | |
35 | "0x%x should be a send-receive right", port); | |
36 | ||
d9a64523 A |
37 | mach_port_name_t name = 123; |
38 | ||
39 | retval = mach_port_insert_right(task, name, port, MACH_MSG_TYPE_MAKE_SEND); | |
40 | T_ASSERT_MACH_ERROR(retval, KERN_FAILURE, "insert a send right for port=[%d] with name=[%d]", port, name); | |
41 | ||
42 | name = port + 1; | |
43 | retval = mach_port_insert_right(task, name, port, MACH_MSG_TYPE_MAKE_SEND); | |
44 | T_ASSERT_MACH_ERROR(retval, KERN_FAILURE, "insert a send right for port=[%d] with name=[%d]", port, name); | |
45 | ||
46 | retval = mach_port_allocate(task, MACH_PORT_RIGHT_RECEIVE, &port2); | |
47 | T_ASSERT_MACH_SUCCESS(retval, "allocate a port=[%d]", port2); | |
48 | ||
cb323159 A |
49 | T_ASSERT_EQ(get_port_type(port2), MACH_PORT_TYPE_RECEIVE, |
50 | "0x%x should be a receive right", port2); | |
51 | ||
d9a64523 A |
52 | name = port; |
53 | retval = mach_port_insert_right(task, name, port2, MACH_MSG_TYPE_MAKE_SEND); | |
54 | T_ASSERT_MACH_ERROR(retval, KERN_RIGHT_EXISTS, "insert a send right for port=[%d] with name=[%d]", port2, name); | |
55 | } |