Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
6717e62a
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
6717e62a
编写于
6月 28, 2011
作者:
R
Rich Felker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reclaim the memory wasted by dynamic linking for use by malloc
上级
e4118279
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
39 addition
and
0 deletion
+39
-0
src/ldso/dynlink.c
src/ldso/dynlink.c
+39
-0
未找到文件。
src/ldso/dynlink.c
浏览文件 @
6717e62a
...
...
@@ -139,6 +139,37 @@ static void do_relocs(unsigned char *base, size_t *rel, size_t rel_size, size_t
}
}
/* A huge hack: to make up for the wastefulness of shared libraries
* needing at least a page of dirty memory even if they have no global
* data, we reclaim the gaps at the beginning and end of writable maps
* and "donate" them to the heap by setting up minimal malloc
* structures and then freeing them. */
static
void
reclaim
(
unsigned
char
*
base
,
size_t
start
,
size_t
end
)
{
size_t
*
a
,
*
z
;
start
=
start
+
6
*
sizeof
(
size_t
)
-
1
&
-
4
*
sizeof
(
size_t
);
end
=
(
end
&
-
4
*
sizeof
(
size_t
))
-
2
*
sizeof
(
size_t
);
if
(
start
>
end
||
end
-
start
<
4
*
sizeof
(
size_t
))
return
;
a
=
(
size_t
*
)(
base
+
start
);
z
=
(
size_t
*
)(
base
+
end
);
a
[
-
2
]
=
1
;
a
[
-
1
]
=
z
[
0
]
=
end
-
start
+
2
*
sizeof
(
size_t
)
|
1
;
z
[
1
]
=
1
;
free
(
a
);
}
static
void
reclaim_gaps
(
unsigned
char
*
base
,
Phdr
*
ph
,
size_t
phent
,
size_t
phcnt
)
{
for
(;
phcnt
--
;
ph
=
(
void
*
)((
char
*
)
ph
+
phent
))
{
if
(
ph
->
p_type
!=
PT_LOAD
)
continue
;
if
((
ph
->
p_flags
&
(
PF_R
|
PF_W
))
!=
(
PF_R
|
PF_W
))
continue
;
reclaim
(
base
,
ph
->
p_vaddr
&
-
PAGE_SIZE
,
ph
->
p_vaddr
);
reclaim
(
base
,
ph
->
p_vaddr
+
ph
->
p_memsz
,
ph
->
p_vaddr
+
ph
->
p_memsz
+
PAGE_SIZE
-
1
&
-
PAGE_SIZE
);
}
}
static
void
*
map_library
(
int
fd
,
size_t
*
lenp
,
unsigned
char
**
basep
,
size_t
*
dynp
)
{
Ehdr
buf
[(
896
+
sizeof
(
Ehdr
))
/
sizeof
(
Ehdr
)];
...
...
@@ -217,6 +248,8 @@ static void *map_library(int fd, size_t *lenp, unsigned char **basep, size_t *dy
}
}
}
if
(
!
runtime
)
reclaim_gaps
(
base
,
(
void
*
)((
char
*
)
buf
+
eh
->
e_phoff
),
eh
->
e_phentsize
,
eh
->
e_phnum
);
*
lenp
=
map_len
;
*
basep
=
base
;
*
dynp
=
dyn
;
...
...
@@ -398,6 +431,7 @@ void *__dynlink(int argc, char **argv, size_t *got)
size_t
lib_dyn
[
DYN_CNT
]
=
{
0
};
size_t
i
;
Phdr
*
phdr
;
Ehdr
*
ehdr
;
struct
dso
lib
,
app
;
/* Find aux vector just past environ[] */
...
...
@@ -456,6 +490,11 @@ void *__dynlink(int argc, char **argv, size_t *got)
/* At this point the standard library is fully functional */
reclaim_gaps
(
app
.
base
,
(
void
*
)
aux
[
AT_PHDR
],
aux
[
AT_PHENT
],
aux
[
AT_PHNUM
]);
ehdr
=
(
void
*
)
lib
.
base
;
reclaim_gaps
(
lib
.
base
,
(
void
*
)(
lib
.
base
+
ehdr
->
e_phoff
),
ehdr
->
e_phentsize
,
ehdr
->
e_phnum
);
head
=
tail
=
&
app
;
libc
=
&
lib
;
app
.
next
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录