Index: /trunk/source/lisp-kernel/memory.c
===================================================================
--- /trunk/source/lisp-kernel/memory.c	(revision 15460)
+++ /trunk/source/lisp-kernel/memory.c	(revision 15461)
@@ -32,5 +32,5 @@
 #include <strings.h>
 #endif
-#ifdef DARWIN64
+#ifdef DARWIN
 #include <pthread.h>
 #endif
@@ -975,5 +975,5 @@
 }
 
-#ifdef DARWIN64
+#ifdef DARWIN
 /*
   On 64-bit Darwin, we try to make a TCR's address serve as a Mach port
@@ -995,4 +995,15 @@
   doesn't conflict with a mapped region (as it seems to in practice
   since at least 10.5 and as it's documented to in 10.6.)
+
+  OSX 10.8 introduces new horrors that affect 32-bit CCL as well: 
+
+  mach_port_allocate_name(mach_task_self(),MACH_PORT_RIGHT_RECEIVE,n)
+  
+  returns KERN_NO_SPACE for n > ~#x09800000.  It's not known whether or
+  not this is intentional; even if it's a bug, it suggests that we should
+  probably stop trying to arrange that a TCR's address can be used as the
+  corresponding thread's exception port and maintain some sort of 
+  efficient and thread-safe mapping from port to TCR.  Soon.
+
 */
 
@@ -1004,5 +1015,24 @@
 but not so much that we waste lots of 32-bit memory. */
 
-#define LIMIT_32_BIT (natural)(1L<<32L)
+#define LIMIT_32_BIT (natural)(0x09800000)
+
+#undef vm_region
+
+void
+link_tcr_list(TCR *head, TCR *buf, int n)
+{
+  TCR *prev = head;
+  int i;
+
+  for (i=0; i < n; i++, buf++) {
+    prev->next = buf;
+    buf->prev = prev;
+    head->prev = buf;
+    buf->next = head;
+    prev = buf;
+  }
+}
+
+TCR initial_tcrs[TCR_CLUSTER_COUNT];
 
 void
@@ -1014,6 +1044,11 @@
   void *p;
   vm_size_t request_size = align_to_power_of_2((TCR_CLUSTER_COUNT*sizeof(TCR)),log2_page_size), vm_size;
+#if WORD_SIZE==64
   vm_region_basic_info_data_64_t vm_info;
   mach_msg_type_number_t vm_info_size = VM_REGION_BASIC_INFO_COUNT_64;
+#else
+  vm_region_basic_info_data_t vm_info;
+  mach_msg_type_number_t vm_info_size = VM_REGION_BASIC_INFO_COUNT;
+#endif
   mach_port_t vm_object_name = (mach_port_t) 0;
   kern_return_t kret;
@@ -1021,4 +1056,5 @@
   while (1) {
     nextaddr = addr;
+#if WORD_SIZE==64
     vm_info_size = VM_REGION_BASIC_INFO_COUNT_64;
     kret = vm_region_64(mach_task_self(),
@@ -1029,4 +1065,14 @@
                         &vm_info_size,
                         &vm_object_name);
+#else
+    vm_info_size = VM_REGION_BASIC_INFO_COUNT;
+    kret = vm_region(mach_task_self(),
+                     &nextaddr,
+                     &vm_size,
+                     VM_REGION_BASIC_INFO,
+                     (vm_region_info_t)&vm_info,
+                     &vm_info_size,
+                     &vm_object_name);
+#endif
     if (kret != KERN_SUCCESS) {
       break;
@@ -1062,11 +1108,5 @@
   }
   
-  for (i=0; i < TCR_CLUSTER_COUNT; i++, work++) {
-    prev->next = work;
-    work->prev = prev;
-    head->prev = work;
-    work->next = head;
-    prev = work;
-  }
+  link_tcr_list(head, work, TCR_CLUSTER_COUNT);
 }
 
@@ -1092,4 +1132,5 @@
   if (head->next == NULL) { /* First time */
     head->next = head->prev = head;
+    link_tcr_list(head,initial_tcrs,TCR_CLUSTER_COUNT);
   }
 
@@ -1102,4 +1143,5 @@
   head->next = tail;
   pthread_mutex_unlock(&darwin_tcr_lock);
+  memset(tcr,0,sizeof(TCR));
   return tcr;
 }
Index: /trunk/source/lisp-kernel/platform-darwinx8664.h
===================================================================
--- /trunk/source/lisp-kernel/platform-darwinx8664.h	(revision 15460)
+++ /trunk/source/lisp-kernel/platform-darwinx8664.h	(revision 15461)
@@ -91,3 +91,3 @@
 #include "os-darwin.h"
 
-#define DARWIN64 1
+
Index: /trunk/source/lisp-kernel/thread_manager.c
===================================================================
--- /trunk/source/lisp-kernel/thread_manager.c	(revision 15460)
+++ /trunk/source/lisp-kernel/thread_manager.c	(revision 15461)
@@ -829,5 +829,5 @@
 #ifdef DARWIN
   extern Boolean use_mach_exception_handling;
-#ifdef DARWIN64
+#ifdef DARWIN
   extern TCR* darwin_allocate_tcr(void);
   extern void darwin_free_tcr(TCR *);
@@ -839,5 +839,5 @@
 #endif
   for (;;) {
-#ifdef DARWIN64
+#ifdef DARWIN
     tcr = darwin_allocate_tcr();
 #else
@@ -862,5 +862,5 @@
     for (;chain;chain = next) {
       next = chain->next;
-#ifdef DARWIN64
+#ifdef DARWIN
       darwin_free_tcr(chain);
 #else
@@ -1363,5 +1363,5 @@
 shutdown_thread_tcr(void *arg)
 {
-#ifdef DARWIN64
+#ifdef DARWIN
   extern void darwin_free_tcr(TCR *);
 #endif
@@ -1441,5 +1441,5 @@
     tcr->interrupt_pending = 0;
     TCR_AUX(tcr)->termination_semaphore = NULL;
-#if defined(HAVE_TLS) || defined(WIN_32) || defined(DARWIN64)
+#if defined(HAVE_TLS) || defined(WIN_32) || defined(DARWIN)
     dequeue_tcr(tcr);
 #endif
@@ -1457,5 +1457,5 @@
 #endif
 #endif
-#ifdef DARWIN64
+#ifdef DARWIN
     darwin_free_tcr(tcr);
 #endif
@@ -2315,5 +2315,5 @@
 free_freed_tcrs ()
 {
-#ifdef DARWIN64
+#ifdef DARWIN
   extern void darwin_free_tcr(TCR *);
 #endif
@@ -2327,5 +2327,5 @@
      * tcr aux vector elsewhere. */
 #else
-#ifdef DARWIN64
+#ifdef DARWIN
     darwin_free_tcr(current);
 #else
