未验证 提交 d49521ba 编写于 作者: Z zhangcui 提交者: Gitee

优化全局变量

Signed-off-by: Nzhangcui <zhangcui11@huawei.com>
上级 8086f6b7
......@@ -44,24 +44,22 @@ static struct MallocDispatchType __ohos_malloc_hook_init_dispatch = {
.munmap = MuslMalloc(munmap),
};
#define MAX_SYM_NAME_SIZE 1000
#define MAX_PROC_NAME_SIZE 1024
static char *__malloc_hook_shared_lib = "libnative_hook.z.so";
static char *__malloc_hook_function_prefix = "ohos_malloc_hook";
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};
static char __progname[PATH_MAX + 1] = {0};
static char __param_value[OHOS_PARAM_MAX_SIZE + 1] = {0};
static char* get_native_hook_param()
static void get_native_hook_param(char *buf, unsigned int buf_len)
{
#ifdef OHOS_ENABLE_PARAMETER
const char *key = MUSL_HOOK_PARAM_NAME;
unsigned int len = OHOS_PARAM_MAX_SIZE;
(void)SystemReadParam(key, __param_value, &len);
return __param_value;
unsigned int len = buf_len;
(void)SystemReadParam(key, buf, &len);
#else
return NULL;
return;
#endif
}
......@@ -70,16 +68,15 @@ static int parse_hook_variable(enum EnumHookMode* mode, char* path, int size)
if (!mode || !path || size <= 0) {
return -1;
}
bool flag = __set_hook_flag(false);
char* hook_param_value = get_native_hook_param();
if (hook_param_value == NULL || hook_param_value[0] == '\0') {
char hook_param_value[OHOS_PARAM_MAX_SIZE + 1] = {0};
unsigned int len = OHOS_PARAM_MAX_SIZE;
get_native_hook_param(hook_param_value,len);
if (hook_param_value[0] == '\0') {
*mode = STEP_HOOK_MODE;
path[0] = '\0';
} else {
char* ptr = hook_param_value;
char* mode_str = hook_param_value;
while (*ptr && *ptr != ':') {
++ptr;
}
......@@ -89,11 +86,11 @@ static int parse_hook_variable(enum EnumHookMode* mode, char* path, int size)
++ptr;
}
if (strcmp(mode_str, "startup") == 0) {
if (strcmp(hook_param_value, "startup") == 0) {
*mode = STARTUP_HOOK_MODE;
} else if (strcmp(mode_str, "direct") == 0) {
} else if (strcmp(hook_param_value, "direct") == 0) {
*mode = DIRECT_HOOK_MODE;
} else if (strcmp(mode_str, "step") == 0) {
} else if (strcmp(hook_param_value, "step") == 0) {
*mode = STEP_HOOK_MODE;
} else {
*mode = STEP_HOOK_MODE;
......@@ -427,8 +424,10 @@ __attribute__((constructor(1))) static void __musl_initialize()
{
atomic_store_explicit(&__hook_enable_hook_flag, (volatile bool)false, memory_order_seq_cst);
__set_default_malloc();
parse_hook_variable(&__hook_mode, __hook_process_path, sizeof(__hook_process_path));
char __hook_process_path[MAX_PROC_NAME_SIZE + 1] = {0};
parse_hook_variable(&__hook_mode, __hook_process_path, sizeof(__hook_process_path) - 1);
if (__hook_mode == STARTUP_HOOK_MODE) {
char __progname[MAX_PROC_NAME_SIZE + 1] = {0};
if (get_proc_name(getpid(), __progname, sizeof(__progname) - 1)) {
const char *pos = strrchr(__progname, '/');
const char* file_name;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册