X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/cf7d32b81c573a0536dc4da4157f9c26f8d0bed3..8a3053a07cee346dca737a5670e546fd26a7c9d6:/bsd/uxkern/ux_exception.c diff --git a/bsd/uxkern/ux_exception.c b/bsd/uxkern/ux_exception.c index e63b6f3ba..3175c3163 100644 --- a/bsd/uxkern/ux_exception.c +++ b/bsd/uxkern/ux_exception.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2008 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -90,7 +90,12 @@ static void ux_exception(int exception, mach_exception_code_t code, mach_exception_subcode_t subcode, int *ux_signal, mach_exception_code_t *ux_code); +#if defined(__x86_64__) +mach_port_t ux_exception_port; +#else mach_port_name_t ux_exception_port; +#endif /* __x86_64__ */ + static task_t ux_handler_self; static @@ -155,7 +160,7 @@ ux_handler(void) mach_port_name_t reply_port; kern_return_t result; - exc_msg.Head.msgh_local_port = (mach_port_t)exc_set_name; + exc_msg.Head.msgh_local_port = CAST_MACH_NAME_TO_PORT(exc_set_name); exc_msg.Head.msgh_size = sizeof (exc_msg); #if 0 result = mach_msg_receive(&exc_msg.Head); @@ -166,14 +171,15 @@ ux_handler(void) 0); #endif if (result == MACH_MSG_SUCCESS) { - reply_port = (mach_port_name_t)exc_msg.Head.msgh_remote_port; + reply_port = CAST_MACH_PORT_TO_NAME(exc_msg.Head.msgh_remote_port); - if (mach_exc_server(&exc_msg.Head, &rep_msg.Head)) - (void) mach_msg_send(&rep_msg.Head, MACH_SEND_MSG, + if (mach_exc_server(&exc_msg.Head, &rep_msg.Head)) { + result = mach_msg_send(&rep_msg.Head, MACH_SEND_MSG, sizeof (rep_msg),MACH_MSG_TIMEOUT_NONE,MACH_PORT_NULL); + if (reply_port != 0 && result != MACH_MSG_SUCCESS) + mach_port_deallocate(get_task_ipcspace(ux_handler_self), reply_port); + } - if (reply_port != MACH_PORT_NULL) - (void) mach_port_deallocate(get_task_ipcspace(ux_handler_self), reply_port); } else if (result == MACH_RCV_TOO_LARGE) /* ignore oversized messages */; @@ -185,8 +191,11 @@ ux_handler(void) void ux_handler_init(void) { + thread_t thread = THREAD_NULL; + ux_exception_port = MACH_PORT_NULL; - (void) kernel_thread(kernel_task, ux_handler); + (void) kernel_thread_start((thread_continue_t)ux_handler, NULL, &thread); + thread_deallocate(thread); proc_list_lock(); if (ux_exception_port == MACH_PORT_NULL) { (void)msleep(&ux_exception_port, proc_list_mlock, 0, "ux_handler_wait", 0); @@ -230,14 +239,13 @@ catch_mach_exception_raise( task_t self = current_task(); thread_t th_act; ipc_port_t thread_port; - struct task *sig_task; struct proc *p; kern_return_t result = MACH_MSG_SUCCESS; int ux_signal = 0; mach_exception_code_t ucode = 0; struct uthread *ut; - mach_port_name_t thread_name = (mach_port_name_t)thread; /* XXX */ - mach_port_name_t task_name = (mach_port_name_t)task; /* XXX */ + mach_port_name_t thread_name = CAST_MACH_PORT_TO_NAME(thread); + mach_port_name_t task_name = CAST_MACH_PORT_TO_NAME(task); /* * Convert local thread name to global port. @@ -264,10 +272,9 @@ catch_mach_exception_raise( ux_exception(exception, code[0], code[1], &ux_signal, &ucode); ut = get_bsdthread_info(th_act); - sig_task = get_threadtask(th_act); - p = (struct proc *) get_bsdtask_info(sig_task); + p = proc_findthread(th_act); - /* Can't deliver a signal without a bsd process */ + /* Can't deliver a signal without a bsd process reference */ if (p == NULL) { ux_signal = 0; result = KERN_FAILURE; @@ -289,15 +296,9 @@ catch_mach_exception_raise( struct sigacts *ps; sp = code[1]; - if (ut && (ut->uu_flag & UT_VFORK)) - p = ut->uu_proc; -#if STACK_GROWTH_UP - stack_min = p->user_stack; - stack_max = p->user_stack + MAXSSIZ; -#else /* STACK_GROWTH_UP */ + stack_max = p->user_stack; stack_min = p->user_stack - MAXSSIZ; -#endif /* STACK_GROWTH_UP */ if (sp >= stack_min && sp < stack_max) { /* @@ -335,7 +336,8 @@ catch_mach_exception_raise( ut->uu_subcode = code[1]; threadsignal(th_act, ux_signal, code[0]); } - + if (p != NULL) + proc_rele(p); thread_deallocate(th_act); } else @@ -345,10 +347,9 @@ catch_mach_exception_raise( result = KERN_INVALID_ARGUMENT; /* - * Delete our send rights to the task and thread ports. + * Delete our send rights to the task port. */ (void)mach_port_deallocate(get_task_ipcspace(ux_handler_self), task_name); - (void)mach_port_deallocate(get_task_ipcspace(ux_handler_self), thread_name); return (result); }