struct exception_action *excp,
lck_mtx_t *mutex)
{
- ipc_port_t exc_port;
+ ipc_port_t exc_port = IPC_PORT_NULL;
exception_data_type_t small_code[EXCEPTION_CODE_MAX];
int code64;
int behavior;
int flavor;
kern_return_t kr;
- int use_fast_retrieve = TRUE;
task_t task;
- ipc_port_t thread_port = NULL, task_port = NULL;
+ ipc_port_t thread_port = IPC_PORT_NULL, task_port = IPC_PORT_NULL;
/*
* Save work if we are terminating.
* to the next level.
*/
if (mac_exc_action_check_exception_send(task, excp) != 0) {
- return KERN_FAILURE;
+ kr = KERN_FAILURE;
+ goto out_release_right;
}
#endif
- if ((thread != current_thread() || exception == EXC_CORPSE_NOTIFY)
- && behavior != EXCEPTION_STATE) {
- use_fast_retrieve = FALSE;
-
- task_reference(task);
- task_port = convert_task_to_port(task);
- /* task ref consumed */
- thread_reference(thread);
- thread_port = convert_thread_to_port(thread);
- /* thread ref consumed */
+ if (behavior != EXCEPTION_STATE) {
+ if (thread != current_thread() || exception == EXC_CORPSE_NOTIFY) {
+ task_reference(task);
+ task_port = convert_task_to_port(task);
+ /* task ref consumed */
+ thread_reference(thread);
+ thread_port = convert_thread_to_port(thread);
+ /* thread ref consumed */
+ }
+ else {
+ task_port = retrieve_task_self_fast(thread->task);
+ thread_port = retrieve_thread_self_fast(thread);
+ }
}
switch (behavior) {
state, state_cnt,
state, &state_cnt);
}
- if (kr == MACH_MSG_SUCCESS && exception != EXC_CORPSE_NOTIFY)
- kr = thread_setstatus(thread, flavor,
- (thread_state_t)state,
- state_cnt);
+ if (kr == KERN_SUCCESS) {
+ if (exception != EXC_CORPSE_NOTIFY)
+ kr = thread_setstatus(thread, flavor,
+ (thread_state_t)state,
+ state_cnt);
+ goto out_release_right;
+ }
+
}
- return kr;
+ goto out_release_right;
}
case EXCEPTION_DEFAULT:
c_thr_exc_raise++;
if (code64) {
kr = mach_exception_raise(exc_port,
- use_fast_retrieve ? retrieve_thread_self_fast(thread) :
- thread_port,
- use_fast_retrieve ? retrieve_task_self_fast(thread->task) :
- task_port,
+ thread_port,
+ task_port,
exception,
code,
codeCnt);
} else {
kr = exception_raise(exc_port,
- use_fast_retrieve ? retrieve_thread_self_fast(thread) :
- thread_port,
- use_fast_retrieve ? retrieve_task_self_fast(thread->task) :
- task_port,
+ thread_port,
+ task_port,
exception,
small_code,
codeCnt);
}
- return kr;
+ goto out_release_right;
case EXCEPTION_STATE_IDENTITY: {
mach_msg_type_number_t state_cnt;
if (code64) {
kr = mach_exception_raise_state_identity(
exc_port,
- use_fast_retrieve ? retrieve_thread_self_fast(thread) :
- thread_port,
- use_fast_retrieve ? retrieve_task_self_fast(thread->task) :
- task_port,
+ thread_port,
+ task_port,
exception,
code,
codeCnt,
state, &state_cnt);
} else {
kr = exception_raise_state_identity(exc_port,
- use_fast_retrieve ? retrieve_thread_self_fast(thread) :
- thread_port,
- use_fast_retrieve ? retrieve_task_self_fast(thread->task) :
- task_port,
+ thread_port,
+ task_port,
exception,
small_code,
codeCnt,
state, state_cnt,
state, &state_cnt);
}
- if (kr == MACH_MSG_SUCCESS && exception != EXC_CORPSE_NOTIFY)
- kr = thread_setstatus(thread, flavor,
- (thread_state_t)state,
- state_cnt);
+
+ if (kr == KERN_SUCCESS) {
+ if (exception != EXC_CORPSE_NOTIFY)
+ kr = thread_setstatus(thread, flavor,
+ (thread_state_t)state,
+ state_cnt);
+ goto out_release_right;
+ }
+
}
- return kr;
+ goto out_release_right;
}
default:
panic ("bad exception behavior!");
return KERN_FAILURE;
}/* switch */
+
+out_release_right:
+
+ if (task_port) {
+ ipc_port_release_send(task_port);
+ }
+
+ if (thread_port) {
+ ipc_port_release_send(thread_port);
+ }
+
+ if (exc_port) {
+ ipc_port_release_send(exc_port);
+ }
+
+ return kr;
}
/*
*/
host_priv = host_priv_self();
mutex = &host_priv->lock;
-
+
if (KERN_SUCCESS == check_exc_receiver_dependency(exception, host_priv->exc_actions, mutex))
{
kr = exception_deliver(thread, exception, code, codeCnt, host_priv->exc_actions, mutex);