提交 5188f84a 编写于 作者: Y yinchuang

fix dlopen time fluctuate

Signed-off-by: Nyinchuang <yinchuang@huawei.com>
上级 7508c603
...@@ -35,12 +35,7 @@ struct handle_node { ...@@ -35,12 +35,7 @@ struct handle_node {
// linked list for handle randomization // linked list for handle randomization
static struct handle_node *handle_map_list = NULL; static struct handle_node *handle_map_list = NULL;
static bool is_first_stage_init(void) static uintptr_t saved_handle = 0;
{
static bool ret;
ret = (getpid() == 1 && access("/proc/self/exe", F_OK) == -1);
return ret;
}
void *add_handle_node(void *handle, struct dso *dso) void *add_handle_node(void *handle, struct dso *dso)
{ {
...@@ -101,12 +96,11 @@ void remove_handle_node(void *handle) ...@@ -101,12 +96,11 @@ void remove_handle_node(void *handle)
static void *gen_handle(void) static void *gen_handle(void)
{ {
uintptr_t handle = 0; uintptr_t handle = saved_handle;
do { do {
if (!is_first_stage_init()) { if (getrandom(&handle, sizeof handle, GRND_RANDOM | GRND_NONBLOCK) == -1) {
getrandom(&handle, sizeof handle, GRND_RANDOM);
} else {
handle += HANDLE_INCREASE; handle += HANDLE_INCREASE;
saved_handle = handle;
} }
} while (find_dso_by_handle((void *)handle) || handle == 0); } while (find_dso_by_handle((void *)handle) || handle == 0);
return (void *)handle; return (void *)handle;
...@@ -220,15 +214,15 @@ void shuffle_loadtasks(struct loadtasks *tasks) ...@@ -220,15 +214,15 @@ void shuffle_loadtasks(struct loadtasks *tasks)
{ {
size_t index = 0; size_t index = 0;
struct loadtask *task = NULL; struct loadtask *task = NULL;
if (is_first_stage_init()) {
return;
}
for (size_t i = 0; i < tasks->length; i++) { 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) {
index %= tasks->length; return;
task = tasks->array[i]; } else {
tasks->array[i] = tasks->array[index]; index %= tasks->length;
tasks->array[index] = task; task = tasks->array[i];
tasks->array[i] = tasks->array[index];
tasks->array[index] = task;
}
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册