Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
db5ff62f
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
10 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
db5ff62f
编写于
3月 22, 2022
作者:
O
openharmony_ci
提交者:
Gitee
3月 22, 2022
浏览文件
操作
浏览文件
下载
差异文件
!274 fix asan build and typo
Merge pull request !274 from stesen/master
上级
22fbed43
f250a07b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
10 deletion
+28
-10
porting/linux/user/src/hook/musl_preinit.c
porting/linux/user/src/hook/musl_preinit.c
+7
-7
porting/linux/user/src/hook/musl_preinit_common.h
porting/linux/user/src/hook/musl_preinit_common.h
+21
-3
未找到文件。
porting/linux/user/src/hook/musl_preinit.c
浏览文件 @
db5ff62f
...
...
@@ -40,7 +40,7 @@ static struct MallocDispatchType __ohos_malloc_hook_init_dispatch = {
static
char
*
__malloc_hook_shared_lib
=
"libnative_hook.z.so"
;
static
char
*
__malloc_hook_function_prefix
=
"ohos_malloc_hook"
;
static
char
*
__get_param_shared_Lib
=
"libparam_client.z.so"
;
volatile
atomic_llong
ohos_malloc_hook_shared_li
i
brary
;
volatile
atomic_llong
ohos_malloc_hook_shared_library
;
void
*
function_of_shared_lib
[
LAST_FUNCTION
];
static
enum
EnumHookMode
__hook_mode
=
STEP_HOOK_MODE
;
static
char
__hook_process_path
[
PATH_MAX
+
1
]
=
{
0
};
...
...
@@ -63,11 +63,11 @@ static char* get_native_hook_param()
}
const
char
*
key
=
MUSL_HOOK_PARAM_NAME
;
char
*
value
=
(
char
*
)
malloc
(
OHOS_PARAM_MAX_SIZE
);
memset
(
value
,
0
,
OHOS_PARAM_MAX_SIZE
);
if
(
value
==
NULL
)
{
dlclose
(
shared_library_handle
);
return
NULL
;
}
memset
(
value
,
0
,
OHOS_PARAM_MAX_SIZE
);
unsigned
int
len
=
OHOS_PARAM_MAX_SIZE
;
getFunction
(
key
,
value
,
&
len
);
dlclose
(
shared_library_handle
);
...
...
@@ -270,7 +270,7 @@ static bool is_empty_string(const char* str)
static
void
install_ohos_malloc_hook
(
struct
musl_libc_globals
*
globals
)
{
volatile
void
*
shared_library_handle
=
(
volatile
void
*
)
atomic_load_explicit
(
&
ohos_malloc_hook_shared_li
i
brary
,
memory_order_acquire
);
volatile
void
*
shared_library_handle
=
(
volatile
void
*
)
atomic_load_explicit
(
&
ohos_malloc_hook_shared_library
,
memory_order_acquire
);
assert
(
shared_library_handle
==
NULL
||
shared_library_handle
==
(
volatile
void
*
)
-
1
);
shared_library_handle
=
(
volatile
void
*
)
load_malloc_hook_shared_library
(
__malloc_hook_shared_lib
,
__malloc_hook_function_prefix
,
&
globals
->
malloc_dispatch_table
);
if
(
shared_library_handle
==
NULL
)
{
...
...
@@ -279,11 +279,11 @@ static void install_ohos_malloc_hook(struct musl_libc_globals* globals)
}
if
(
finish_install_ohos_malloc_hooks
(
globals
,
NULL
,
__malloc_hook_function_prefix
))
{
atomic_store_explicit
(
&
ohos_malloc_hook_shared_li
i
brary
,
(
volatile
long
long
)
shared_library_handle
,
memory_order_seq_cst
);
atomic_store_explicit
(
&
ohos_malloc_hook_shared_library
,
(
volatile
long
long
)
shared_library_handle
,
memory_order_seq_cst
);
}
else
{
// __musl_log(__MUSL_LOG_ERROR, "finish_install_ohos_malloc_hooks failed\n");
dlclose
((
void
*
)
shared_library_handle
);
atomic_store_explicit
(
&
ohos_malloc_hook_shared_li
i
brary
,
(
volatile
long
long
)
0
,
memory_order_seq_cst
);
atomic_store_explicit
(
&
ohos_malloc_hook_shared_library
,
(
volatile
long
long
)
0
,
memory_order_seq_cst
);
}
}
...
...
@@ -319,11 +319,11 @@ static void __install_malloc_hook()
{
atomic_store_explicit
(
&
__hook_enable_hook_flag
,
(
volatile
bool
)
true
,
memory_order_seq_cst
);
volatile
void
*
shared_library_handle
=
(
volatile
void
*
)
atomic_load_explicit
(
&
ohos_malloc_hook_shared_li
i
brary
,
memory_order_acquire
);
volatile
void
*
shared_library_handle
=
(
volatile
void
*
)
atomic_load_explicit
(
&
ohos_malloc_hook_shared_library
,
memory_order_acquire
);
if
(
shared_library_handle
==
NULL
)
{
if
(
__hook_mode
==
STEP_HOOK_MODE
)
{
atomic_store_explicit
(
&
__musl_libc_globals
.
current_dispatch_table
,
(
volatile
const
long
long
)
&
__ohos_malloc_hook_init_dispatch
,
memory_order_seq_cst
);
atomic_store_explicit
(
&
ohos_malloc_hook_shared_li
i
brary
,
(
volatile
long
long
)
-
1
,
memory_order_seq_cst
);
atomic_store_explicit
(
&
ohos_malloc_hook_shared_library
,
(
volatile
long
long
)
-
1
,
memory_order_seq_cst
);
}
else
{
init_ohos_malloc_hook
();
}
...
...
porting/linux/user/src/hook/musl_preinit_common.h
浏览文件 @
db5ff62f
...
...
@@ -27,8 +27,10 @@ enum EnumHookMode {
STEP_HOOK_MODE
,
};
#ifdef HOOK_ENABLE
extern
void
*
function_of_shared_lib
[];
extern
volatile
atomic_llong
ohos_malloc_hook_shared_liibrary
;
extern
volatile
atomic_llong
ohos_malloc_hook_shared_library
;
#endif // HOOK_ENABLE
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -37,14 +39,19 @@ extern "C" {
__attribute__
((
always_inline
))
inline
bool
__get_global_hook_flag
()
{
#ifdef HOOK_ENABLE
volatile
bool
g_flag
=
atomic_load_explicit
(
&
__hook_enable_hook_flag
,
memory_order_acquire
);
return
g_flag
;
#else
return
false
;
#endif // HOOK_ENABLE
}
__attribute__
((
always_inline
))
inline
bool
__get_hook_flag
()
{
volatile
void
*
impl_handle
=
(
void
*
)
atomic_load_explicit
(
&
ohos_malloc_hook_shared_liibrary
,
memory_order_acquire
);
#ifdef HOOK_ENABLE
volatile
void
*
impl_handle
=
(
void
*
)
atomic_load_explicit
(
&
ohos_malloc_hook_shared_library
,
memory_order_acquire
);
if
(
impl_handle
==
NULL
)
{
return
false
;
}
...
...
@@ -56,12 +63,16 @@ inline bool __get_hook_flag()
bool
flag
=
get_hook_func_ptr
();
return
flag
;
}
#else
return
false
;
#endif // HOOK_ENABLE
}
__attribute__
((
always_inline
))
inline
bool
__set_hook_flag
(
bool
flag
)
{
volatile
void
*
impl_handle
=
(
void
*
)
atomic_load_explicit
(
&
ohos_malloc_hook_shared_liibrary
,
memory_order_acquire
);
#ifdef HOOK_ENABLE
volatile
void
*
impl_handle
=
(
void
*
)
atomic_load_explicit
(
&
ohos_malloc_hook_shared_library
,
memory_order_acquire
);
if
(
impl_handle
==
NULL
)
{
return
false
;
}
...
...
@@ -72,11 +83,15 @@ inline bool __set_hook_flag(bool flag)
SetHookFlagType
set_hook_func_ptr
=
(
SetHookFlagType
)(
function_of_shared_lib
[
SET_HOOK_FLAG_FUNCTION
]);
return
set_hook_func_ptr
(
flag
);
}
#else
return
false
;
#endif // HOOK_ENABLE
}
__attribute__
((
always_inline
))
inline
volatile
const
struct
MallocDispatchType
*
get_current_dispatch_table
()
{
#ifdef HOOK_ENABLE
volatile
const
struct
MallocDispatchType
*
ret
=
(
struct
MallocDispatchType
*
)
atomic_load_explicit
(
&
__musl_libc_globals
.
current_dispatch_table
,
memory_order_acquire
);
if
(
ret
!=
NULL
)
{
if
(
!
__get_global_hook_flag
())
{
...
...
@@ -87,6 +102,9 @@ inline volatile const struct MallocDispatchType* get_current_dispatch_table()
}
}
return
ret
;
#else
return
NULL
;
#endif // HOOK_ENABLE
}
#define MUSL_HOOK_PARAM_NAME "libc.hook_mode"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录