Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
6ff6b312
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,发现更多精彩内容 >>
提交
6ff6b312
编写于
11月 10, 2022
作者:
L
lutao
1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add calloc and realloc hook
Signed-off-by:
N
lutao
<
lutao31@huawei.com
>
上级
0915ec27
变更
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
浏览文件 @
6ff6b312
...
...
@@ -50,4 +50,24 @@ int munmap(void* addr, size_t length)
return
MuslMalloc
(
munmap
)(
addr
,
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
);
}
}
#endif
porting/linux/user/src/hook/musl_preinit.c
浏览文件 @
6ff6b312
...
...
@@ -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
...
...
@@ -189,6 +191,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_hook_functions
(
void
*
shared_library_handler
,
struct
MallocDispatchType
*
table
,
const
char
*
prefix
)
{
if
(
!
init_malloc_function
(
shared_library_handler
,
&
table
->
malloc
,
prefix
))
{
...
...
@@ -203,6 +227,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
浏览文件 @
6ff6b312
...
...
@@ -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
),
};
volatile
atomic_bool
__hook_enable_hook_flag
;
...
...
porting/linux/user/src/malloc/malloc.c
浏览文件 @
6ff6b312
...
...
@@ -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
);
...
...
鸿蒙社区
@harmonycommunity
mentioned in commit
002602ef
·
11月 23, 2022
mentioned in commit
002602ef
mentioned in commit 002602ef276ff9d5227af67fc3d3e7bbc13261c8
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录