Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
c6cfe995
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
未验证
提交
c6cfe995
编写于
11月 07, 2022
作者:
O
openharmony_ci
提交者:
Gitee
11月 07, 2022
浏览文件
操作
浏览文件
下载
差异文件
!623 Add cached mechanism for getpid
Merge pull request !623 from haotuo/add_getpid_cached
上级
6785bd2c
12a34711
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
140 addition
and
11 deletion
+140
-11
musl_src.gni
musl_src.gni
+8
-2
porting/linux/user/src/env/__init_tls.c
porting/linux/user/src/env/__init_tls.c
+1
-1
porting/linux/user/src/internal/pthread_impl.h
porting/linux/user/src/internal/pthread_impl.h
+1
-0
porting/linux/user/src/linux/clone.c
porting/linux/user/src/linux/clone.c
+25
-8
porting/linux/user/src/process/arm/__vfork.s
porting/linux/user/src/process/arm/__vfork.s
+10
-0
porting/linux/user/src/process/fork.c
porting/linux/user/src/process/fork.c
+38
-0
porting/linux/user/src/process/vfork.c
porting/linux/user/src/process/vfork.c
+27
-0
porting/linux/user/src/process/x86_64/__vfork.s
porting/linux/user/src/process/x86_64/__vfork.s
+10
-0
porting/linux/user/src/thread/pthread_create.c
porting/linux/user/src/thread/pthread_create.c
+3
-0
porting/linux/user/src/unistd/getpid.c
porting/linux/user/src/unistd/getpid.c
+17
-0
未找到文件。
musl_src.gni
浏览文件 @
c6cfe995
...
...
@@ -1555,7 +1555,7 @@ if (musl_arch == "arm") {
"src/math/fmaf.c",
"src/math/sqrt.c",
"src/math/sqrtf.c",
"src/process/
vfork.c
",
"src/process/
arm/vfork.s
",
"src/setjmp/longjmp.c",
"src/setjmp/setjmp.c",
"src/signal/restore.c",
...
...
@@ -1647,7 +1647,7 @@ if (musl_arch == "arm") {
"src/math/sqrtf.c",
"src/math/sqrtl.c",
"src/math/truncl.c",
"src/process/
vfork.c
",
"src/process/
x86_64/vfork.s
",
"src/setjmp/longjmp.c",
"src/setjmp/setjmp.c",
"src/signal/restore.c",
...
...
@@ -2062,6 +2062,7 @@ musl_src_porting_file = [
"ldso/ns_config.h",
"ldso/strops.h",
"src/legacy/ulimit.c",
"src/linux/clone.c",
"src/linux/gettid.c",
"src/linux/reboot.c",
"src/linux/tgkill.c",
...
...
@@ -2131,6 +2132,11 @@ musl_src_porting_file = [
"src/time/clock_getres.c",
"src/time/gettimeofday.c",
"src/time/time.c",
"src/unistd/getpid.c",
"src/process/fork.c",
"src/process/vfork.c",
"src/process/arm/__vfork.s",
"src/process/x86_64/__vfork.s",
]
musl_inc_hook_files = [
...
...
porting/linux/user/src/env/__init_tls.c
浏览文件 @
c6cfe995
...
...
@@ -19,7 +19,7 @@ int __init_tp(void *p)
if
(
r
<
0
)
return
-
1
;
if
(
!
r
)
libc
.
can_do_threads
=
1
;
td
->
detach_state
=
DT_JOINABLE
;
td
->
tid
=
__syscall
(
SYS_set_tid_address
,
&
__thread_list_lock
);
td
->
tid
=
td
->
pid
=
__syscall
(
SYS_set_tid_address
,
&
__thread_list_lock
);
td
->
locale
=
&
libc
.
global_locale
;
td
->
robust_list
.
head
=
&
td
->
robust_list
.
head
;
td
->
sysinfo
=
__sysinfo
;
...
...
porting/linux/user/src/internal/pthread_impl.h
浏览文件 @
c6cfe995
...
...
@@ -39,6 +39,7 @@ struct pthread {
/* Part 2 -- implementation details, non-ABI. */
int
tid
;
int
pid
;
int
errno_val
;
volatile
int
detach_state
;
volatile
int
cancel
;
...
...
porting/linux/user/src/linux/clone.c
浏览文件 @
c6cfe995
...
...
@@ -48,19 +48,36 @@ int clone(int (*func)(void *), void *stack, int flags, void *arg, ...)
tls
=
va_arg
(
ap
,
void
*
);
ctid
=
va_arg
(
ap
,
pid_t
*
);
va_end
(
ap
);
if
(
!
(
flags
&
(
CLONE_VM
|
CLONE_VFORK
))
&&
func
)
{
clone_args
=
(
struct
__clone_args
*
)
malloc
(
sizeof
(
struct
__clone_args
));
if
(
clone_args
==
NULL
)
{
errno
=
ENOMEM
;
return
-
1
;
pthread_t
self
=
__pthread_self
();
pid_t
parent_pid
=
self
->
pid
;
self
->
pid
=
0
;
pid_t
caller_tid
=
self
->
tid
;
if
(
!
(
flags
&
(
CLONE_VM
|
CLONE_VFORK
)))
{
self
->
tid
=
-
1
;
if
(
func
)
{
clone_args
=
(
struct
__clone_args
*
)
malloc
(
sizeof
(
struct
__clone_args
));
if
(
clone_args
==
NULL
)
{
errno
=
ENOMEM
;
return
-
1
;
}
clone_args
->
func
=
clone_func
;
clone_args
->
arg
=
arg
;
clone_func
=
__start_child
;
}
clone_args
->
func
=
clone_func
;
clone_args
->
arg
=
arg
;
clone_func
=
__start_child
;
}
ret
=
__syscall_ret
(
__clone
(
clone_func
,
stack
,
flags
,
(
void
*
)
clone_args
,
ptid
,
tls
,
ctid
));
if
(
!
(
flags
&
(
CLONE_VM
|
CLONE_VFORK
))
&&
func
)
{
free
(
clone_args
);
}
if
(
ret
!=
0
)
{
self
->
pid
=
parent_pid
;
self
->
tid
=
caller_tid
;
}
else
if
(
self
->
tid
==
-
1
)
{
self
->
tid
=
__syscall
(
SYS_gettid
);
self
->
pid
=
self
->
tid
;
}
return
ret
;
}
porting/linux/user/src/process/arm/__vfork.s
0 → 100644
浏览文件 @
c6cfe995
.
syntax
unified
.
hidden
__vfork
.
type
__vfork
,%
function
__vfork
:
mov
ip
,
r7
mov
r7
,
190
svc
0
mov
r7
,
ip
.
hidden
__syscall_ret
b
__syscall_ret
porting/linux/user/src/process/fork.c
0 → 100644
浏览文件 @
c6cfe995
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include "syscall.h"
#include "libc.h"
#include "pthread_impl.h"
static
void
dummy
(
int
x
)
{
}
weak_alias
(
dummy
,
__fork_handler
);
pid_t
fork
(
void
)
{
pid_t
ret
;
sigset_t
set
;
__fork_handler
(
-
1
);
__block_all_sigs
(
&
set
);
#ifdef SYS_fork
ret
=
__syscall
(
SYS_fork
);
#else
ret
=
__syscall
(
SYS_clone
,
SIGCHLD
,
0
);
#endif
if
(
!
ret
)
{
pthread_t
self
=
__pthread_self
();
self
->
tid
=
__syscall
(
SYS_gettid
);
self
->
pid
=
self
->
tid
;
self
->
robust_list
.
off
=
0
;
self
->
robust_list
.
pending
=
0
;
self
->
next
=
self
->
prev
=
self
;
__thread_list_lock
=
0
;
libc
.
threads_minus_1
=
0
;
}
__restore_sigs
(
&
set
);
__fork_handler
(
!
ret
);
return
__syscall_ret
(
ret
);
}
porting/linux/user/src/process/vfork.c
0 → 100644
浏览文件 @
c6cfe995
#define _GNU_SOURCE
#include <unistd.h>
#include <signal.h>
#include "syscall.h"
#include "pthread_impl.h"
hidden
pid_t
__vfork
(
void
)
{
/* vfork syscall cannot be made from C code */
#ifdef SYS_fork
return
syscall
(
SYS_fork
);
#else
return
syscall
(
SYS_clone
,
SIGCHLD
,
0
);
#endif
}
pid_t
vfork
(
void
)
{
pthread_t
self
=
__pthread_self
();
pid_t
parent_pid
=
self
->
pid
;
self
->
pid
=
0
;
pid_t
ret
=
__vfork
();
if
(
ret
!=
0
)
{
self
->
pid
=
parent_pid
;
}
return
ret
;
}
porting/linux/user/src/process/x86_64/__vfork.s
0 → 100644
浏览文件 @
c6cfe995
.
hidden
__vfork
.
type
__vfork
,@
function
__vfork
:
pop
%
rdx
mov
$
58
,%
eax
syscall
push
%
rdx
mov
%
rax
,%
rdi
.
hidden
__syscall_ret
jmp
__syscall_ret
porting/linux/user/src/thread/pthread_create.c
浏览文件 @
c6cfe995
...
...
@@ -10,6 +10,8 @@
#include <stddef.h>
#include <stdarg.h>
pid_t
getpid
(
void
);
void
log_print
(
const
char
*
info
,...)
{
va_list
ap
;
...
...
@@ -389,6 +391,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
new
->
stack_size
=
stack
-
stack_limit
;
new
->
guard_size
=
guard
;
new
->
self
=
new
;
new
->
pid
=
getpid
();
new
->
tsd
=
(
void
*
)
tsd
;
new
->
locale
=
&
libc
.
global_locale
;
if
(
attr
.
_a_detach
)
{
...
...
porting/linux/user/src/unistd/getpid.c
0 → 100644
浏览文件 @
c6cfe995
#include <unistd.h>
#include "pthread_impl.h"
#include "syscall.h"
static
pid_t
__get_cached_pid
()
{
return
__pthread_self
()
->
pid
;
}
pid_t
getpid
(
void
)
{
pid_t
pid
=
__get_cached_pid
();
if
(
pid
!=
0
)
{
return
pid
;
}
return
__syscall
(
SYS_getpid
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录