Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
ff2384d6
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
ff2384d6
编写于
11月 14, 2022
作者:
卢
卢韬
提交者:
Gitee
11月 14, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of gitee.com:openharmony/third_party_musl into master
Signed-off-by:
N
卢韬
<
lutao31@huawei.com
>
上级
6ff6b312
278e4a52
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
188 addition
and
5 deletion
+188
-5
libc.map.txt
libc.map.txt
+2
-2
musl_src.gni
musl_src.gni
+2
-0
porting/linux/user/src/hook/malloc_common.c
porting/linux/user/src/hook/malloc_common.c
+10
-0
porting/linux/user/src/hook/musl_preinit.c
porting/linux/user/src/hook/musl_preinit.c
+35
-3
porting/linux/user/src/hook/musl_preinit_common.c
porting/linux/user/src/hook/musl_preinit_common.c
+1
-0
porting/linux/user/src/hook/musl_preinit_common.h
porting/linux/user/src/hook/musl_preinit_common.h
+5
-0
porting/linux/user/src/internal/malloc_impl.h
porting/linux/user/src/internal/malloc_impl.h
+2
-0
porting/linux/user/src/linux/cache.c
porting/linux/user/src/linux/cache.c
+65
-0
porting/linux/user/src/malloc/malloc_usable_size.c
porting/linux/user/src/malloc/malloc_usable_size.c
+9
-0
porting/linux/user/src/sched/sched_getcpu.c
porting/linux/user/src/sched/sched_getcpu.c
+57
-0
未找到文件。
libc.map.txt
浏览文件 @
ff2384d6
LIBC
{
{
global:
___environ;
__adjtime64;
...
...
@@ -2060,4 +2060,4 @@ LIBC {
trace_marker_async_end;
trace_marker_count;
trace_marker_end;
};
\ No newline at end of file
};
musl_src.gni
浏览文件 @
ff2384d6
...
...
@@ -2137,6 +2137,8 @@ musl_src_porting_file = [
"src/process/vfork.c",
"src/process/arm/__vfork.s",
"src/process/x86_64/__vfork.s",
"src/linux/cache.c",
"src/sched/sched_getcpu.c",
]
musl_inc_hook_files = [
...
...
porting/linux/user/src/hook/malloc_common.c
浏览文件 @
ff2384d6
...
...
@@ -70,4 +70,14 @@ void* realloc(void *p, size_t n)
return
MuslMalloc
(
realloc
)(
p
,
n
);
}
}
size_t
malloc_usable_size
(
void
*
addr
)
{
volatile
const
struct
MallocDispatchType
*
dispatch_table
=
get_current_dispatch_table
();
if
(
__predict_false
(
dispatch_table
!=
NULL
))
{
return
dispatch_table
->
malloc_usable_size
(
addr
);
}
else
{
return
MuslMalloc
(
malloc_usable_size
)(
addr
);
}
}
#endif
porting/linux/user/src/hook/musl_preinit.c
浏览文件 @
ff2384d6
...
...
@@ -51,14 +51,24 @@ 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"
;
volatile
atomic_llong
ohos_malloc_hook_shared_library
;
static
char
*
kMemTrackSharedLib
=
"libmemleak_tracker.so"
;
static
char
*
kMemTrackPrefix
=
"track"
;
static
char
*
kMemTrackPropertyEnable
=
"const.hiview.memleak_tracker.enable"
;
static
char
*
kMemTrackSign
=
"true"
;
bool
checkLoadMallocMemTrack
=
false
;
void
*
function_of_shared_lib
[
LAST_FUNCTION
];
static
enum
EnumHookMode
__hook_mode
=
STEP_HOOK_MODE
;
static
char
__memleak_param_value
[
OHOS_PARAM_MAX_SIZE
+
1
]
=
{
0
};
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
=
buf_len
;
(
void
)
SystemReadParam
(
kMemTrackPropertyEnable
,
__memleak_param_value
,
&
len
);
if
(
strncmp
(
__memleak_param_value
,
kMemTrackSign
,
strlen
(
kMemTrackSign
))
==
0
)
{
checkLoadMallocMemTrack
=
true
;
}
(
void
)
SystemReadParam
(
key
,
buf
,
&
len
);
#else
return
;
...
...
@@ -213,6 +223,17 @@ static bool init_realloc_function(void* malloc_shared_library_handler, MallocRea
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
];
snprintf
(
symbol
,
sizeof
(
symbol
),
"%s_%s"
,
prefix
,
"malloc_usable_size"
);
*
func
=
(
MallocMallocUsableSizeType
)(
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
))
{
...
...
@@ -236,6 +257,9 @@ static bool init_hook_functions(void* shared_library_handler, struct MallocDispa
if
(
!
init_memorytag_function
(
shared_library_handler
,
prefix
))
{
return
false
;
}
if
(
!
init_malloc_usable_size_function
(
shared_library_handler
,
&
table
->
malloc_usable_size
,
prefix
))
{
return
false
;
}
return
true
;
}
...
...
@@ -344,11 +368,11 @@ static bool is_empty_string(const char* str)
return
true
;
}
static
void
install_ohos_malloc_hook
(
struct
musl_libc_globals
*
globals
)
static
void
install_ohos_malloc_hook
(
struct
musl_libc_globals
*
globals
,
const
char
*
shared_lib
,
const
char
*
prefix
)
{
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
);
shared_library_handle
=
(
volatile
void
*
)
load_malloc_hook_shared_library
(
shared_lib
,
prefix
,
&
globals
->
malloc_dispatch_table
);
if
(
shared_library_handle
==
NULL
)
{
// __musl_log(__MUSL_LOG_ERROR, "Can't load shared library '%s'\n", __malloc_hook_shared_lib);
return
;
...
...
@@ -365,7 +389,11 @@ static void install_ohos_malloc_hook(struct musl_libc_globals* globals)
static
void
*
init_ohos_malloc_hook
()
{
install_ohos_malloc_hook
(
&
__musl_libc_globals
);
if
(
checkLoadMallocMemTrack
)
{
install_ohos_malloc_hook
(
&
__musl_libc_globals
,
kMemTrackSharedLib
,
kMemTrackPrefix
);
}
else
{
install_ohos_malloc_hook
(
&
__musl_libc_globals
,
__malloc_hook_shared_lib
,
__malloc_hook_function_prefix
);
}
return
NULL
;
}
...
...
@@ -472,6 +500,10 @@ __attribute__((constructor(1))) static void __musl_initialize()
__hook_mode
=
STEP_HOOK_MODE
;
}
}
volatile
bool
hook_disable
=
atomic_load_explicit
(
&
__hook_enable_hook_flag
,
memory_order_acquire
);
if
(
!
hook_disable
&&
checkLoadMallocMemTrack
)
{
init_ohos_malloc_hook
();
}
__initialize_malloc
();
errno
=
0
;
}
...
...
porting/linux/user/src/hook/musl_preinit_common.c
浏览文件 @
ff2384d6
...
...
@@ -14,6 +14,7 @@ struct MallocDispatchType __libc_malloc_default_dispatch = {
.
munmap
=
MuslMalloc
(
munmap
),
.
calloc
=
MuslMalloc
(
calloc
),
.
realloc
=
MuslMalloc
(
realloc
),
.
malloc_usable_size
=
MuslMalloc
(
malloc_usable_size
),
};
volatile
atomic_bool
__hook_enable_hook_flag
;
...
...
porting/linux/user/src/hook/musl_preinit_common.h
浏览文件 @
ff2384d6
...
...
@@ -11,6 +11,8 @@ extern struct MallocDispatchType __libc_malloc_default_dispatch;
extern
volatile
atomic_bool
__hook_enable_hook_flag
;
extern
bool
checkLoadMallocMemTrack
;
enum
EnumFunc
{
INITIALIZE_FUNCTION
,
FINALIZE_FUNCTION
,
...
...
@@ -94,6 +96,9 @@ 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
(
checkLoadMallocMemTrack
)
{
return
ret
;
}
if
(
!
__get_global_hook_flag
())
{
ret
=
NULL
;
}
...
...
porting/linux/user/src/internal/malloc_impl.h
浏览文件 @
ff2384d6
...
...
@@ -95,6 +95,8 @@ hidden void *internal_calloc(size_t m, size_t n);
hidden
void
*
internal_realloc
(
void
*
p
,
size_t
n
);
hidden
size_t
internal_malloc_usable_size
(
void
*
p
);
#ifdef MALLOC_RED_ZONE
hidden
void
chunk_checksum_set
(
struct
chunk
*
c
);
...
...
porting/linux/user/src/linux/cache.c
0 → 100644
浏览文件 @
ff2384d6
/* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <errno.h>
#include "syscall.h"
#include "atomic.h"
#ifdef SYS_cacheflush
int
_flush_cache
(
void
*
addr
,
int
len
,
int
op
)
{
return
syscall
(
SYS_cacheflush
,
addr
,
len
,
op
);
}
weak_alias
(
_flush_cache
,
cacheflush
);
#endif
#ifdef SYS_cachectl
int
__cachectl
(
void
*
addr
,
int
len
,
int
op
)
{
return
syscall
(
SYS_cachectl
,
addr
,
len
,
op
);
}
weak_alias
(
__cachectl
,
cachectl
);
#endif
#ifdef SYS_riscv_flush_icache
#define VDSO_FLUSH_ICACHE_SYM "__vdso_flush_icache"
#define VDSO_FLUSH_ICACHE_VER "LINUX_4.5"
static
void
*
volatile
vdso_func
;
static
int
flush_icache_init
(
void
*
start
,
void
*
end
,
unsigned
long
int
flags
)
{
__get_vdso_info
();
void
*
p
=
__get_vdso_addr
(
VDSO_FLUSH_ICACHE_VER
,
VDSO_FLUSH_ICACHE_SYM
);
int
(
*
f
)(
void
*
,
void
*
,
unsigned
long
int
)
=
(
int
(
*
)(
void
*
,
void
*
,
unsigned
long
int
))
p
;
a_cas_p
(
&
vdso_func
,
(
void
*
)
flush_icache_init
,
p
);
return
f
?
f
(
start
,
end
,
flags
)
:
-
ENOSYS
;
}
static
void
*
volatile
vdso_func
=
(
void
*
)
flush_icache_init
;
int
__riscv_flush_icache
(
void
*
start
,
void
*
end
,
unsigned
long
int
flags
)
{
int
(
*
f
)(
void
*
,
void
*
,
unsigned
long
int
)
=
(
int
(
*
)(
void
*
,
void
*
,
unsigned
long
int
))
vdso_func
;
if
(
f
)
{
int
r
=
f
(
start
,
end
,
flags
);
if
(
!
r
)
return
r
;
if
(
r
!=
-
ENOSYS
)
return
__syscall_ret
(
r
);
}
}
weak_alias
(
__riscv_flush_icache
,
riscv_flush_icache
);
#endif
porting/linux/user/src/malloc/malloc_usable_size.c
浏览文件 @
ff2384d6
...
...
@@ -11,7 +11,16 @@ extern size_t je_malloc_usable_size(void *p);
hidden
void
*
(
*
const
__realloc_dep
)(
void
*
,
size_t
)
=
realloc
;
#ifdef HOOK_ENABLE
size_t
__libc_malloc_usable_size
(
void
*
p
)
#else
size_t
malloc_usable_size
(
void
*
p
)
#endif
{
return
internal_malloc_usable_size
(
p
);
}
size_t
internal_malloc_usable_size
(
void
*
p
)
{
#ifdef USE_JEMALLOC
return
je_malloc_usable_size
(
p
);
...
...
porting/linux/user/src/sched/sched_getcpu.c
0 → 100644
浏览文件 @
ff2384d6
/* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define _GNU_SOURCE
#include <errno.h>
#include <sched.h>
#include "syscall.h"
#include "atomic.h"
#ifdef VDSO_GETCPU_SYM
static
void
*
volatile
vdso_func
;
typedef
long
(
*
getcpu_f
)(
unsigned
*
,
unsigned
*
,
void
*
);
static
long
getcpu_init
(
unsigned
*
cpu
,
unsigned
*
node
,
void
*
unused
)
{
__get_vdso_info
();
void
*
p
=
__get_vdso_addr
(
VDSO_GETCPU_VER
,
VDSO_GETCPU_SYM
);
getcpu_f
f
=
(
getcpu_f
)
p
;
a_cas_p
(
&
vdso_func
,
(
void
*
)
getcpu_init
,
p
);
return
f
?
f
(
cpu
,
node
,
unused
)
:
-
ENOSYS
;
}
static
void
*
volatile
vdso_func
=
(
void
*
)
getcpu_init
;
#endif
int
sched_getcpu
(
void
)
{
int
r
;
unsigned
cpu
;
#ifdef VDSO_GETCPU_SYM
getcpu_f
f
=
(
getcpu_f
)
vdso_func
;
if
(
f
)
{
r
=
f
(
&
cpu
,
0
,
0
);
if
(
!
r
)
return
cpu
;
if
(
r
!=
-
ENOSYS
)
return
__syscall_ret
(
r
);
}
#endif
r
=
__syscall
(
SYS_getcpu
,
&
cpu
,
0
,
0
);
if
(
!
r
)
return
cpu
;
return
__syscall_ret
(
r
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录