/*
- * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
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
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);
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 */;
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);
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.
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;
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) {
/*
ut->uu_subcode = code[1];
threadsignal(th_act, ux_signal, code[0]);
}
-
+ if (p != NULL)
+ proc_rele(p);
thread_deallocate(th_act);
}
else
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);
}