提交 c2bfac38 编写于 作者: W wangjiahui

fix dlopen ld-musl-aarch64.so.1 error

Signed-off-by: Nwangjiahui <wangjiahui27@huawei.com>
上级 bfeda6a1
......@@ -25,7 +25,7 @@
#include "functionalext.h"
#define PIPE_FD 2
#define NUM_OF_BYTE 8
#define LEN_OF_POINTER 8
#define BASE_NUM 11
#define TEST_COUNTS 32
......@@ -561,6 +561,42 @@ static void dlclose_randomization_0100(void)
EXPECT_EQ(__FUNCTION__, -1, ret);
}
/**
* @tc.name : dlopen_randomization_0800
* @tc.desc : Call the dlopen interface to load libc.so
* @tc.level : Level1
*/
static void dlopen_randomization_0800(void)
{
if (sizeof(void *) == LEN_OF_POINTER) {
system("cp /system/lib64/libc.so .");
} else {
system("cp /system/lib/libc.so .");
}
void *handle = dlopen("./libc.so", RTLD_NOW);
EXPECT_PTRNE(__FUNCTION__, handle, 0);
system("rm ./libc.so");
}
/**
* @tc.name : dlopen_randomization_0900
* @tc.desc : Call the dlopen interface to load ld.so
* @tc.level : Level1
*/
static void dlopen_randomization_0900(void)
{
void *handle = NULL;
if (sizeof(void *) == LEN_OF_POINTER) {
system("cp /system/lib/ld-musl-aarch64.so.1 .");
handle = dlopen("./ld-musl-aarch64.so.1", RTLD_NOW);
system("rm ld-musl-aarch64.so.1");
} else {
system("cp /system/lib/ld-musl-arm.so.1 .");
handle = dlopen("./ld-musl-arm.so.1", RTLD_NOW);
system("rm ./ld-musl-arm.so.1");
}
EXPECT_PTRNE(__FUNCTION__, handle, 0);
}
TEST_FUNC test_cases[] = {
dlopen_randomization_0100,
......@@ -586,6 +622,8 @@ TEST_FUNC test_cases[] = {
dlsym_randomization_0600,
dlsym_randomization_0700,
dlclose_randomization_0100,
dlopen_randomization_0800,
dlopen_randomization_0900,
};
int main(int argc, char *argv[])
......
......@@ -2397,6 +2397,7 @@ static void *dlopen_impl(
#ifdef LOAD_ORDER_RANDOMIZATION
struct loadtasks *tasks = NULL;
struct loadtask *task = NULL;
bool is_task_appended = false;
#endif
if (!file) {
......@@ -2498,42 +2499,47 @@ static void *dlopen_impl(
file);
goto end;
}
p = task->p;
if (reserved_address) {
reserved_params.target = p;
reserved_params.target = task->p;
}
#else
p = load_library(file, head, ns, true, reserved_address ? &reserved_params : NULL);
#endif
}
if (!p) {
if (!task->p) {
error(noload ?
"Library %s is not already loaded" :
"Error loading shared library %s: %m",
file);
goto end;
}
#ifdef LOAD_ORDER_RANDOMIZATION
if (!task->isloaded) {
append_loadtasks(tasks, task);
is_task_appended = append_loadtasks(tasks, task);
}
preload_deps(p, ns, tasks);
preload_deps(task->p, ns, tasks);
unmap_preloaded_sections(tasks);
if (!reserved_address_recursive) {
shuffle_loadtasks(tasks);
}
run_loadtasks(tasks, reserved_address ? &reserved_params : NULL);
p = task->p;
if (!task->isloaded) {
assign_tls(p);
} else {
}
if (!is_task_appended) {
free_task(task);
task = NULL;
}
free_loadtasks(tasks);
tasks = NULL;
#else
p = load_library(file, head, ns, true, reserved_address ? &reserved_params : NULL);
}
if (!p) {
error(noload ?
"Library %s is not already loaded" :
"Error loading shared library %s: %m",
file);
goto end;
}
/* First load handling */
load_deps(p, ns, reserved_address && reserved_address_recursive ? &reserved_params : NULL);
#endif
......@@ -2588,8 +2594,10 @@ static void *dlopen_impl(
#endif
end:
#ifdef LOAD_ORDER_RANDOMIZATION
if (!is_task_appended) {
free_task(task);
}
free_loadtasks(tasks);
tasks = NULL;
#endif
__release_ptc();
if (p) gencnt++;
......@@ -3704,11 +3712,17 @@ static void task_load_library(struct loadtask *task, struct reserved_address_par
decode_dyn(task->p);
if (find_sym(task->p, "__libc_start_main", 1).sym &&
find_sym(task->p, "stdin", 1).sym) {
unmap_library(task->p);
do_dlclose(task->p);
task->p = NULL;
free((void*)task->name);
task->name = strdup("libc.so");
task->check_inherited = true;
load_library_header(task);
if (!load_library_header(task)) {
error("Error loading library %s: failed to load libc.so", task->name);
if (runtime) {
longjmp(*rtld_fail, 1);
}
}
return;
}
/* Past this point, if we haven't reached runtime yet, ldso has
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册