#include <excserver.h>
+T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
+
static dispatch_semaphore_t sync_sema;
kern_return_t
catch_mach_exception_raise(mach_port_t exception_port,
- mach_port_t thread,
- mach_port_t task,
- exception_type_t exception,
- mach_exception_data_t code,
- mach_msg_type_number_t code_count)
+ mach_port_t thread,
+ mach_port_t task,
+ exception_type_t exception,
+ mach_exception_data_t code,
+ mach_msg_type_number_t code_count)
{
#pragma unused(exception_port, thread, task, code, code_count)
pid_t pid;
kern_return_t
catch_mach_exception_raise_state(mach_port_t exception_port,
- exception_type_t exception,
- const mach_exception_data_t code,
- mach_msg_type_number_t code_count,
- int * flavor,
- const thread_state_t old_state,
- mach_msg_type_number_t old_state_count,
- thread_state_t new_state,
- mach_msg_type_number_t * new_state_count)
+ exception_type_t exception,
+ const mach_exception_data_t code,
+ mach_msg_type_number_t code_count,
+ int * flavor,
+ const thread_state_t old_state,
+ mach_msg_type_number_t old_state_count,
+ thread_state_t new_state,
+ mach_msg_type_number_t * new_state_count)
{
#pragma unused(exception_port, exception, code, code_count, flavor, old_state, old_state_count, new_state, new_state_count)
T_FAIL("Unsupported catch_mach_exception_raise_state");
kern_return_t
catch_mach_exception_raise_state_identity(mach_port_t exception_port,
- mach_port_t thread,
- mach_port_t task,
- exception_type_t exception,
- mach_exception_data_t code,
- mach_msg_type_number_t code_count,
- int * flavor,
- thread_state_t old_state,
- mach_msg_type_number_t old_state_count,
- thread_state_t new_state,
- mach_msg_type_number_t * new_state_count)
+ mach_port_t thread,
+ mach_port_t task,
+ exception_type_t exception,
+ mach_exception_data_t code,
+ mach_msg_type_number_t code_count,
+ int * flavor,
+ thread_state_t old_state,
+ mach_msg_type_number_t old_state_count,
+ thread_state_t new_state,
+ mach_msg_type_number_t * new_state_count)
{
#pragma unused(exception_port, thread, task, exception, code, code_count, flavor, old_state, old_state_count, new_state, new_state_count)
T_FAIL("Unsupported catch_mach_exception_raise_state_identity");
mach_port_t exception_port;
kret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &exception_port);
- if (kret != KERN_SUCCESS)
+ if (kret != KERN_SUCCESS) {
T_FAIL("mach_port_allocate: %s (%d)", mach_error_string(kret), kret);
+ }
kret = mach_port_insert_right(mach_task_self(), exception_port, exception_port, MACH_MSG_TYPE_MAKE_SEND);
- if (kret != KERN_SUCCESS)
+ if (kret != KERN_SUCCESS) {
T_FAIL("mach_port_insert_right: %s (%d)", mach_error_string(kret), kret);
+ }
kret = task_set_exception_ports(mach_task_self(), EXC_MASK_CRASH | EXC_MASK_CORPSE_NOTIFY, exception_port,
- (exception_behavior_t)(EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES), 0);
- if (kret != KERN_SUCCESS)
+ (exception_behavior_t)(EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES), 0);
+ if (kret != KERN_SUCCESS) {
T_FAIL("task_set_exception_ports: %s (%d)", mach_error_string(kret), kret);
+ }
dispatch_semaphore_signal(sync_sema);
kret = mach_msg_server(mach_exc_server, MACH_MSG_SIZE_RELIABLE, exception_port, 0);
- if (kret != KERN_SUCCESS)
+ if (kret != KERN_SUCCESS) {
T_FAIL("mach_msg_server: %s (%d)", mach_error_string(kret), kret);
+ }
return NULL;
}
static void*
-dummy_thread(void *arg) {
+dummy_thread(void *arg)
+{
#pragma unused(arg)
while (1) {
sleep(60);
size_t enabled_size = sizeof(enabled);
err = sysctlbyname("kern.exc_resource_threads_enabled", &enabled, &enabled_size, NULL, 0);
- if (err || !enabled)
+ if (err || !enabled) {
T_SKIP("EXC_RESOURCE RESOURCE_TYPE_THREADS not enabled on this system");
-
+ }
}
T_DECL(exc_resource_threads, "Ensures that a process with a thread_limit set will receive an exc_resource when it crosses its thread limit",
- T_META_ASROOT(true),
- T_META_CHECK_LEAKS(false))
+ T_META_ASROOT(true),
+ T_META_CHECK_LEAKS(false))
{
pthread_t handle_thread;