Index: /trunk/source/lisp-kernel/x86-exceptions.c
===================================================================
--- /trunk/source/lisp-kernel/x86-exceptions.c	(revision 15463)
+++ /trunk/source/lisp-kernel/x86-exceptions.c	(revision 15464)
@@ -2937,5 +2937,5 @@
 
 #define TCR_FROM_EXCEPTION_PORT(p) find_tcr_from_exception_port(p)
-#define TCR_TO_EXCEPTION_PORT(t) (mach_port_name_t)(((TCR *)t)->io_datum)
+#define TCR_TO_EXCEPTION_PORT(t) (mach_port_name_t)((natural) (((TCR *)t)->io_datum))
 
 
@@ -3263,13 +3263,28 @@
 #define DARWIN_EXCEPTION_HANDLER signal_handler
 
+#define EXCEPTION_PORT_BUCKETS 109
+
+TCR *
+exception_port_map[EXCEPTION_PORT_BUCKETS];
+
+pthread_mutex_t 
+exception_port_map_lock = PTHREAD_MUTEX_INITIALIZER;
+
 TCR *
 find_tcr_from_exception_port(mach_port_t port)
 {
-  mach_vm_address_t addr = 0;
-  kern_return_t kret;
-
-  kret = mach_port_get_context(mach_task_self(),port,&addr);
-  MACH_CHECK_ERROR("finding TCR from exception port",kret);
-  return (TCR *)((natural)addr);
+  TCR *tcr = NULL;
+  pthread_mutex_lock(&exception_port_map_lock);
+
+  tcr = exception_port_map[(unsigned)port % EXCEPTION_PORT_BUCKETS];
+
+  while (tcr) {
+    if (TCR_TO_EXCEPTION_PORT(tcr) == port) {
+      break;
+    }
+    tcr = (TCR *)tcr->pending_io_info;
+  }
+  pthread_mutex_unlock(&exception_port_map_lock);
+  return tcr;
 }
 
@@ -3277,8 +3292,10 @@
 associate_tcr_with_exception_port(mach_port_t port, TCR *tcr)
 {
-  kern_return_t kret;
-
-  kret = mach_port_set_context(mach_task_self(),port,(mach_vm_address_t)((natural)tcr));
-  MACH_CHECK_ERROR("associating TCR with exception port",kret);
+  int b = (unsigned)port % EXCEPTION_PORT_BUCKETS;
+  pthread_mutex_lock(&exception_port_map_lock);
+
+  tcr->pending_io_info = (void *)(exception_port_map[b]);
+  exception_port_map[b] = tcr;
+  pthread_mutex_unlock(&exception_port_map_lock);
 }
 
@@ -3286,4 +3303,16 @@
 disassociate_tcr_from_exception_port(mach_port_t port)
 {
+  TCR **prev = &(exception_port_map[(unsigned)port % EXCEPTION_PORT_BUCKETS]),
+    *tcr;
+  pthread_mutex_lock(&exception_port_map_lock);
+
+  while((tcr = *prev) != NULL) {
+    if (TCR_TO_EXCEPTION_PORT(tcr) == port) {
+      *prev = (TCR *)tcr->pending_io_info;
+      break;
+    }
+    prev = (TCR **)&(tcr->pending_io_info);
+  }
+  pthread_mutex_unlock(&exception_port_map_lock);
 }
   
@@ -3420,5 +3449,5 @@
 {
   extern boolean_t exc_server();
-  mach_port_t p = (mach_port_t)arg;
+  mach_port_t p = (mach_port_t)((natural)arg);
 
   mach_exception_thread = pthread_mach_thread_np(pthread_self());
