Fix the build on OS X 10.8.0
authorPaul Khuong <pvk@pvk.ca>
Sat, 20 Apr 2013 11:43:00 +0000 (13:43 +0200)
committerPaul Khuong <pvk@pvk.ca>
Sat, 20 Apr 2013 11:58:13 +0000 (13:58 +0200)
It seems our exception handler can be called before it's fully set up.
Handle that case without potentially leaking too many ports.

Reported by Gabriel Dos Reis on sbcl-devel.

NEWS
src/runtime/x86-64-darwin-os.c
src/runtime/x86-darwin-os.c

diff --git a/NEWS b/NEWS
index a4a0305..c2cf5f2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 ;;;; -*- coding: utf-8; fill-column: 78 -*-
 changes relative to sbcl-1.1.6
+  * bug fix: our mach exception handler can seemingly called very early in
+    the program execution process on OS X 10.8.0. Try and handle that case
+    robustly, without potentially leaking mach ports too much.
   * enhancement: TRACE :PRINT-ALL handles multiple-valued forms.
     (lp#457053)
   * bug fix: :allocation slot option works for condition slots
index 6378d7b..3c06b56 100644 (file)
@@ -574,6 +574,9 @@ catch_exception_raise(mach_port_t exception_port,
         ret = KERN_INVALID_RIGHT;
     }
 
+    if (current_mach_task == MACH_PORT_NULL)
+        current_mach_task = mach_task_self();
+
     dealloc_ret = mach_port_deallocate (current_mach_task, thread);
     if (dealloc_ret) {
       lose("mach_port_deallocate (thread) failed with return_code %d\n", dealloc_ret);
index 8489322..bf127b6 100644 (file)
@@ -504,6 +504,9 @@ catch_exception_raise(mach_port_t exception_port,
       call_handler_on_thread(thread, &thread_state, signal, &siginfo, handler);
     }
 
+    if (current_mach_task == MACH_PORT_NULL)
+        current_mach_task = mach_task_self();
+
     dealloc_ret = mach_port_deallocate (current_mach_task, thread);
     if (dealloc_ret) {
       lose("mach_port_deallocate (thread) failed with return_code %d\n", dealloc_ret);