1 #include <darwintest.h>
2 #include <pthread/private.h>
3 #include <sys/sysctl.h>
4 #include <mach/task.h>
5 #include "exc_helpers.h"
6
7 #define EXCEPTION_IDENTITY_PROTECTED 4
8
9 T_GLOBAL_META(
10 T_META_NAMESPACE("xnu.ipc"),
11 T_META_RADAR_COMPONENT_NAME("xnu"),
12 T_META_RADAR_COMPONENT_VERSION("IPC"),
13 T_META_RUN_CONCURRENTLY(true));
14
15 static size_t
exc_handler_identity_protected(task_id_token_t token,uint64_t thread_id,exception_type_t type,__unused exception_data_t codes)16 exc_handler_identity_protected(
17 task_id_token_t token,
18 uint64_t thread_id,
19 exception_type_t type,
20 __unused exception_data_t codes)
21 {
22 mach_port_t port1, port2;
23 kern_return_t kr;
24
25 T_LOG("Got protected exception!");
26
27 port1 = mach_task_self();
28 kr = task_identity_token_get_task_port(token, TASK_FLAVOR_CONTROL, &port2); /* Immovable control port for self */
29 T_ASSERT_MACH_SUCCESS(kr, "task_identity_token_get_task_port() - CONTROL");
30 T_EXPECT_EQ(port1, port2, "Control port matches!");
31
32 T_END;
33 }
34
35 T_DECL(exc_raise_identity_protected, "Test identity-protected exception delivery behavior",
36 T_META_TAG_VM_NOT_PREFERRED)
37 {
38 mach_port_t exc_port = create_exception_port_behavior64(EXC_MASK_BAD_ACCESS, EXCEPTION_IDENTITY_PROTECTED);
39
40 run_exception_handler_behavior64(exc_port, NULL, exc_handler_identity_protected, EXCEPTION_IDENTITY_PROTECTED, true);
41 *(void *volatile*)0 = 0;
42 }
43