Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
3ce905f5
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
大约 1 年 前同步成功
通知
37
Star
125
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Musl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3ce905f5
编写于
7月 13, 2023
作者:
H
heyujie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
File hugepage support - modify link code to support .so PMD size alignment
Signed-off-by:
N
heyujie
<
heyujie4@hisilicon.com
>
上级
029b8b76
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
87 addition
and
10 deletion
+87
-10
porting/linux/user/ldso/dynlink.c
porting/linux/user/ldso/dynlink.c
+87
-10
未找到文件。
porting/linux/user/ldso/dynlink.c
浏览文件 @
3ce905f5
...
...
@@ -81,6 +81,9 @@ static void error(const char *, ...);
#define RELOC_CAN_SEARCH_DSO_BASE_CAPACITY 32
#define ANON_NAME_MAX_LEN 70
#define KPMD_SIZE (1UL << 21)
#define HUGEPAGES_SUPPORTED_STR_SIZE (32)
#ifdef UNIT_TEST_STATIC
#define UT_STATIC
#else
...
...
@@ -1301,6 +1304,54 @@ UT_STATIC void fill_random_data(void *buf, size_t buflen)
return
;
}
static
bool
get_transparent_hugepages_supported
(
void
)
{
int
fd
=
-
1
;
ssize_t
read_size
=
0
;
bool
enable
=
false
;
char
buf
[
HUGEPAGES_SUPPORTED_STR_SIZE
]
=
{
'0'
};
fd
=
open
(
"/sys/kernel/mm/transparent_hugepage/enabled"
,
O_RDONLY
);
if
(
fd
<
0
)
goto
done
;
read_size
=
read
(
fd
,
buf
,
HUGEPAGES_SUPPORTED_STR_SIZE
-
1
);
if
(
read_size
<
0
)
goto
close_fd
;
buf
[
HUGEPAGES_SUPPORTED_STR_SIZE
-
1
]
=
'\0'
;
if
(
strstr
(
buf
,
"[never]"
)
==
NULL
)
enable
=
true
;
close_fd:
close
(
fd
);
done:
return
enable
;
}
static
size_t
phdr_table_get_maxinum_alignment
(
Phdr
*
phdr_table
,
size_t
phdr_count
)
{
#if defined(__LP64__)
size_t
maxinum_alignment
=
PAGE_SIZE
;
size_t
i
=
0
;
for
(
i
=
0
;
i
<
phdr_count
;
++
i
)
{
const
Phdr
*
phdr
=
&
phdr_table
[
i
];
/* p_align must be 0, 1, or a positive, integral power of two */
if
((
phdr
->
p_type
!=
PT_LOAD
)
||
((
phdr
->
p_align
&
(
phdr
->
p_align
-
1
))
!=
0
))
continue
;
if
(
phdr
->
p_align
>
maxinum_alignment
)
maxinum_alignment
=
phdr
->
p_align
;
}
return
maxinum_alignment
;
#else
return
PAGE_SIZE
;
#endif
}
UT_STATIC
void
*
map_library
(
int
fd
,
struct
dso
*
dso
,
struct
reserved_address_params
*
reserved_params
)
{
Ehdr
buf
[(
896
+
sizeof
(
Ehdr
))
/
sizeof
(
Ehdr
)];
...
...
@@ -1319,6 +1370,8 @@ UT_STATIC void *map_library(int fd, struct dso *dso, struct reserved_address_par
size_t
i
;
int
map_flags
=
MAP_PRIVATE
;
size_t
start_addr
;
size_t
start_alignment
=
PAGE_SIZE
;
bool
hugepage_enabled
=
false
;
ssize_t
l
=
read
(
fd
,
buf
,
sizeof
buf
);
eh
=
buf
;
...
...
@@ -1419,6 +1472,14 @@ UT_STATIC void *map_library(int fd, struct dso *dso, struct reserved_address_par
off_start
&=
-
PAGE_SIZE
;
map_len
=
addr_max
-
addr_min
+
off_start
;
start_addr
=
addr_min
;
hugepage_enabled
=
get_transparent_hugepages_supported
();
if
(
hugepage_enabled
)
{
size_t
maxinum_alignment
=
phdr_table_get_maxinum_alignment
(
ph0
,
eh
->
e_phnum
);
start_alignment
=
maxinum_alignment
==
KPMD_SIZE
?
KPMD_SIZE
:
PAGE_SIZE
;
}
if
(
reserved_params
)
{
if
(
map_len
>
reserved_params
->
reserved_size
)
{
if
(
reserved_params
->
must_use_reserved
)
{
...
...
@@ -1430,10 +1491,11 @@ UT_STATIC void *map_library(int fd, struct dso *dso, struct reserved_address_par
}
}
/* we will find a
LIBRARY_ALIGNMENT
aligned address as the start of dso
* so we need a tmp_map_len as map_len +
LIBRARY_ALIGNMENT
to make sure
/* we will find a
mapping_align
aligned address as the start of dso
* so we need a tmp_map_len as map_len +
mapping_align
to make sure
* we have enough space to shift the dso to the correct location. */
size_t
tmp_map_len
=
ALIGN
(
map_len
,
LIBRARY_ALIGNMENT
)
+
LIBRARY_ALIGNMENT
-
PAGE_SIZE
;
size_t
mapping_align
=
start_alignment
>
LIBRARY_ALIGNMENT
?
start_alignment
:
LIBRARY_ALIGNMENT
;
size_t
tmp_map_len
=
ALIGN
(
map_len
,
mapping_align
)
+
mapping_align
-
PAGE_SIZE
;
/* if reserved_params exists, we should use start_addr as prefered result to do the mmap operation */
if
(
reserved_params
)
{
...
...
@@ -1455,8 +1517,8 @@ UT_STATIC void *map_library(int fd, struct dso *dso, struct reserved_address_par
goto
error
;
}
/* find the
LIBRARY_ALIGNMENT
aligned address */
unsigned
char
*
real_map
=
(
unsigned
char
*
)
ALIGN
((
uintptr_t
)
temp_map
,
LIBRARY_ALIGNMENT
);
/* find the
mapping_align
aligned address */
unsigned
char
*
real_map
=
(
unsigned
char
*
)
ALIGN
((
uintptr_t
)
temp_map
,
mapping_align
);
/* mummap the space we mmap before so that we can mmap correct space again */
munmap
(
temp_map
,
tmp_map_len
);
...
...
@@ -1505,6 +1567,8 @@ UT_STATIC void *map_library(int fd, struct dso *dso, struct reserved_address_par
if
((
ph
->
p_vaddr
&
-
PAGE_SIZE
)
!=
addr_min
||
DL_NOMMU_SUPPORT
)
if
(
mmap_fixed
(
base
+
this_min
,
this_max
-
this_min
,
prot
,
MAP_PRIVATE
|
MAP_FIXED
,
fd
,
off_start
)
==
MAP_FAILED
)
goto
error
;
if
((
ph
->
p_flags
&
PF_X
)
&&
(
ph
->
p_align
==
KPMD_SIZE
)
&&
hugepage_enabled
)
madvise
(
base
+
this_min
,
this_max
-
this_min
,
MADV_HUGEPAGE
);
if
(
ph
->
p_memsz
>
ph
->
p_filesz
&&
(
ph
->
p_flags
&
PF_W
))
{
size_t
brk
=
(
size_t
)
base
+
ph
->
p_vaddr
+
ph
->
p_filesz
;
size_t
pgbrk
=
brk
+
PAGE_SIZE
-
1
&
-
PAGE_SIZE
;
...
...
@@ -4472,6 +4536,8 @@ static bool task_map_library(struct loadtask *task, struct reserved_address_para
size_t
i
;
int
map_flags
=
MAP_PRIVATE
;
size_t
start_addr
;
size_t
start_alignment
=
PAGE_SIZE
;
bool
hugepage_enabled
=
false
;
for
(
i
=
task
->
eh
->
e_phnum
;
i
;
i
--
,
ph
=
(
void
*
)((
char
*
)
ph
+
task
->
eh
->
e_phentsize
))
{
if
(
ph
->
p_type
==
PT_GNU_RELRO
)
{
...
...
@@ -4550,6 +4616,14 @@ static bool task_map_library(struct loadtask *task, struct reserved_address_para
off_start
&=
-
PAGE_SIZE
;
map_len
=
addr_max
-
addr_min
+
off_start
;
start_addr
=
addr_min
;
hugepage_enabled
=
get_transparent_hugepages_supported
();
if
(
hugepage_enabled
)
{
size_t
maxinum_alignment
=
phdr_table_get_maxinum_alignment
(
task
->
ph0
,
task
->
eh
->
e_phnum
);
start_alignment
=
maxinum_alignment
==
KPMD_SIZE
?
KPMD_SIZE
:
PAGE_SIZE
;
}
if
(
reserved_params
)
{
if
(
map_len
>
reserved_params
->
reserved_size
)
{
if
(
reserved_params
->
must_use_reserved
)
{
...
...
@@ -4562,10 +4636,11 @@ static bool task_map_library(struct loadtask *task, struct reserved_address_para
}
}
/* we will find a
LIBRARY_ALIGNMENT
aligned address as the start of dso
* so we need a tmp_map_len as map_len +
LIBRARY_ALIGNMENT
to make sure
/* we will find a
mapping_align
aligned address as the start of dso
* so we need a tmp_map_len as map_len +
mapping_align
to make sure
* we have enough space to shift the dso to the correct location. */
size_t
tmp_map_len
=
ALIGN
(
map_len
,
LIBRARY_ALIGNMENT
)
+
LIBRARY_ALIGNMENT
-
PAGE_SIZE
;
size_t
mapping_align
=
start_alignment
>
LIBRARY_ALIGNMENT
?
start_alignment
:
LIBRARY_ALIGNMENT
;
size_t
tmp_map_len
=
ALIGN
(
map_len
,
mapping_align
)
+
mapping_align
-
PAGE_SIZE
;
/* if reserved_params exists, we should use start_addr as prefered result to do the mmap operation */
if
(
reserved_params
)
{
...
...
@@ -4587,8 +4662,8 @@ static bool task_map_library(struct loadtask *task, struct reserved_address_para
goto
error
;
}
/* find the
LIBRARY_ALIGNMENT
aligned address */
unsigned
char
*
real_map
=
(
unsigned
char
*
)
ALIGN
((
uintptr_t
)
temp_map
,
LIBRARY_ALIGNMENT
);
/* find the
mapping_align
aligned address */
unsigned
char
*
real_map
=
(
unsigned
char
*
)
ALIGN
((
uintptr_t
)
temp_map
,
mapping_align
);
/* mummap the space we mmap before so that we can mmap correct space again */
munmap
(
temp_map
,
tmp_map_len
);
...
...
@@ -4647,6 +4722,8 @@ static bool task_map_library(struct loadtask *task, struct reserved_address_para
goto
error
;
}
}
if
((
ph
->
p_flags
&
PF_X
)
&&
(
ph
->
p_align
==
KPMD_SIZE
)
&&
hugepage_enabled
)
madvise
(
base
+
this_min
,
this_max
-
this_min
,
MADV_HUGEPAGE
);
if
(
ph
->
p_memsz
>
ph
->
p_filesz
&&
(
ph
->
p_flags
&
PF_W
))
{
size_t
brk
=
(
size_t
)
base
+
ph
->
p_vaddr
+
ph
->
p_filesz
;
size_t
pgbrk
=
brk
+
PAGE_SIZE
-
1
&
-
PAGE_SIZE
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录