Fix a race condition when finding stack unwinding functions.

This commit is contained in:
davidxu 2010-09-19 05:19:47 +00:00
parent eebc7df64c
commit ad24f558bd

View File

@ -70,18 +70,31 @@ static void
thread_uw_init(void) thread_uw_init(void)
{ {
static int inited = 0; static int inited = 0;
Dl_info dlinfo;
void *handle; void *handle;
void *forcedunwind, *resume, *getcfa;
if (inited) if (inited)
return; return;
inited = 1;
handle = RTLD_DEFAULT; handle = RTLD_DEFAULT;
if ((uwl_forcedunwind = dlsym(handle, "_Unwind_ForcedUnwind")) == NULL|| if ((forcedunwind = dlsym(handle, "_Unwind_ForcedUnwind")) != NULL) {
(uwl_resume = dlsym(handle, "_Unwind_Resume")) == NULL || if (dladdr(forcedunwind, &dlinfo)) {
(uwl_getcfa = dlsym(handle, "_Unwind_GetCFA")) == NULL) { if ((handle = dlopen(dlinfo.dli_fname, RTLD_LAZY)) != NULL) {
uwl_forcedunwind = NULL; forcedunwind = dlsym(handle, "_Unwind_ForcedUnwind");
return; resume = dlsym(handle, "_Unwind_Resume");
getcfa = dlsym(handle, "_Unwind_GetCFA");
if (forcedunwind != NULL && resume != NULL &&
getcfa != NULL) {
uwl_forcedunwind = forcedunwind;
uwl_resume = resume;
uwl_getcfa = getcfa;
} else {
dlclose(handle);
}
}
}
} }
inited = 1;
} }
void void