@@ -84,6 +84,7 @@ bitflags! {
8484
8585#[ apply( syscall_instrument) ]
8686pub fn sys_clone (
87+ tf : & TrapFrame ,
8788 flags : u32 ,
8889 stack : usize ,
8990 parent_tid : usize ,
@@ -103,23 +104,12 @@ pub fn sys_clone(
103104 return Err ( LinuxError :: EINVAL ) ;
104105 }
105106
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) ;
107+ let mut new_uctx = UspaceContext :: from ( tf) ;
110108 if stack != 0 {
111109 new_uctx. set_sp ( stack) ;
112110 }
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- }
121111 if flags. contains ( CloneFlags :: SETTLS ) {
122- warn ! ( "sys_clone: CLONE_SETTLS is not supported yet" ) ;
112+ new_uctx . set_tls ( tls ) ;
123113 }
124114 new_uctx. set_retval ( 0 ) ;
125115
@@ -128,13 +118,9 @@ pub fn sys_clone(
128118 } else {
129119 None
130120 } ;
131- let mut new_task = new_user_task ( curr. name ( ) , new_uctx, set_child_tid) ;
132121
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 ( ) ) ;
122+ let curr = current ( ) ;
123+ let mut new_task = new_user_task ( curr. name ( ) , new_uctx, set_child_tid) ;
138124
139125 let tid = new_task. id ( ) . as_u64 ( ) as Pid ;
140126 if flags. contains ( CloneFlags :: PARENT_SETTID ) {
@@ -218,12 +204,6 @@ pub fn sys_clone(
218204 Ok ( tid as _ )
219205}
220206
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 )
207+ pub fn sys_fork ( tf : & TrapFrame ) -> LinuxResult < isize > {
208+ sys_clone ( tf, SIGCHLD , 0 , 0 , 0 , 0 )
229209}
0 commit comments