Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
5713bb18
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
接近 2 年 前同步成功
通知
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看板
提交
5713bb18
编写于
6月 01, 2023
作者:
F
fangting
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of gitee.com:openharmony/third_party_musl into master
Signed-off-by:
N
fangting
<
fangting12@huawei.com
>
上级
c6553ba5
9caef6a1
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
318 addition
and
14 deletion
+318
-14
libc-test/src/functional/test-mallopt.c
libc-test/src/functional/test-mallopt.c
+1
-1
musl_src.gni
musl_src.gni
+4
-0
musl_template.gni
musl_template.gni
+9
-0
ndk_musl_include/malloc.h
ndk_musl_include/malloc.h
+11
-0
ndk_script/adapter/libc.ndk.json
ndk_script/adapter/libc.ndk.json
+1
-0
porting/linux/user/src/hook/musl_preinit.c
porting/linux/user/src/hook/musl_preinit.c
+3
-3
porting/linux/user/src/internal/pthread_impl.h
porting/linux/user/src/internal/pthread_impl.h
+3
-0
porting/linux/user/src/internal/stdio_impl.h
porting/linux/user/src/internal/stdio_impl.h
+1
-0
porting/linux/user/src/stdio/fmemopen.c
porting/linux/user/src/stdio/fmemopen.c
+128
-0
porting/linux/user/src/stdio/freopen.c
porting/linux/user/src/stdio/freopen.c
+59
-0
porting/linux/user/src/stdio/stdin.c
porting/linux/user/src/stdio/stdin.c
+18
-0
porting/linux/user/src/string/stpncpy.c
porting/linux/user/src/string/stpncpy.c
+8
-7
porting/linux/user/src/string/strncpy.c
porting/linux/user/src/string/strncpy.c
+2
-3
porting/linux/user/src/thread/pthread_create.c
porting/linux/user/src/thread/pthread_create.c
+8
-0
porting/linux/user/src/thread/pthread_once.c
porting/linux/user/src/thread/pthread_once.c
+62
-0
未找到文件。
libc-test/src/functional/test-mallopt.c
浏览文件 @
5713bb18
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
static
int
test_mallopt
()
static
int
test_mallopt
()
{
{
return
mallopt
(
0
,
0
)
!
=
0
;
return
mallopt
(
0
,
0
)
=
=
0
;
}
}
int
main
()
int
main
()
...
...
musl_src.gni
浏览文件 @
5713bb18
...
@@ -2168,6 +2168,9 @@ musl_src_porting_file = [
...
@@ -2168,6 +2168,9 @@ musl_src_porting_file = [
"src/stdio/vfprintf.c",
"src/stdio/vfprintf.c",
"src/stdio/__stdio_read.c",
"src/stdio/__stdio_read.c",
"src/stdio/fread.c",
"src/stdio/fread.c",
"src/stdio/fmemopen.c",
"src/stdio/freopen.c",
"src/stdio/stdin.c",
"src/internal/stdio_impl.h",
"src/internal/stdio_impl.h",
"src/internal/vdso.c",
"src/internal/vdso.c",
"src/time/clock_gettime.c",
"src/time/clock_gettime.c",
...
@@ -2187,6 +2190,7 @@ musl_src_porting_file = [
...
@@ -2187,6 +2190,7 @@ musl_src_porting_file = [
"src/env/getenv.c",
"src/env/getenv.c",
"src/string/stpncpy.c",
"src/string/stpncpy.c",
"src/string/strncpy.c",
"src/string/strncpy.c",
"src/thread/pthread_once.c",
]
]
musl_inc_hook_files = [
musl_inc_hook_files = [
...
...
musl_template.gni
浏览文件 @
5713bb18
...
@@ -393,6 +393,15 @@ template("musl_libs") {
...
@@ -393,6 +393,15 @@ template("musl_libs") {
}
}
defines = []
defines = []
if (musl_arch == "arm") {
defines += [ "MUSL_ARM_ARCH" ]
}
if (musl_arch == "aarch64") {
defines += [ "MUSL_AARCH64_ARCH" ]
}
if (musl_arch == "x86_64") {
defines += [ "MUSL_X86_64_ARCH" ]
}
if (musl_secure_level > 0) {
if (musl_secure_level > 0) {
defines += [ "MALLOC_FREELIST_HARDENED" ]
defines += [ "MALLOC_FREELIST_HARDENED" ]
}
}
...
...
ndk_musl_include/malloc.h
浏览文件 @
5713bb18
...
@@ -9,6 +9,16 @@ extern "C" {
...
@@ -9,6 +9,16 @@ extern "C" {
#include <bits/alltypes.h>
#include <bits/alltypes.h>
#define M_SET_THREAD_CACHE -1001
#define M_THREAD_CACHE_ENABLE 1
#define M_THREAD_CACHE_DISABLE 0
#define M_FLUSH_THREAD_CACHE -1002
#define M_DELAYED_FREE -1003
#define M_DELAYED_FREE_ENABLE 1
#define M_DELAYED_FREE_DISABLE 0
void
*
malloc
(
size_t
);
void
*
malloc
(
size_t
);
void
*
calloc
(
size_t
,
size_t
);
void
*
calloc
(
size_t
,
size_t
);
void
*
realloc
(
void
*
,
size_t
);
void
*
realloc
(
void
*
,
size_t
);
...
@@ -17,6 +27,7 @@ void *valloc (size_t);
...
@@ -17,6 +27,7 @@ void *valloc (size_t);
void
*
memalign
(
size_t
,
size_t
);
void
*
memalign
(
size_t
,
size_t
);
size_t
malloc_usable_size
(
void
*
);
size_t
malloc_usable_size
(
void
*
);
int
mallopt
(
int
param
,
int
value
);
struct
mallinfo
{
struct
mallinfo
{
int
arena
;
int
arena
;
...
...
ndk_script/adapter/libc.ndk.json
浏览文件 @
5713bb18
...
@@ -736,6 +736,7 @@
...
@@ -736,6 +736,7 @@
{
"name"
:
"lutimes"
},
{
"name"
:
"lutimes"
},
{
"name"
:
"madvise"
},
{
"name"
:
"madvise"
},
{
"name"
:
"malloc"
},
{
"name"
:
"malloc"
},
{
"name"
:
"mallopt"
},
{
"name"
:
"malloc_usable_size"
},
{
"name"
:
"malloc_usable_size"
},
{
"name"
:
"mblen"
},
{
"name"
:
"mblen"
},
{
"name"
:
"mbrlen"
},
{
"name"
:
"mbrlen"
},
...
...
porting/linux/user/src/hook/musl_preinit.c
浏览文件 @
5713bb18
...
@@ -380,7 +380,7 @@ static void malloc_finalize()
...
@@ -380,7 +380,7 @@ static void malloc_finalize()
fclose
(
stderr
);
fclose
(
stderr
);
}
}
bool
finish_install_ohos_malloc_hooks
(
struct
musl_libc_globals
*
globals
,
const
char
*
options
,
const
char
*
prefix
)
bool
finish_install_ohos_malloc_hooks
(
struct
musl_libc_globals
*
globals
,
const
char
*
options
,
const
char
*
prefix
,
void
*
shared_library_handle
)
{
{
init_func_t
init_func
=
(
init_func_t
)(
function_of_shared_lib
[
INITIALIZE_FUNCTION
]);
init_func_t
init_func
=
(
init_func_t
)(
function_of_shared_lib
[
INITIALIZE_FUNCTION
]);
if
(
!
init_func
(
&
__libc_malloc_default_dispatch
,
NULL
,
options
))
{
if
(
!
init_func
(
&
__libc_malloc_default_dispatch
,
NULL
,
options
))
{
...
@@ -395,6 +395,7 @@ bool finish_install_ohos_malloc_hooks(struct musl_libc_globals* globals, const c
...
@@ -395,6 +395,7 @@ bool finish_install_ohos_malloc_hooks(struct musl_libc_globals* globals, const c
clear_function_table
();
clear_function_table
();
return
false
;
return
false
;
}
}
atomic_store_explicit
(
&
ohos_malloc_hook_shared_library
,
(
volatile
long
long
)
shared_library_handle
,
memory_order_seq_cst
);
atomic_store_explicit
(
&
__musl_libc_globals
.
so_dispatch_table
,
(
volatile
long
long
)
&
globals
->
malloc_dispatch_table
,
memory_order_seq_cst
);
atomic_store_explicit
(
&
__musl_libc_globals
.
so_dispatch_table
,
(
volatile
long
long
)
&
globals
->
malloc_dispatch_table
,
memory_order_seq_cst
);
atomic_store_explicit
(
&
__musl_libc_globals
.
current_dispatch_table
,
(
volatile
long
long
)
&
globals
->
malloc_dispatch_table
,
memory_order_seq_cst
);
atomic_store_explicit
(
&
__musl_libc_globals
.
current_dispatch_table
,
(
volatile
long
long
)
&
globals
->
malloc_dispatch_table
,
memory_order_seq_cst
);
}
}
...
@@ -437,8 +438,7 @@ static void install_ohos_malloc_hook(struct musl_libc_globals* globals, const ch
...
@@ -437,8 +438,7 @@ static void install_ohos_malloc_hook(struct musl_libc_globals* globals, const ch
return
;
return
;
}
}
if
(
finish_install_ohos_malloc_hooks
(
globals
,
NULL
,
prefix
))
{
if
(
finish_install_ohos_malloc_hooks
(
globals
,
NULL
,
prefix
,
shared_library_handle
))
{
atomic_store_explicit
(
&
ohos_malloc_hook_shared_library
,
(
volatile
long
long
)
shared_library_handle
,
memory_order_seq_cst
);
if
(
strncmp
(
__malloc_hook_function_prefix
,
prefix
,
strlen
(
prefix
))
==
0
)
{
if
(
strncmp
(
__malloc_hook_function_prefix
,
prefix
,
strlen
(
prefix
))
==
0
)
{
atomic_store_explicit
(
&
ohos_malloc_ever_shared_library_handle
,
(
volatile
long
long
)
shared_library_handle
,
memory_order_seq_cst
);
atomic_store_explicit
(
&
ohos_malloc_ever_shared_library_handle
,
(
volatile
long
long
)
shared_library_handle
,
memory_order_seq_cst
);
}
else
{
}
else
{
...
...
porting/linux/user/src/internal/pthread_impl.h
浏览文件 @
5713bb18
...
@@ -74,6 +74,9 @@ struct pthread {
...
@@ -74,6 +74,9 @@ struct pthread {
volatile
int
killlock
[
1
];
volatile
int
killlock
[
1
];
char
*
dlerror_buf
;
char
*
dlerror_buf
;
void
*
stdio_locks
;
void
*
stdio_locks
;
#ifdef RESERVE_SIGNAL_STACK
void
*
signal_stack
;
#endif
/* Part 3 -- the positions of these fields relative to
/* Part 3 -- the positions of these fields relative to
* the end of the structure is external and internal ABI. */
* the end of the structure is external and internal ABI. */
...
...
porting/linux/user/src/internal/stdio_impl.h
浏览文件 @
5713bb18
...
@@ -63,6 +63,7 @@ hidden off_t __stdio_seek(FILE *, off_t, int);
...
@@ -63,6 +63,7 @@ hidden off_t __stdio_seek(FILE *, off_t, int);
hidden
int
__stdio_close
(
FILE
*
);
hidden
int
__stdio_close
(
FILE
*
);
hidden
int
__fill_buffer
(
FILE
*
f
);
hidden
int
__fill_buffer
(
FILE
*
f
);
hidden
int
__toread
(
FILE
*
);
hidden
int
__toread
(
FILE
*
);
hidden
int
__towrite
(
FILE
*
);
hidden
int
__towrite
(
FILE
*
);
...
...
porting/linux/user/src/stdio/fmemopen.c
0 → 100644
浏览文件 @
5713bb18
#include "stdio_impl.h"
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include <inttypes.h>
#include "libc.h"
struct
cookie
{
size_t
pos
,
len
,
size
;
unsigned
char
*
buf
;
int
mode
;
};
struct
mem_FILE
{
FILE
f
;
struct
cookie
c
;
unsigned
char
buf
[
UNGET
+
BUFSIZ
],
buf2
[];
};
static
off_t
mseek
(
FILE
*
f
,
off_t
off
,
int
whence
)
{
ssize_t
base
;
struct
cookie
*
c
=
f
->
cookie
;
if
(
whence
>
2U
)
{
fail:
errno
=
EINVAL
;
return
-
1
;
}
base
=
(
size_t
[
3
]){
0
,
c
->
pos
,
c
->
len
}[
whence
];
if
(
off
<
-
base
||
off
>
(
ssize_t
)
c
->
size
-
base
)
goto
fail
;
return
c
->
pos
=
base
+
off
;
}
static
size_t
mread
(
FILE
*
f
,
unsigned
char
*
buf
,
size_t
len
)
{
struct
cookie
*
c
=
f
->
cookie
;
size_t
rem
=
c
->
len
-
c
->
pos
;
if
(
c
->
pos
>
c
->
len
)
rem
=
0
;
if
(
len
>
rem
)
{
len
=
rem
;
f
->
flags
|=
F_EOF
;
}
memcpy
(
buf
,
c
->
buf
+
c
->
pos
,
len
);
c
->
pos
+=
len
;
rem
-=
len
;
if
(
rem
>
f
->
buf_size
)
rem
=
f
->
buf_size
;
f
->
rpos
=
f
->
buf
;
f
->
rend
=
f
->
buf
+
rem
;
memcpy
(
f
->
rpos
,
c
->
buf
+
c
->
pos
,
rem
);
c
->
pos
+=
rem
;
return
len
;
}
static
size_t
mwrite
(
FILE
*
f
,
const
unsigned
char
*
buf
,
size_t
len
)
{
struct
cookie
*
c
=
f
->
cookie
;
size_t
rem
;
size_t
len2
=
f
->
wpos
-
f
->
wbase
;
if
(
len2
)
{
f
->
wpos
=
f
->
wbase
;
if
(
mwrite
(
f
,
f
->
wpos
,
len2
)
<
len2
)
return
0
;
}
if
(
c
->
mode
==
'a'
)
c
->
pos
=
c
->
len
;
rem
=
c
->
size
-
c
->
pos
;
if
(
len
>
rem
)
len
=
rem
;
memcpy
(
c
->
buf
+
c
->
pos
,
buf
,
len
);
c
->
pos
+=
len
;
if
(
c
->
pos
>
c
->
len
)
{
c
->
len
=
c
->
pos
;
if
(
c
->
len
<
c
->
size
)
c
->
buf
[
c
->
len
]
=
0
;
else
if
((
f
->
flags
&
F_NORD
)
&&
c
->
size
)
c
->
buf
[
c
->
size
-
1
]
=
0
;
}
return
len
;
}
static
int
mclose
(
FILE
*
m
)
{
return
0
;
}
FILE
*
fmemopen
(
void
*
restrict
buf
,
size_t
size
,
const
char
*
restrict
mode
)
{
struct
mem_FILE
*
f
;
int
plus
=
!!
strchr
(
mode
,
'+'
);
if
(
!
strchr
(
"rwa"
,
*
mode
))
{
errno
=
EINVAL
;
return
0
;
}
if
(
!
buf
&&
size
>
PTRDIFF_MAX
)
{
errno
=
ENOMEM
;
return
0
;
}
f
=
malloc
(
sizeof
*
f
+
(
buf
?
0
:
size
));
if
(
!
f
)
return
0
;
memset
(
f
,
0
,
offsetof
(
struct
mem_FILE
,
buf
));
f
->
f
.
cookie
=
&
f
->
c
;
f
->
f
.
fd
=
-
1
;
f
->
f
.
lbf
=
EOF
;
f
->
f
.
buf
=
f
->
buf
+
UNGET
;
f
->
f
.
buf_size
=
sizeof
f
->
buf
-
UNGET
;
if
(
!
buf
)
{
buf
=
f
->
buf2
;
memset
(
buf
,
0
,
size
);
}
f
->
c
.
buf
=
buf
;
f
->
c
.
size
=
size
;
f
->
c
.
mode
=
*
mode
;
if
(
!
plus
)
f
->
f
.
flags
=
(
*
mode
==
'r'
)
?
F_NOWR
:
F_NORD
;
if
(
*
mode
==
'r'
)
f
->
c
.
len
=
size
;
else
if
(
*
mode
==
'a'
)
f
->
c
.
len
=
f
->
c
.
pos
=
strnlen
(
buf
,
size
);
else
if
(
plus
)
*
f
->
c
.
buf
=
0
;
f
->
f
.
read
=
mread
;
f
->
f
.
readx
=
mread
;
f
->
f
.
write
=
mwrite
;
f
->
f
.
seek
=
mseek
;
f
->
f
.
close
=
mclose
;
if
(
!
libc
.
threaded
)
f
->
f
.
lock
=
-
1
;
return
__ofl_add
(
&
f
->
f
);
}
porting/linux/user/src/stdio/freopen.c
0 → 100644
浏览文件 @
5713bb18
#include "stdio_impl.h"
#include <fcntl.h>
#include <unistd.h>
/* The basic idea of this implementation is to open a new FILE,
* hack the necessary parts of the new FILE into the old one, then
* close the new FILE. */
/* Locking IS necessary because another thread may provably hold the
* lock, via flockfile or otherwise, when freopen is called, and in that
* case, freopen cannot act until the lock is released. */
FILE
*
freopen
(
const
char
*
restrict
filename
,
const
char
*
restrict
mode
,
FILE
*
restrict
f
)
{
int
fl
=
__fmodeflags
(
mode
);
FILE
*
f2
;
FLOCK
(
f
);
fflush
(
f
);
if
(
!
filename
)
{
if
(
fl
&
O_CLOEXEC
)
__syscall
(
SYS_fcntl
,
f
->
fd
,
F_SETFD
,
FD_CLOEXEC
);
fl
&=
~
(
O_CREAT
|
O_EXCL
|
O_CLOEXEC
);
if
(
syscall
(
SYS_fcntl
,
f
->
fd
,
F_SETFL
,
fl
)
<
0
)
{
goto
fail
;
}
}
else
{
f2
=
fopen
(
filename
,
mode
);
if
(
!
f2
)
goto
fail
;
if
(
f2
->
fd
==
f
->
fd
)
{
f2
->
fd
=
-
1
;
/* avoid closing in fclose */
}
else
if
(
__dup3
(
f2
->
fd
,
f
->
fd
,
fl
&
O_CLOEXEC
)
<
0
)
{
goto
fail2
;
}
f
->
flags
=
(
f
->
flags
&
F_PERM
)
|
f2
->
flags
;
f
->
read
=
f2
->
read
;
f
->
readx
=
f2
->
readx
;
f
->
write
=
f2
->
write
;
f
->
seek
=
f2
->
seek
;
f
->
close
=
f2
->
close
;
fclose
(
f2
);
}
FUNLOCK
(
f
);
return
f
;
fail2:
fclose
(
f2
);
fail:
fclose
(
f
);
return
NULL
;
}
weak_alias
(
freopen
,
freopen64
);
porting/linux/user/src/stdio/stdin.c
0 → 100644
浏览文件 @
5713bb18
#include "stdio_impl.h"
#undef stdin
static
unsigned
char
buf
[
BUFSIZ
+
UNGET
];
hidden
FILE
__stdin_FILE
=
{
.
buf
=
buf
+
UNGET
,
.
buf_size
=
sizeof
buf
-
UNGET
,
.
fd
=
0
,
.
flags
=
F_PERM
|
F_NOWR
,
.
read
=
__stdio_read
,
.
readx
=
__stdio_readx
,
.
seek
=
__stdio_seek
,
.
close
=
__stdio_close
,
.
lock
=
-
1
,
};
FILE
*
const
stdin
=
&
__stdin_FILE
;
FILE
*
volatile
__stdin_used
=
&
__stdin_FILE
;
porting/linux/user/src/string/stpncpy.c
浏览文件 @
5713bb18
...
@@ -3,17 +3,18 @@
...
@@ -3,17 +3,18 @@
char
*
__stpncpy
(
char
*
dst
,
const
char
*
src
,
size_t
n
)
char
*
__stpncpy
(
char
*
dst
,
const
char
*
src
,
size_t
n
)
{
{
char
*
d
=
dst
,
*
s
=
src
;
char
*
d
=
dst
,
*
s
=
src
;
char
*
flag
=
dst
;
dst
=
&
dst
[
n
]
;
while
(
n
>
0
){
while
(
n
>
0
){
*
d
=
*
src
;
if
((
*
d
++
=
*
src
++
)
==
0
){
if
(
*
s
!=
0
){
dst
=
d
-
1
;
s
++
;
while
(
--
n
>
0
){
flag
++
;
*
d
++
=
0
;
}
break
;
}
}
d
++
;
n
--
;
n
--
;
}
}
return
(
++
flag
);
return
(
dst
);
}
}
weak_alias
(
__stpncpy
,
stpncpy
);
weak_alias
(
__stpncpy
,
stpncpy
);
porting/linux/user/src/string/strncpy.c
浏览文件 @
5713bb18
...
@@ -4,12 +4,11 @@ char *strncpy(char *dst, const char *src, size_t n)
...
@@ -4,12 +4,11 @@ char *strncpy(char *dst, const char *src, size_t n)
{
{
char
*
d
=
dst
,
*
s
=
src
;
char
*
d
=
dst
,
*
s
=
src
;
while
(
n
>
0
){
while
(
n
>
0
){
*
d
=
*
s
;
if
((
*
d
=
*
s
)
!=
0
){
if
(
*
s
!=
0
){
s
++
;
s
++
;
}
}
d
++
;
d
++
;
n
--
;
n
--
;
}
}
return
(
d
);
return
(
d
st
);
}
}
\ No newline at end of file
porting/linux/user/src/thread/pthread_create.c
浏览文件 @
5713bb18
...
@@ -61,6 +61,7 @@ void __pthread_reserve_signal_stack()
...
@@ -61,6 +61,7 @@ void __pthread_reserve_signal_stack()
sigaltstack
(
&
signal_stack
,
NULL
);
sigaltstack
(
&
signal_stack
,
NULL
);
pthread_t
self
=
__pthread_self
();
pthread_t
self
=
__pthread_self
();
self
->
signal_stack
=
stack
;
char
name
[
ANON_STACK_NAME_SIZE
];
char
name
[
ANON_STACK_NAME_SIZE
];
snprintf
(
name
,
ANON_STACK_NAME_SIZE
,
"signal_stack:%d"
,
__pthread_self
()
->
tid
);
snprintf
(
name
,
ANON_STACK_NAME_SIZE
,
"signal_stack:%d"
,
__pthread_self
()
->
tid
);
prctl
(
PR_SET_VMA
,
PR_SET_VMA_ANON_NAME
,
signal_stack
.
ss_sp
,
signal_stack
.
ss_size
,
name
);
prctl
(
PR_SET_VMA
,
PR_SET_VMA_ANON_NAME
,
signal_stack
.
ss_sp
,
signal_stack
.
ss_size
,
name
);
...
@@ -69,13 +70,20 @@ void __pthread_reserve_signal_stack()
...
@@ -69,13 +70,20 @@ void __pthread_reserve_signal_stack()
void
__pthread_release_signal_stack
()
void
__pthread_release_signal_stack
()
{
{
pthread_t
self
=
__pthread_self
();
if
(
self
->
signal_stack
==
NULL
)
{
return
;
}
stack_t
signal_stack
,
old_stack
;
stack_t
signal_stack
,
old_stack
;
memset
(
&
signal_stack
,
0
,
sizeof
(
signal_stack
));
memset
(
&
signal_stack
,
0
,
sizeof
(
signal_stack
));
signal_stack
.
ss_flags
=
SS_DISABLE
;
signal_stack
.
ss_flags
=
SS_DISABLE
;
sigaltstack
(
&
signal_stack
,
&
old_stack
);
sigaltstack
(
&
signal_stack
,
&
old_stack
);
munmap
(
self
->
signal_stack
,
__default_guardsize
);
if
(
old_stack
.
ss_flags
!=
SS_DISABLE
)
{
if
(
old_stack
.
ss_flags
!=
SS_DISABLE
)
{
munmap
(
old_stack
.
ss_sp
,
old_stack
.
ss_size
);
munmap
(
old_stack
.
ss_sp
,
old_stack
.
ss_size
);
}
}
self
->
signal_stack
=
NULL
;
}
}
weak_alias
(
__pthread_reserve_signal_stack
,
pthread_reserve_signal_stack
);
weak_alias
(
__pthread_reserve_signal_stack
,
pthread_reserve_signal_stack
);
...
...
porting/linux/user/src/thread/pthread_once.c
0 → 100644
浏览文件 @
5713bb18
#include "pthread_impl.h"
static
void
undo
(
void
*
control
)
{
/* Wake all waiters, since the waiter status is lost when
* resetting control to the initial state. */
if
(
a_swap
(
control
,
0
)
==
3
)
__wake
(
control
,
-
1
,
1
);
}
hidden
int
__pthread_once_full
(
pthread_once_t
*
control
,
void
(
*
init
)(
void
))
{
/* Try to enter initializing state. Four possibilities:
* 0 - we're the first or the other cancelled; run init
* 1 - another thread is running init; wait
* 2 - another thread finished running init; just return
* 3 - another thread is running init, waiters present; wait */
for
(;;)
switch
(
a_cas
(
control
,
0
,
1
))
{
case
0
:
pthread_cleanup_push
(
undo
,
control
);
init
();
pthread_cleanup_pop
(
0
);
if
(
a_swap
(
control
,
2
)
==
3
)
__wake
(
control
,
-
1
,
1
);
return
0
;
case
1
:
/* If this fails, so will __wait. */
a_cas
(
control
,
1
,
3
);
case
3
:
__wait
(
control
,
0
,
3
,
1
);
continue
;
case
2
:
return
0
;
}
}
#if defined(MUSL_AARCH64_ARCH) || defined(MUSL_ARM_ARCH)
int
__pthread_once
(
pthread_once_t
*
control
,
void
(
*
init
)(
void
))
{
/* Return immediately if init finished before, use load aquire to ensure that
* effects of the init routine are visible to the caller. */
if
(
a_ll
((
volatile
int
*
)
control
)
==
2
)
{
return
0
;
}
return
__pthread_once_full
(
control
,
init
);
}
#else
int
__pthread_once
(
pthread_once_t
*
control
,
void
(
*
init
)(
void
))
{
/* Return immediately if init finished before, but ensure that
* effects of the init routine are visible to the caller. */
if
(
*
(
volatile
int
*
)
control
==
2
)
{
a_barrier
();
return
0
;
}
return
__pthread_once_full
(
control
,
init
);
}
#endif
weak_alias
(
__pthread_once
,
pthread_once
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录