提交 bf0df2a6 编写于 作者: D dhy308

fixed 1129a091 from https://gitee.com/dhy308/third_party_musl/pulls/709

Adjust the lock sequence in the dlopen process.
Issue: I6396D
Test: libc-test pass
Signed-off-by: Ndhy308 <tony.gan@huawei.com>
上级 e8a349a1
......@@ -2918,8 +2918,37 @@ static void prepare_lazy(struct dso *p)
lazy_head = p;
}
static void *dlopen_post(struct dso* p, int mode) {
if (p == NULL) {
return p;
}
p->nr_dlopen++;
if (p->bfs_built) {
for (int i = 0; p->deps[i]; i++) {
p->deps[i]->nr_dlopen++;
if (mode & RTLD_NODELETE) {
p->deps[i]->flags |= DSO_FLAGS_NODELETE;
}
}
}
#ifdef HANDLE_RANDOMIZATION
void *handle = assign_valid_handle(p);
if (handle == NULL) {
LD_LOGE("dlopen_post: generate random handle failed");
do_dlclose(p);
}
return handle;
#endif
return p;
}
/* add namespace function */
static void *dlopen_impl_orig(
static void *dlopen_impl(
const char *file, int mode, const char *namespace, const void *caller_addr, const dl_extinfo *extinfo)
{
struct dso *volatile p, *orig_tail, *orig_syms_tail, *orig_lazy_head, *next;
......@@ -2941,8 +2970,8 @@ static void *dlopen_impl_orig(
#endif
if (!file) {
LD_LOGD("dlopen_impl_orig file is null, return head.");
return head;
LD_LOGD("dlopen_impl file is null, return head.");
return dlopen_post(head, mode);
}
if (extinfo) {
......@@ -3033,16 +3062,16 @@ static void *dlopen_impl_orig(
#ifdef LOAD_ORDER_RANDOMIZATION
tasks = create_loadtasks();
if (!tasks) {
LD_LOGE("dlopen_impl_orig create loadtasks failed");
LD_LOGE("dlopen_impl create loadtasks failed");
goto end;
}
task = create_loadtask(file, head, ns, true);
if (!task) {
LD_LOGE("dlopen_impl_orig create loadtask failed");
LD_LOGE("dlopen_impl create loadtask failed");
goto end;
}
if (!load_library_header(task)) {
LD_LOGE("dlopen_impl_orig load library header failed for %{public}s", task->name);
LD_LOGE("dlopen_impl load library header failed for %{public}s", task->name);
goto end;
}
if (reserved_address) {
......@@ -3050,7 +3079,7 @@ static void *dlopen_impl_orig(
}
}
if (!task->p) {
LD_LOGE("dlopen_impl_orig load library failed for %{public}s", task->name);
LD_LOGE("dlopen_impl load library failed for %{public}s", task->name);
error(noload ?
"Library %s is not already loaded" :
"Error loading shared library %s: %m",
......@@ -3130,6 +3159,8 @@ static void *dlopen_impl_orig(
if (tls_cnt != orig_tls_cnt)
install_new_tls();
orig_tail = tail;
p = dlopen_post(p, mode);
end:
debug.state = RT_CONSISTENT;
_dl_debug_state();
......@@ -3150,42 +3181,6 @@ end:
return p;
}
static void *dlopen_impl(
const char *file, int mode, const char *namespace, const void *caller_addr, const dl_extinfo *extinfo){
struct dso* p = (struct dso*)dlopen_impl_orig(file, mode, namespace, caller_addr, extinfo);
if (p == NULL) {
return p;
}
pthread_rwlock_wrlock(&lock);
p->nr_dlopen++;
if (p->bfs_built) {
for (int i = 0; p->deps[i]; i++) {
p->deps[i]->nr_dlopen++;
if (mode & RTLD_NODELETE) {
p->deps[i]->flags |= DSO_FLAGS_NODELETE;
}
}
}
#ifdef HANDLE_RANDOMIZATION
void *handle = assign_valid_handle(p);
if (handle == NULL) {
LD_LOGE("dlopen_impl: generate random handle failed");
do_dlclose(p);
}
pthread_rwlock_unlock(&lock);
return handle;
#endif
pthread_rwlock_unlock(&lock);
return p;
}
void *dlopen(const char *file, int mode)
{
const void *caller_addr = __builtin_return_address(0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册