]> git.saurik.com Git - apple/xnu.git/blob - tests/mach_port_insert_right.c
xnu-4903.241.1.tar.gz
[apple/xnu.git] / tests / mach_port_insert_right.c
1 #include <stdio.h>
2 #include <mach/mach.h>
3 #include <mach/message.h>
4 #include <darwintest.h>
5
6 T_DECL(mach_port_insert_right,"insert send right for an existing right", T_META_CHECK_LEAKS(false))
7 {
8 mach_port_t port = MACH_PORT_NULL;
9 mach_port_t port2 = MACH_PORT_NULL;
10 kern_return_t retval;
11
12 mach_port_t task = mach_task_self();
13
14 retval = mach_port_allocate(task, MACH_PORT_RIGHT_RECEIVE, &port);
15 T_ASSERT_MACH_SUCCESS(retval, "allocate a port=[%d]", port);
16
17 mach_port_name_t name = 123;
18
19 retval = mach_port_insert_right(task, name, port, MACH_MSG_TYPE_MAKE_SEND);
20 T_ASSERT_MACH_ERROR(retval, KERN_FAILURE, "insert a send right for port=[%d] with name=[%d]", port, name);
21
22 name = port + 1;
23 retval = mach_port_insert_right(task, name, port, MACH_MSG_TYPE_MAKE_SEND);
24 T_ASSERT_MACH_ERROR(retval, KERN_FAILURE, "insert a send right for port=[%d] with name=[%d]", port, name);
25
26 retval = mach_port_allocate(task, MACH_PORT_RIGHT_RECEIVE, &port2);
27 T_ASSERT_MACH_SUCCESS(retval, "allocate a port=[%d]", port2);
28
29 name = port;
30 retval = mach_port_insert_right(task, name, port2, MACH_MSG_TYPE_MAKE_SEND);
31 T_ASSERT_MACH_ERROR(retval, KERN_RIGHT_EXISTS, "insert a send right for port=[%d] with name=[%d]", port2, name);
32 }