]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: give proper messages when user defined DYLD_INSERT_LIBRARIES on Darwin
authorShenghou Ma <minux.ma@gmail.com>
Mon, 30 Apr 2012 19:55:07 +0000 (15:55 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 30 Apr 2012 19:55:07 +0000 (15:55 -0400)
       also gives clear error when bsdthread_register fails on Darwin
       Fixes #2992.

R=rsc, krautz
CC=golang-dev
https://golang.org/cl/5966067

src/pkg/runtime/os_darwin.h
src/pkg/runtime/sys_darwin_386.s
src/pkg/runtime/sys_darwin_amd64.s
src/pkg/runtime/thread_darwin.c

index eb5d2daa3867ef5d8151da51594bc2eaad5072f8..70cfcce8467a75f8f1767c3abcde9a08d2ff55ee 100644 (file)
@@ -6,7 +6,7 @@
 #define SIG_IGN ((void*)1)
 
 int32  runtime·bsdthread_create(void*, M*, G*, void(*)(void));
-void   runtime·bsdthread_register(void);
+int32  runtime·bsdthread_register(void);
 int32  runtime·mach_msg_trap(MachHeader*, int32, uint32, uint32, uint32, uint32, uint32);
 uint32 runtime·mach_reply_port(void);
 int32  runtime·mach_semacquire(uint32, int64);
index 3cf3506adffa864f68263cb80d4d0ac91e8ac557..5dd4d59cf68bef794832ea5da7435f0f80b4a23d 100644 (file)
@@ -268,8 +268,10 @@ TEXT runtime·bsdthread_register(SB),7,$40
        MOVL    $0, 20(SP)      // targetconc_ptr
        MOVL    $0, 24(SP)      // dispatchqueue_offset
        INT     $0x80
-       JAE     2(PC)
-       MOVL    $0xf1, 0xf1  // crash
+       JAE     3(PC)
+       NEGL    AX
+       RET
+       MOVL    $0, AX
        RET
 
 // Invoke Mach system call.
index 90571baae46d04e73a431b962d8dcb86f0474c31..09a80c96d99f1ef4522d9098a5562869f643c151 100644 (file)
@@ -265,8 +265,10 @@ TEXT runtime·bsdthread_register(SB),7,$0
        MOVQ    $0, R9  // dispatchqueue_offset
        MOVQ    $(0x2000000+366), AX    // bsdthread_register
        SYSCALL
-       JCC 2(PC)
-       MOVL    $0xf1, 0xf1  // crash
+       JCC 3(PC)
+       NEGL    AX
+       RET
+       MOVL    $0, AX
        RET
 
 // Mach system calls use 0x1000000 instead of the BSD's 0x2000000.
index 6a83e48a330e846e771df56ae5559a15e3450c86..a0fb5272f7c4073af60defc05d33461f13b5e919 100644 (file)
@@ -50,11 +50,8 @@ runtime·semacreate(void)
 void
 runtime·osinit(void)
 {
-       // Register our thread-creation callback (see sys_darwin_{amd64,386}.s)
-       // but only if we're not using cgo.  If we are using cgo we need
-       // to let the C pthread libary install its own thread-creation callback.
-       if(!runtime·iscgo)
-               runtime·bsdthread_register();
+       // bsdthread_register delayed until end of goenvs so that we
+       // can look at the environment first.
 
        // Use sysctl to fetch hw.ncpu.
        uint32 mib[2];
@@ -75,6 +72,18 @@ void
 runtime·goenvs(void)
 {
        runtime·goenvs_unix();
+
+       // Register our thread-creation callback (see sys_darwin_{amd64,386}.s)
+       // but only if we're not using cgo.  If we are using cgo we need
+       // to let the C pthread libary install its own thread-creation callback.
+       if(!runtime·iscgo) {
+               if(runtime·bsdthread_register() != 0) {
+                       if(runtime·getenv("DYLD_INSERT_LIBRARIES"))
+                               runtime·throw("runtime: bsdthread_register error (unset DYLD_INSERT_LIBRARIES)");
+                       runtime·throw("runtime: bsdthread_register error");
+               }
+       }
+
 }
 
 void