1 #include <darwintest.h>
2 #include <pthread/private.h>
3 #include <sys/sysctl.h>
4 #include "exc_helpers.h"
7 T_META_NAMESPACE("xnu.ipc"),
8 T_META_RUN_CONCURRENTLY(true));
11 exc_immovable_handler(
14 __unused exception_type_t type
,
15 __unused mach_exception_data_t codes
)
17 T_EXPECT_EQ(task
, mach_task_self(), "Received immovable task port");
18 T_EXPECT_EQ(thread
, pthread_mach_thread_np(pthread_main_thread_np()),
19 "Received immovable thread port");
23 T_DECL(exc_immovable
, "Test that exceptions receive immovable ports")
25 mach_port_t exc_port
= create_exception_port(EXC_MASK_BAD_ACCESS
);
27 size_t size
= sizeof(&opts
);
31 T_LOG("Check if task_exc_guard exception has been enabled\n");
32 int ret
= sysctlbyname("kern.ipc_control_port_options", &opts
, &size
, NULL
, 0);
33 T_EXPECT_POSIX_SUCCESS(ret
, "sysctlbyname(kern.ipc_control_port_options)");
35 if ((opts
& 0x30) == 0) {
36 T_SKIP("immovable rights aren't enabled");
39 kr
= task_get_special_port(mach_task_self(), TASK_KERNEL_PORT
, &mp
);
40 T_EXPECT_MACH_SUCCESS(kr
, "task_get_special_port");
41 T_EXPECT_NE(mp
, mach_task_self(), "should receive movable port");
44 * do not deallocate the port we received on purpose to check
45 * that the exception will not coalesce with the movable port
46 * we have in our space now
49 run_exception_handler(exc_port
, exc_immovable_handler
);
50 *(void *volatile*)0 = 0;