Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
9f99486c
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
9 个月 前同步成功
通知
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 搜索 >>
提交
9f99486c
编写于
8月 26, 2022
作者:
J
jwz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
抓取native进程启动阶段的内存
Signed-off-by:
N
jwz
<
jiangweizheng@huawei.com
>
上级
117785e1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
68 addition
and
26 deletion
+68
-26
musl_template.gni
musl_template.gni
+7
-0
porting/linux/user/ldso/dynlink.c
porting/linux/user/ldso/dynlink.c
+6
-1
porting/linux/user/src/hook/musl_preinit.c
porting/linux/user/src/hook/musl_preinit.c
+54
-24
porting/linux/user/src/hook/musl_preinit_common.h
porting/linux/user/src/hook/musl_preinit_common.h
+1
-1
未找到文件。
musl_template.gni
浏览文件 @
9f99486c
...
@@ -187,6 +187,7 @@ template("musl_libs") {
...
@@ -187,6 +187,7 @@ template("musl_libs") {
defines += [
defines += [
"OHOS_DNS_PROXY_BY_NETSYS=1",
"OHOS_DNS_PROXY_BY_NETSYS=1",
"OHOS_PERMISSION_INTERNET=1",
"OHOS_PERMISSION_INTERNET=1",
"OHOS_ENABLE_PARAMETER",
]
]
}
}
...
@@ -470,6 +471,9 @@ template("musl_libs") {
...
@@ -470,6 +471,9 @@ template("musl_libs") {
}
}
deps = porting_deps
deps = porting_deps
if (is_standard_system) {
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
}
}
}
source_set("${abi_prefix}_musl_hook") {
source_set("${abi_prefix}_musl_hook") {
...
@@ -490,6 +494,9 @@ template("musl_libs") {
...
@@ -490,6 +494,9 @@ template("musl_libs") {
"//third_party/musl:musl_copy_inc_root",
"//third_party/musl:musl_copy_inc_root",
"//third_party/musl:musl_copy_inc_sys",
"//third_party/musl:musl_copy_inc_sys",
]
]
if (is_standard_system) {
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
}
configs -= musl_inherited_configs
configs -= musl_inherited_configs
...
...
porting/linux/user/ldso/dynlink.c
浏览文件 @
9f99486c
...
@@ -34,6 +34,9 @@
...
@@ -34,6 +34,9 @@
#include "ns_config.h"
#include "ns_config.h"
#include "pthread_impl.h"
#include "pthread_impl.h"
#include "strops.h"
#include "strops.h"
#ifdef OHOS_ENABLE_PARAMETER
#include "sys_param.h"
#endif
static
void
error
(
const
char
*
,
...);
static
void
error
(
const
char
*
,
...);
...
@@ -2280,7 +2283,9 @@ void __dls3(size_t *sp, size_t *auxv)
...
@@ -2280,7 +2283,9 @@ void __dls3(size_t *sp, size_t *auxv)
env_path
=
getenv
(
"LD_LIBRARY_PATH"
);
env_path
=
getenv
(
"LD_LIBRARY_PATH"
);
env_preload
=
getenv
(
"LD_PRELOAD"
);
env_preload
=
getenv
(
"LD_PRELOAD"
);
}
}
#ifdef OHOS_ENABLE_PARAMETER
InitParameterClient
();
#endif
/* If the main program was already loaded by the kernel,
/* If the main program was already loaded by the kernel,
* AT_PHDR will point to some location other than the dynamic
* AT_PHDR will point to some location other than the dynamic
* linker's program headers. */
* linker's program headers. */
...
...
porting/linux/user/src/hook/musl_preinit.c
浏览文件 @
9f99486c
...
@@ -21,10 +21,14 @@ which need be escaped.
...
@@ -21,10 +21,14 @@ which need be escaped.
#include "musl_malloc.h"
#include "musl_malloc.h"
#include "memory_tag.h"
#include "memory_tag.h"
#include "musl_preinit_common.h"
#include "musl_preinit_common.h"
#ifdef OHOS_ENABLE_PARAMETER
#include "sys_param.h"
#endif
#include <pthread.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdlib.h>
#include <limits.h>
#include <limits.h>
#include <dlfcn.h>
#include <dlfcn.h>
#include <errno.h>
#include <stdatomic.h>
#include <stdatomic.h>
#include <ctype.h>
#include <ctype.h>
#include <assert.h>
#include <assert.h>
...
@@ -42,39 +46,26 @@ static struct MallocDispatchType __ohos_malloc_hook_init_dispatch = {
...
@@ -42,39 +46,26 @@ static struct MallocDispatchType __ohos_malloc_hook_init_dispatch = {
#define MAX_SYM_NAME_SIZE 1000
#define MAX_SYM_NAME_SIZE 1000
static
char
*
__malloc_hook_shared_lib
=
"libnative_hook.z.so"
;
static
char
*
__malloc_hook_shared_lib
=
"libnative_hook.z.so"
;
static
char
*
__malloc_hook_function_prefix
=
"ohos_malloc_hook"
;
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_library
;
volatile
atomic_llong
ohos_malloc_hook_shared_library
;
void
*
function_of_shared_lib
[
LAST_FUNCTION
];
void
*
function_of_shared_lib
[
LAST_FUNCTION
];
static
enum
EnumHookMode
__hook_mode
=
STEP_HOOK_MODE
;
static
enum
EnumHookMode
__hook_mode
=
STEP_HOOK_MODE
;
static
char
__hook_process_path
[
PATH_MAX
+
1
]
=
{
0
};
static
char
__hook_process_path
[
PATH_MAX
+
1
]
=
{
0
};
static
char
__progname
[
PATH_MAX
+
1
]
=
{
0
};
static
char
__progname
[
PATH_MAX
+
1
]
=
{
0
};
static
char
*
get_native_hook_param
()
static
char
*
get_native_hook_param
()
{
{
int
(
*
getFunction
)(
const
char
*
name
,
char
*
value
,
unsigned
int
*
len
);
#ifdef OHOS_ENABLE_PARAMETER
void
*
shared_library_handle
=
dlopen
(
__get_param_shared_Lib
,
RTLD_NOW
|
RTLD_LOCAL
);
if
(
!
shared_library_handle
)
{
return
NULL
;
}
getFunction
=
(
int
(
*
)(
const
char
*
name
,
char
*
value
,
unsigned
int
*
len
))
dlsym
((
void
*
)
shared_library_handle
,
"SystemGetParameter"
);
if
(
getFunction
==
NULL
)
{
dlclose
(
shared_library_handle
);
return
NULL
;
}
const
char
*
key
=
MUSL_HOOK_PARAM_NAME
;
const
char
*
key
=
MUSL_HOOK_PARAM_NAME
;
char
*
value
=
(
char
*
)
malloc
(
OHOS_PARAM_MAX_SIZE
);
char
*
value
=
(
char
*
)
calloc
(
OHOS_PARAM_MAX_SIZE
,
sizeof
(
char
)
);
if
(
value
==
NULL
)
{
if
(
value
==
NULL
)
{
dlclose
(
shared_library_handle
);
return
NULL
;
return
NULL
;
}
}
memset
(
value
,
0
,
OHOS_PARAM_MAX_SIZE
);
unsigned
int
len
=
OHOS_PARAM_MAX_SIZE
;
unsigned
int
len
=
OHOS_PARAM_MAX_SIZE
;
getFunction
(
key
,
value
,
&
len
);
(
void
)
SystemReadParam
(
key
,
value
,
&
len
);
dlclose
(
shared_library_handle
);
return
value
;
return
value
;
#else
return
NULL
;
#endif
}
}
static
int
parse_hook_variable
(
enum
EnumHookMode
*
mode
,
char
*
path
,
int
size
)
static
int
parse_hook_variable
(
enum
EnumHookMode
*
mode
,
char
*
path
,
int
size
)
...
@@ -102,7 +93,7 @@ static int parse_hook_variable(enum EnumHookMode* mode, char* path, int size)
...
@@ -102,7 +93,7 @@ static int parse_hook_variable(enum EnumHookMode* mode, char* path, int size)
}
}
if
(
strcmp
(
mode_str
,
"startup"
)
==
0
)
{
if
(
strcmp
(
mode_str
,
"startup"
)
==
0
)
{
*
mode
=
STA
TR
UP_HOOK_MODE
;
*
mode
=
STA
RT
UP_HOOK_MODE
;
}
else
if
(
strcmp
(
mode_str
,
"direct"
)
==
0
)
{
}
else
if
(
strcmp
(
mode_str
,
"direct"
)
==
0
)
{
*
mode
=
DIRECT_HOOK_MODE
;
*
mode
=
DIRECT_HOOK_MODE
;
}
else
if
(
strcmp
(
mode_str
,
"step"
)
==
0
)
{
}
else
if
(
strcmp
(
mode_str
,
"step"
)
==
0
)
{
...
@@ -110,7 +101,7 @@ static int parse_hook_variable(enum EnumHookMode* mode, char* path, int size)
...
@@ -110,7 +101,7 @@ static int parse_hook_variable(enum EnumHookMode* mode, char* path, int size)
}
else
{
}
else
{
*
mode
=
STEP_HOOK_MODE
;
*
mode
=
STEP_HOOK_MODE
;
}
}
if
(
*
mode
==
STA
TR
UP_HOOK_MODE
)
{
if
(
*
mode
==
STA
RT
UP_HOOK_MODE
)
{
if
(
*
ptr
==
'\"'
)
{
if
(
*
ptr
==
'\"'
)
{
++
ptr
;
++
ptr
;
int
idx
=
0
;
int
idx
=
0
;
...
@@ -133,6 +124,26 @@ static int parse_hook_variable(enum EnumHookMode* mode, char* path, int size)
...
@@ -133,6 +124,26 @@ static int parse_hook_variable(enum EnumHookMode* mode, char* path, int size)
return
0
;
return
0
;
}
}
static
bool
get_proc_name
(
pid_t
pid
,
char
*
buf
,
unsigned
int
buf_len
)
{
if
(
pid
<=
0
)
{
return
false
;
}
const
int
file_name_max_size
=
40
;
char
target_file
[
file_name_max_size
]
=
{
0
};
(
void
)
sprintf
(
target_file
,
"/proc/%d/cmdline"
,
pid
);
FILE
*
f
=
fopen
(
target_file
,
"r"
);
if
(
f
==
NULL
)
{
return
false
;
}
if
(
fgets
(
buf
,
buf_len
,
f
)
==
NULL
)
{
(
void
)
fclose
(
f
);
return
false
;
}
(
void
)
fclose
(
f
);
return
true
;
}
static
bool
init_malloc_function
(
void
*
malloc_shared_library_handler
,
MallocMallocType
*
func
,
const
char
*
prefix
)
static
bool
init_malloc_function
(
void
*
malloc_shared_library_handler
,
MallocMallocType
*
func
,
const
char
*
prefix
)
{
{
char
symbol
[
MAX_SYM_NAME_SIZE
];
char
symbol
[
MAX_SYM_NAME_SIZE
];
...
@@ -418,12 +429,31 @@ static void __initialize_malloc()
...
@@ -418,12 +429,31 @@ static void __initialize_malloc()
__install_malloc_hook_signal_handler
();
__install_malloc_hook_signal_handler
();
}
}
__attribute__
((
constructor
(
1
)))
static
void
__musl_initialize
()
__attribute__
((
constructor
(
1
)))
static
void
__musl_initialize
()
{
{
atomic_store_explicit
(
&
__hook_enable_hook_flag
,
(
volatile
bool
)
false
,
memory_order_seq_cst
);
atomic_store_explicit
(
&
__hook_enable_hook_flag
,
(
volatile
bool
)
false
,
memory_order_seq_cst
);
__set_default_malloc
();
__set_default_malloc
();
//__init_musl_log();
parse_hook_variable
(
&
__hook_mode
,
__hook_process_path
,
sizeof
(
__hook_process_path
));
if
(
__hook_mode
==
STARTUP_HOOK_MODE
)
{
if
(
get_proc_name
(
getpid
(),
__progname
,
sizeof
(
__progname
)
-
1
))
{
const
char
*
pos
=
strrchr
(
__progname
,
'/'
);
const
char
*
file_name
;
if
(
pos
!=
NULL
)
{
file_name
=
pos
+
1
;
}
else
{
file_name
=
__progname
;
}
if
(
strncmp
(
file_name
,
__hook_process_path
,
strlen
(
__hook_process_path
))
==
0
)
{
atomic_store_explicit
(
&
__hook_enable_hook_flag
,
(
volatile
bool
)
true
,
memory_order_seq_cst
);
init_ohos_malloc_hook
();
}
else
{
__hook_mode
=
STEP_HOOK_MODE
;
}
}
else
{
__hook_mode
=
STEP_HOOK_MODE
;
}
}
__initialize_malloc
();
__initialize_malloc
();
errno
=
0
;
}
}
#endif
#endif
porting/linux/user/src/hook/musl_preinit_common.h
浏览文件 @
9f99486c
...
@@ -22,7 +22,7 @@ enum EnumFunc {
...
@@ -22,7 +22,7 @@ enum EnumFunc {
};
};
enum
EnumHookMode
{
enum
EnumHookMode
{
STA
TR
UP_HOOK_MODE
,
STA
RT
UP_HOOK_MODE
,
DIRECT_HOOK_MODE
,
DIRECT_HOOK_MODE
,
STEP_HOOK_MODE
,
STEP_HOOK_MODE
,
};
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录