Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
b74a631e
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看板
未验证
提交
b74a631e
编写于
11月 17, 2022
作者:
O
openharmony_ci
提交者:
Gitee
11月 17, 2022
浏览文件
操作
浏览文件
下载
差异文件
!670 支持calloc和realloc hook
Merge pull request !670 from 卢韬/master
上级
49123903
ff2384d6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
60 addition
and
0 deletion
+60
-0
porting/linux/user/src/hook/malloc_common.c
porting/linux/user/src/hook/malloc_common.c
+20
-0
porting/linux/user/src/hook/musl_preinit.c
porting/linux/user/src/hook/musl_preinit.c
+30
-0
porting/linux/user/src/hook/musl_preinit_common.c
porting/linux/user/src/hook/musl_preinit_common.c
+2
-0
porting/linux/user/src/malloc/malloc.c
porting/linux/user/src/malloc/malloc.c
+8
-0
未找到文件。
porting/linux/user/src/hook/malloc_common.c
浏览文件 @
b74a631e
...
...
@@ -51,6 +51,26 @@ int munmap(void* addr, size_t length)
}
}
void
*
calloc
(
size_t
m
,
size_t
n
)
{
volatile
const
struct
MallocDispatchType
*
dispatch_table
=
get_current_dispatch_table
();
if
(
__predict_false
(
dispatch_table
!=
NULL
))
{
return
dispatch_table
->
calloc
(
m
,
n
);
}
else
{
return
MuslMalloc
(
calloc
)(
m
,
n
);
}
}
void
*
realloc
(
void
*
p
,
size_t
n
)
{
volatile
const
struct
MallocDispatchType
*
dispatch_table
=
get_current_dispatch_table
();
if
(
__predict_false
(
dispatch_table
!=
NULL
))
{
return
dispatch_table
->
realloc
(
p
,
n
);
}
else
{
return
MuslMalloc
(
realloc
)(
p
,
n
);
}
}
size_t
malloc_usable_size
(
void
*
addr
)
{
volatile
const
struct
MallocDispatchType
*
dispatch_table
=
get_current_dispatch_table
();
...
...
porting/linux/user/src/hook/musl_preinit.c
浏览文件 @
b74a631e
...
...
@@ -43,6 +43,8 @@ static struct MallocDispatchType __ohos_malloc_hook_init_dispatch = {
.
free
=
MuslMalloc
(
free
),
.
mmap
=
MuslMalloc
(
mmap
),
.
munmap
=
MuslMalloc
(
munmap
),
.
calloc
=
MuslMalloc
(
calloc
),
.
realloc
=
MuslMalloc
(
realloc
),
};
#define MAX_SYM_NAME_SIZE 1000
#define MAX_PROC_NAME_SIZE 256
...
...
@@ -199,6 +201,28 @@ static bool init_memorytag_function(void* malloc_shared_library_handler, const c
return
true
;
}
static
bool
init_calloc_function
(
void
*
malloc_shared_library_handler
,
MallocCallocType
*
func
,
const
char
*
prefix
)
{
char
symbol
[
MAX_SYM_NAME_SIZE
];
snprintf
(
symbol
,
sizeof
(
symbol
),
"%s_%s"
,
prefix
,
"calloc"
);
*
func
=
(
MallocCallocType
)(
dlsym
(
malloc_shared_library_handler
,
symbol
));
if
(
*
func
==
NULL
)
{
return
false
;
}
return
true
;
}
static
bool
init_realloc_function
(
void
*
malloc_shared_library_handler
,
MallocReallocType
*
func
,
const
char
*
prefix
)
{
char
symbol
[
MAX_SYM_NAME_SIZE
];
snprintf
(
symbol
,
sizeof
(
symbol
),
"%s_%s"
,
prefix
,
"realloc"
);
*
func
=
(
MallocReallocType
)(
dlsym
(
malloc_shared_library_handler
,
symbol
));
if
(
*
func
==
NULL
)
{
return
false
;
}
return
true
;
}
static
bool
init_malloc_usable_size_function
(
void
*
malloc_shared_library_handler
,
MallocMallocUsableSizeType
*
func
,
const
char
*
prefix
)
{
char
symbol
[
MAX_SYM_NAME_SIZE
];
...
...
@@ -224,6 +248,12 @@ static bool init_hook_functions(void* shared_library_handler, struct MallocDispa
if
(
!
init_munmap_function
(
shared_library_handler
,
&
table
->
munmap
,
prefix
))
{
return
false
;
}
if
(
!
init_calloc_function
(
shared_library_handler
,
&
table
->
calloc
,
prefix
))
{
return
false
;
}
if
(
!
init_realloc_function
(
shared_library_handler
,
&
table
->
realloc
,
prefix
))
{
return
false
;
}
if
(
!
init_memorytag_function
(
shared_library_handler
,
prefix
))
{
return
false
;
}
...
...
porting/linux/user/src/hook/musl_preinit_common.c
浏览文件 @
b74a631e
...
...
@@ -12,6 +12,8 @@ struct MallocDispatchType __libc_malloc_default_dispatch = {
.
free
=
MuslMalloc
(
free
),
.
mmap
=
MuslMalloc
(
mmap
),
.
munmap
=
MuslMalloc
(
munmap
),
.
calloc
=
MuslMalloc
(
calloc
),
.
realloc
=
MuslMalloc
(
realloc
),
.
malloc_usable_size
=
MuslMalloc
(
malloc_usable_size
),
};
...
...
porting/linux/user/src/malloc/malloc.c
浏览文件 @
b74a631e
...
...
@@ -564,7 +564,11 @@ static size_t mal0_clear(char *p, size_t pagesz, size_t n)
}
}
#ifdef HOOK_ENABLE
void
*
__libc_calloc
(
size_t
m
,
size_t
n
)
#else
void
*
calloc
(
size_t
m
,
size_t
n
)
#endif
{
#ifdef USE_JEMALLOC
return
je_calloc
(
m
,
n
);
...
...
@@ -603,7 +607,11 @@ void *internal_calloc(size_t m, size_t n)
return
memset
(
p
,
0
,
n
);
}
#ifdef HOOK_ENABLE
void
*
__libc_realloc
(
void
*
p
,
size_t
n
)
#else
void
*
realloc
(
void
*
p
,
size_t
n
)
#endif
{
#ifdef USE_JEMALLOC
return
je_realloc
(
p
,
n
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录