runtime: give proper messages when user defined DYLD_INSERT_LIBRARIES on Darwin

also gives clear error when bsdthread_register fails on Darwin
       Fixes #2992.

R=rsc, krautz
CC=golang-dev
https://golang.org/cl/5966067
This commit is contained in:
Shenghou Ma 2012-04-30 15:55:07 -04:00 committed by Russ Cox
parent 1bdb788b2e
commit 44fd1d1a6a
4 changed files with 23 additions and 10 deletions

View File

@ -6,7 +6,7 @@
#define SIG_IGN ((void*)1) #define SIG_IGN ((void*)1)
int32 runtime·bsdthread_create(void*, M*, G*, void(*)(void)); 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); int32 runtime·mach_msg_trap(MachHeader*, int32, uint32, uint32, uint32, uint32, uint32);
uint32 runtime·mach_reply_port(void); uint32 runtime·mach_reply_port(void);
int32 runtime·mach_semacquire(uint32, int64); int32 runtime·mach_semacquire(uint32, int64);

View File

@ -268,8 +268,10 @@ TEXT runtime·bsdthread_register(SB),7,$40
MOVL $0, 20(SP) // targetconc_ptr MOVL $0, 20(SP) // targetconc_ptr
MOVL $0, 24(SP) // dispatchqueue_offset MOVL $0, 24(SP) // dispatchqueue_offset
INT $0x80 INT $0x80
JAE 2(PC) JAE 3(PC)
MOVL $0xf1, 0xf1 // crash NEGL AX
RET
MOVL $0, AX
RET RET
// Invoke Mach system call. // Invoke Mach system call.

View File

@ -265,8 +265,10 @@ TEXT runtime·bsdthread_register(SB),7,$0
MOVQ $0, R9 // dispatchqueue_offset MOVQ $0, R9 // dispatchqueue_offset
MOVQ $(0x2000000+366), AX // bsdthread_register MOVQ $(0x2000000+366), AX // bsdthread_register
SYSCALL SYSCALL
JCC 2(PC) JCC 3(PC)
MOVL $0xf1, 0xf1 // crash NEGL AX
RET
MOVL $0, AX
RET RET
// Mach system calls use 0x1000000 instead of the BSD's 0x2000000. // Mach system calls use 0x1000000 instead of the BSD's 0x2000000.

View File

@ -50,11 +50,8 @@ runtime·semacreate(void)
void void
runtime·osinit(void) runtime·osinit(void)
{ {
// Register our thread-creation callback (see sys_darwin_{amd64,386}.s) // bsdthread_register delayed until end of goenvs so that we
// but only if we're not using cgo. If we are using cgo we need // can look at the environment first.
// to let the C pthread libary install its own thread-creation callback.
if(!runtime·iscgo)
runtime·bsdthread_register();
// Use sysctl to fetch hw.ncpu. // Use sysctl to fetch hw.ncpu.
uint32 mib[2]; uint32 mib[2];
@ -75,6 +72,18 @@ void
runtime·goenvs(void) runtime·goenvs(void)
{ {
runtime·goenvs_unix(); 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 void