Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
5457f0ad
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
5457f0ad
编写于
11月 07, 2022
作者:
G
guzhihao4
提交者:
Gitee
11月 07, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'monthly_20221018' of gitee.com:openharmony/third_party_musl into monthly_20221018
Signed-off-by:
N
guzhihao4
<
guzhihao4@huawei.com
>
上级
1721c8d6
06588fcb
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
252 addition
and
21 deletion
+252
-21
musl_config.gni
musl_config.gni
+1
-0
musl_src.gni
musl_src.gni
+1
-0
musl_template.gni
musl_template.gni
+87
-0
ndk_script/toolchain.sh
ndk_script/toolchain.sh
+1
-1
porting/linux/user/ldso/dynlink.c
porting/linux/user/ldso/dynlink.c
+5
-2
porting/linux/user/ldso/dynlink_rand.c
porting/linux/user/ldso/dynlink_rand.c
+12
-18
porting/linux/user/src/malloc/jemalloc/jemalloc.c
porting/linux/user/src/malloc/jemalloc/jemalloc.c
+1
-0
porting/linux/user/src/malloc/malloc.c
porting/linux/user/src/malloc/malloc.c
+22
-0
porting/linux/user/src/malloc/malloc_usable_size.c
porting/linux/user/src/malloc/malloc_usable_size.c
+8
-0
porting/linux/user/src/malloc/memalign.c
porting/linux/user/src/malloc/memalign.c
+9
-0
porting/linux/user/src/stdio/__fdopen.c
porting/linux/user/src/stdio/__fdopen.c
+105
-0
未找到文件。
musl_config.gni
浏览文件 @
5457f0ad
...
...
@@ -32,6 +32,7 @@ declare_args() {
runtime_lib_path =
"//prebuilts/clang/ohos/linux-x86_64/llvm/lib/clang/12.0.1/lib"
user_custom_libc = true
use_jemalloc = false
musl_ported_dir = "intermidiates/${musl_target_os}/musl_src_ported"
musl_inc_out_dir = "usr/include/${musl_target_triple}"
uapi_dir = "//kernel/linux/patches/linux-5.10/prebuilts/usr/include"
...
...
musl_src.gni
浏览文件 @
5457f0ad
...
...
@@ -2130,6 +2130,7 @@ musl_src_porting_file = [
"src/time/clock_getres.c",
"src/time/gettimeofday.c",
"src/time/time.c",
"src/stdio/__fdopen.c",
]
musl_inc_hook_files = [
...
...
musl_template.gni
浏览文件 @
5457f0ad
...
...
@@ -207,6 +207,66 @@ template("musl_libs") {
}
}
config("soft_jemalloc") {
configs = []
include_dirs = [
"${target_out_dir}/${musl_ported_dir}/arch/${musl_arch}",
"${target_out_dir}/${musl_ported_dir}/arch/generic",
"${target_out_dir}/${musl_ported_dir}/src/internal",
"${target_out_dir}/${musl_ported_dir}/src/include",
"${target_out_dir}/${musl_ported_dir}/include",
"${target_out_dir}/${musl_inc_out_dir}",
"${clang_base_path}/lib/clang/${clang_version}/include",
]
cflags = [
"--target=${musl_target_triple}",
"-D_GNU_SOURCE",
"-D_REENTRANT",
"-Wall",
"-Wshorten-64-to-32",
"-Wsign-compare",
"-Wundef",
"-Wno-format-zero-length",
"-pipe",
"-g3",
"-fvisibility=hidden",
"-O3",
"-funroll-loops",
# The following flags are for avoiding errors when compiling.
"-Wno-unused-parameter",
"-Wno-unused-function",
"-Wno-missing-field-initializers",
"-U_FORTIFY_SOURCE",
"-DOHOS_ENABLE_TCACHE",
"-DOHOS_LG_TCACHE_MAXCLASS_DEFAULT=16",
"-DOHOS_NUM_ARENAS=2",
"-DOHOS_TCACHE_NSLOTS_SMALL_MAX=8",
"-DOHOS_TCACHE_NSLOTS_LARGE=16",
]
if (musl_arch == "arm") {
cflags += [ "-march=armv7-a" ]
} else if (musl_arch == "aarch64") {
cflags += [ "-march=armv8" ]
} else if (musl_arch == "x86_64") {
cflags += [ "-march=x86-64" ]
}
include_dirs += [
"//third_party",
"//third_party/musl/src/include/",
"//third_party/jemalloc/include/",
"//third_party/jemalloc/include/jemalloc/internal",
"//third_party/jemalloc/include/jemalloc",
]
}
source_set("soft_musl_crt") {
sources = [
"${target_out_dir}/${musl_ported_dir}/crt/${musl_arch}/crti.s",
...
...
@@ -452,6 +512,11 @@ template("musl_libs") {
"-fstack-protector-strong",
]
if (use_jemalloc) {
defines += [ "USE_JEMALLOC" ]
include_dirs = [ "//third_party/jemalloc/include/jemalloc" ]
}
configs -= musl_inherited_configs
configs += [ ":soft_musl_config" ]
...
...
@@ -577,6 +642,24 @@ template("musl_libs") {
]
}
source_set("soft_musl_jemalloc") {
sources = [ "./porting/linux/user/src/malloc/jemalloc/jemalloc.c" ]
deps = [
"//third_party/musl:create_alltypes_h",
"//third_party/musl:create_porting_src",
"//third_party/musl:create_syscall_h",
"//third_party/musl:create_version_h",
"//third_party/musl:musl_copy_inc_bits",
"//third_party/musl:musl_copy_inc_root",
"//third_party/musl:musl_copy_inc_sys",
]
configs -= musl_inherited_configs
configs += [ ":soft_jemalloc" ]
}
static_library("soft_libc_musl_static") {
output_name = "libc"
complete_static_lib = true
...
...
@@ -694,6 +777,10 @@ template("musl_libs") {
if (is_standard_system) {
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
}
if (use_jemalloc) {
deps += [ ":soft_musl_jemalloc" ]
}
}
action_foreach("soft_musl_crt_install_action") {
...
...
ndk_script/toolchain.sh
浏览文件 @
5457f0ad
...
...
@@ -22,7 +22,7 @@ do
done
ndk_dir
=
$(
ls
${
SOURCE_DIR
}
/lib/|more |grep ohos |awk
'{print $NF}'
)
ndk_dir
=
$(
ls
${
SOURCE_DIR
}
/lib/|more |grep ohos |
grep
-v
mipsel |grep
-v
riscv |
awk
'{print $NF}'
)
for
i
in
$ndk_dir
do
...
...
porting/linux/user/ldso/dynlink.c
浏览文件 @
5457f0ad
...
...
@@ -3390,6 +3390,7 @@ static int dlclose_impl(struct dso *p)
static
char
*
dlclose_deps_black_list
[]
=
{
"/system/lib/libhidebug.so"
,
"/system/lib64/libhidebug.so"
,
"/system/lib64/libmsdp_neardetect_algorithm.z.so"
,
"/vendor/lib64/libhril_hdf.z.so"
...
...
@@ -3410,7 +3411,7 @@ static int do_dlclose(struct dso *p)
for
(
deps_num
=
0
;
p
->
deps
[
deps_num
];
deps_num
++
);
struct
dso
**
deps_bak
=
malloc
(
deps_num
*
sizeof
(
struct
dso
*
));
struct
dso
**
deps_bak
=
internal_
malloc
(
deps_num
*
sizeof
(
struct
dso
*
));
if
(
deps_bak
!=
NULL
)
{
memcpy
(
deps_bak
,
p
->
deps
,
deps_num
*
sizeof
(
struct
dso
*
));
}
...
...
@@ -3425,7 +3426,9 @@ static int do_dlclose(struct dso *p)
}
}
free
(
deps_bak
);
internal_free
(
deps_bak
);
return
0
;
}
hidden
int
__dlclose
(
void
*
p
)
...
...
porting/linux/user/ldso/dynlink_rand.c
浏览文件 @
5457f0ad
...
...
@@ -35,12 +35,7 @@ struct handle_node {
// linked list for handle randomization
static
struct
handle_node
*
handle_map_list
=
NULL
;
static
bool
is_first_stage_init
(
void
)
{
static
bool
ret
;
ret
=
(
getpid
()
==
1
&&
access
(
"/proc/self/exe"
,
F_OK
)
==
-
1
);
return
ret
;
}
static
uintptr_t
saved_handle
=
0
;
void
*
add_handle_node
(
void
*
handle
,
struct
dso
*
dso
)
{
...
...
@@ -101,12 +96,11 @@ void remove_handle_node(void *handle)
static
void
*
gen_handle
(
void
)
{
uintptr_t
handle
=
0
;
uintptr_t
handle
=
saved_handle
;
do
{
if
(
!
is_first_stage_init
())
{
getrandom
(
&
handle
,
sizeof
handle
,
GRND_RANDOM
);
}
else
{
if
(
getrandom
(
&
handle
,
sizeof
handle
,
GRND_RANDOM
|
GRND_NONBLOCK
)
==
-
1
)
{
handle
+=
HANDLE_INCREASE
;
saved_handle
=
handle
;
}
}
while
(
find_dso_by_handle
((
void
*
)
handle
)
||
handle
==
0
);
return
(
void
*
)
handle
;
...
...
@@ -220,15 +214,15 @@ void shuffle_loadtasks(struct loadtasks *tasks)
{
size_t
index
=
0
;
struct
loadtask
*
task
=
NULL
;
if
(
is_first_stage_init
())
{
return
;
}
for
(
size_t
i
=
0
;
i
<
tasks
->
length
;
i
++
)
{
getrandom
(
&
index
,
sizeof
index
,
GRND_RANDOM
);
index
%=
tasks
->
length
;
task
=
tasks
->
array
[
i
];
tasks
->
array
[
i
]
=
tasks
->
array
[
index
];
tasks
->
array
[
index
]
=
task
;
if
(
getrandom
(
&
index
,
sizeof
index
,
GRND_RANDOM
|
GRND_NONBLOCK
)
==
-
1
)
{
return
;
}
else
{
index
%=
tasks
->
length
;
task
=
tasks
->
array
[
i
];
tasks
->
array
[
i
]
=
tasks
->
array
[
index
];
tasks
->
array
[
index
]
=
task
;
}
}
}
...
...
porting/linux/user/src/malloc/jemalloc/jemalloc.c
0 → 100644
浏览文件 @
5457f0ad
#include "jemalloc/src/static.c"
\ No newline at end of file
porting/linux/user/src/malloc/malloc.c
浏览文件 @
5457f0ad
...
...
@@ -12,6 +12,14 @@
#include "malloc_random.h"
#include <sys/prctl.h>
#ifdef USE_JEMALLOC
#include <malloc.h>
extern
void
*
je_malloc
(
size_t
size
);
extern
void
*
je_calloc
(
size_t
count
,
size_t
size
);
extern
void
*
je_realloc
(
void
*
p
,
size_t
newsize
);
extern
void
je_free
(
void
*
p
);
#endif
#if defined(__GNUC__) && defined(__PIC__)
#define inline inline __attribute__((always_inline))
#endif
...
...
@@ -448,6 +456,9 @@ void *__libc_malloc(size_t n)
void
*
malloc
(
size_t
n
)
#endif
{
#ifdef USE_JEMALLOC
return
je_malloc
(
n
);
#endif
return
internal_malloc
(
n
);
}
...
...
@@ -555,6 +566,9 @@ static size_t mal0_clear(char *p, size_t pagesz, size_t n)
void
*
calloc
(
size_t
m
,
size_t
n
)
{
#ifdef USE_JEMALLOC
return
je_calloc
(
m
,
n
);
#endif
if
(
n
&&
m
>
(
size_t
)
-
1
/
n
){
errno
=
ENOMEM
;
return
0
;
...
...
@@ -591,6 +605,9 @@ void *internal_calloc(size_t m, size_t n)
void
*
realloc
(
void
*
p
,
size_t
n
)
{
#ifdef USE_JEMALLOC
return
je_realloc
(
p
,
n
);
#endif
struct
chunk
*
self
,
*
next
;
size_t
n0
,
n1
;
void
*
new
;
...
...
@@ -1036,6 +1053,9 @@ void __libc_free(void *p)
void
free
(
void
*
p
)
#endif
{
#ifdef USE_JEMALLOC
return
je_free
(
p
);
#endif
return
internal_free
(
p
);
}
...
...
@@ -1065,6 +1085,7 @@ void internal_free(void *p)
void
__malloc_donate
(
char
*
start
,
char
*
end
)
{
#ifndef USE_JEMALLOC
size_t
align_start_up
=
(
SIZE_ALIGN
-
1
)
&
(
-
(
uintptr_t
)
start
-
OVERHEAD
);
size_t
align_end_down
=
(
SIZE_ALIGN
-
1
)
&
(
uintptr_t
)
end
;
...
...
@@ -1085,4 +1106,5 @@ void __malloc_donate(char *start, char *end)
chunk_checksum_set
(
c
);
#endif
__bin_chunk
(
c
);
#endif
}
porting/linux/user/src/malloc/malloc_usable_size.c
浏览文件 @
5457f0ad
...
...
@@ -5,10 +5,18 @@
#include "atomic.h"
#endif
#ifdef USE_JEMALLOC
extern
size_t
je_malloc_usable_size
(
void
*
p
);
#endif
hidden
void
*
(
*
const
__realloc_dep
)(
void
*
,
size_t
)
=
realloc
;
size_t
malloc_usable_size
(
void
*
p
)
{
#ifdef USE_JEMALLOC
return
je_malloc_usable_size
(
p
);
#endif
#ifndef MALLOC_RED_ZONE
return
p
?
CHUNK_SIZE
(
MEM_TO_CHUNK
(
p
))
-
OVERHEAD
:
0
;
#else
...
...
porting/linux/user/src/malloc/memalign.c
浏览文件 @
5457f0ad
#include <stdlib.h>
#ifndef USE_JEMALLOC
#include <stdint.h>
#include <errno.h>
#include "malloc_impl.h"
#include "malloc_config.h"
#else
extern
void
*
je_memalign
(
size_t
align
,
size_t
len
);
#endif
void
*
__memalign
(
size_t
align
,
size_t
len
)
{
#ifdef USE_JEMALLOC
return
je_memalign
(
align
,
len
);
#else
unsigned
char
*
mem
,
*
new
;
if
((
align
&
-
align
)
!=
align
)
{
...
...
@@ -66,6 +74,7 @@ void *__memalign(size_t align, size_t len)
__bin_chunk
(
c
);
return
new
;
#endif
}
weak_alias
(
__memalign
,
memalign
);
porting/linux/user/src/stdio/__fdopen.c
0 → 100644
浏览文件 @
5457f0ad
/* 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 "stdio_impl.h"
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include "libc.h"
static
size_t
get_bufsize
(
int
fd
)
{
struct
stat
st
;
size_t
buf_size
=
0
;
if
(
fstat
(
fd
,
&
st
)
<
0
)
{
buf_size
=
BUFSIZ
;
}
else
if
(
st
.
st_blksize
==
0
)
{
buf_size
=
BUFSIZ
;
}
else
{
buf_size
=
st
.
st_blksize
;
}
return
buf_size
;
}
FILE
*
__fdopen
(
int
fd
,
const
char
*
mode
)
{
FILE
*
f
;
struct
winsize
wsz
;
size_t
buf_size
=
0
;
/* Check for valid initial mode character */
if
(
!
strchr
(
"rwa"
,
*
mode
))
{
errno
=
EINVAL
;
return
0
;
}
/* get buffer size via file stat */
buf_size
=
get_bufsize
(
fd
);
/* Allocate FILE+buffer or fail */
if
(
!
(
f
=
malloc
(
sizeof
*
f
+
UNGET
+
buf_size
)))
{
return
0
;
}
/* Zero-fill only the struct, not the buffer */
memset
(
f
,
0
,
sizeof
*
f
);
/* Impose mode restrictions */
if
(
!
strchr
(
mode
,
'+'
))
{
f
->
flags
=
(
*
mode
==
'r'
)
?
F_NOWR
:
F_NORD
;
}
/* Apply close-on-exec flag */
if
(
strchr
(
mode
,
'e'
))
{
__syscall
(
SYS_fcntl
,
fd
,
F_SETFD
,
FD_CLOEXEC
);
}
/* Set append mode on fd if opened for append */
if
(
*
mode
==
'a'
)
{
int
flags
=
__syscall
(
SYS_fcntl
,
fd
,
F_GETFL
);
if
(
!
(
flags
&
O_APPEND
))
__syscall
(
SYS_fcntl
,
fd
,
F_SETFL
,
flags
|
O_APPEND
);
f
->
flags
|=
F_APP
;
}
f
->
fd
=
fd
;
f
->
buf
=
(
unsigned
char
*
)
f
+
sizeof
*
f
+
UNGET
;
f
->
buf_size
=
buf_size
;
/* Activate line buffered mode for terminals */
f
->
lbf
=
EOF
;
if
(
!
(
f
->
flags
&
F_NOWR
)
&&
!
__syscall
(
SYS_ioctl
,
fd
,
TIOCGWINSZ
,
&
wsz
))
{
f
->
lbf
=
'\n'
;
}
/* Initialize op ptrs. No problem if some are unneeded. */
f
->
read
=
__stdio_read
;
f
->
write
=
__stdio_write
;
f
->
seek
=
__stdio_seek
;
f
->
close
=
__stdio_close
;
if
(
!
libc
.
threaded
)
{
f
->
lock
=
-
1
;
}
/* Add new FILE to open file list */
return
__ofl_add
(
f
);
}
weak_alias
(
__fdopen
,
fdopen
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录