未验证 提交 5fb5f523 编写于 作者: O openharmony_ci 提交者: Gitee

!641 Pick musl 631: fix dlopen time fluctuate

Merge pull request !641 from yinchuang/fix_dlopen_time_fluctuates_pick
......@@ -35,12 +35,7 @@ struct handle_node {
// linked list for handle randomization
static struct handle_node *handle_map_list = NULL;
static bool is_first_stage_init(void)
{
static bool ret;
ret = (getpid() == 1 && access("/proc/self/exe", F_OK) == -1);
return ret;
}
static uintptr_t saved_handle = 0;
void *add_handle_node(void *handle, struct dso *dso)
{
......@@ -101,12 +96,11 @@ void remove_handle_node(void *handle)
static void *gen_handle(void)
{
uintptr_t handle = 0;
uintptr_t handle = saved_handle;
do {
if (!is_first_stage_init()) {
getrandom(&handle, sizeof handle, GRND_RANDOM);
} else {
if (getrandom(&handle, sizeof handle, GRND_RANDOM | GRND_NONBLOCK) == -1) {
handle += HANDLE_INCREASE;
saved_handle = handle;
}
} while (find_dso_by_handle((void *)handle) || handle == 0);
return (void *)handle;
......@@ -220,16 +214,16 @@ void shuffle_loadtasks(struct loadtasks *tasks)
{
size_t index = 0;
struct loadtask *task = NULL;
if (is_first_stage_init()) {
return;
}
for (size_t i = 0; i < tasks->length; i++) {
getrandom(&index, sizeof index, GRND_RANDOM);
if (getrandom(&index, sizeof index, GRND_RANDOM | GRND_NONBLOCK) == -1) {
return;
} else {
index %= tasks->length;
task = tasks->array[i];
tasks->array[i] = tasks->array[index];
tasks->array[index] = task;
}
}
}
struct loadtask *create_loadtask(const char *name, struct dso *needed_by, ns_t *ns, bool check_inherited)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册