@@ -8,16 +8,12 @@ use axsync::Mutex;
88use axtask:: { TaskExtRef , current} ;
99use bitflags:: bitflags;
1010use linux_raw_sys:: general:: * ;
11- use macro_rules_attribute:: apply;
1211use starry_core:: {
1312 mm:: copy_from_kernel,
1413 task:: { ProcessData , TaskExt , ThreadData , add_thread_to_table, new_user_task} ,
1514} ;
1615
17- use crate :: {
18- ptr:: { PtrWrapper , UserPtr } ,
19- syscall_instrument,
20- } ;
16+ use crate :: ptr:: { PtrWrapper , UserPtr } ;
2117
2218bitflags ! {
2319 /// Options for use with [`sys_clone`].
@@ -82,13 +78,14 @@ bitflags! {
8278 }
8379}
8480
85- #[ apply( syscall_instrument) ]
8681pub fn sys_clone (
82+ tf : & TrapFrame ,
8783 flags : u32 ,
8884 stack : usize ,
8985 parent_tid : usize ,
90- child_tid : usize ,
86+ # [ cfg ( any ( target_arch = "x86_64" , target_arch = "loongarch64" ) ) ] child_tid : usize ,
9187 tls : usize ,
88+ #[ cfg( not( any( target_arch = "x86_64" , target_arch = "loongarch64" ) ) ) ] child_tid : usize ,
9289) -> LinuxResult < isize > {
9390 const FLAG_MASK : u32 = 0xff ;
9491 let exit_signal = flags & FLAG_MASK ;
@@ -103,23 +100,12 @@ pub fn sys_clone(
103100 return Err ( LinuxError :: EINVAL ) ;
104101 }
105102
106- let curr = current ( ) ;
107-
108- let trap_frame = read_trapframe_from_kstack ( curr. get_kernel_stack_top ( ) . unwrap ( ) ) ;
109- let mut new_uctx = UspaceContext :: from ( & trap_frame) ;
103+ let mut new_uctx = UspaceContext :: from ( tf) ;
110104 if stack != 0 {
111105 new_uctx. set_sp ( stack) ;
112106 }
113- // Skip current instruction
114- // FIXME: we should do this in arceos before calling `handle_syscall`.
115- // See: https://github.com/oscomp/arceos/commit/13ff3f58bd825c37ea5eef3393a4f8c0bb5b4f41
116- #[ cfg( any( target_arch = "riscv64" , target_arch = "loongarch64" ) ) ]
117- {
118- let new_uctx_ip = new_uctx. ip ( ) ;
119- new_uctx. set_ip ( new_uctx_ip + 4 ) ;
120- }
121107 if flags. contains ( CloneFlags :: SETTLS ) {
122- warn ! ( "sys_clone: CLONE_SETTLS is not supported yet" ) ;
108+ new_uctx . set_tls ( tls ) ;
123109 }
124110 new_uctx. set_retval ( 0 ) ;
125111
@@ -128,13 +114,9 @@ pub fn sys_clone(
128114 } else {
129115 None
130116 } ;
131- let mut new_task = new_user_task ( curr. name ( ) , new_uctx, set_child_tid) ;
132117
133- // FIXME: remove this when we fix the tls issue
134- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
135- new_task
136- . ctx_mut ( )
137- . set_tls ( axhal:: arch:: read_thread_pointer ( ) . into ( ) ) ;
118+ let curr = current ( ) ;
119+ let mut new_task = new_user_task ( curr. name ( ) , new_uctx, set_child_tid) ;
138120
139121 let tid = new_task. id ( ) . as_u64 ( ) as Pid ;
140122 if flags. contains ( CloneFlags :: PARENT_SETTID ) {
@@ -218,12 +200,6 @@ pub fn sys_clone(
218200 Ok ( tid as _ )
219201}
220202
221- fn read_trapframe_from_kstack ( kstack_top : usize ) -> TrapFrame {
222- let trap_frame_size = core:: mem:: size_of :: < TrapFrame > ( ) ;
223- let trap_frame_ptr = ( kstack_top - trap_frame_size) as * mut TrapFrame ;
224- unsafe { * trap_frame_ptr }
225- }
226-
227- pub fn sys_fork ( ) -> LinuxResult < isize > {
228- sys_clone ( SIGCHLD , 0 , 0 , 0 , 0 )
203+ pub fn sys_fork ( tf : & TrapFrame ) -> LinuxResult < isize > {
204+ sys_clone ( tf, SIGCHLD , 0 , 0 , 0 , 0 )
229205}
0 commit comments