@@ -2113,9 +2113,6 @@ dmn_ctrl_launch(DMN_CtrlCtx *ctx, OS_ProcessLaunchParams *params)
21132113 // change work directory to tracee
21142114 if (OS_LNX_RETRY_ON_EINTR (chdir (work_dir_path )) < 0 ) { goto child_exit ; }
21152115
2116- // @first_sigstop notify parent that we are going to execve
2117- if (OS_LNX_RETRY_ON_EINTR (raise (SIGSTOP )) < 0 ) { goto child_exit ; }
2118-
21192116 // replace process with target program
21202117 if (OS_LNX_RETRY_ON_EINTR (execve (argv [0 ], argv , envp )) < 0 ) { goto child_exit ; }
21212118
@@ -2128,7 +2125,9 @@ dmn_ctrl_launch(DMN_CtrlCtx *ctx, OS_ProcessLaunchParams *params)
21282125 B32 failed_to_seize = 1 ;
21292126
21302127 // try to seize child process
2131- if (OS_LNX_RETRY_ON_EINTR (ptrace (PTRACE_SEIZE , pid , 0 , 0 ) < 0 )) { goto parent_exit ; }
2128+ //
2129+ // TODO: PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK | PTRACE_O_TRACEVFORKDONE
2130+ if (OS_LNX_RETRY_ON_EINTR (ptrace (PTRACE_SEIZE , pid , 0 , PTRACE_O_TRACEEXEC | PTRACE_O_EXITKILL | PTRACE_O_TRACECLONE ) < 0 )) { goto parent_exit ; }
21322131
21332132 // ensure tracer ops are issued on thread that sizes processes
21342133 if (dmn_lnx_state -> tracer_tid == 0 ) { dmn_lnx_state -> tracer_tid = gettid (); }
@@ -2140,7 +2139,7 @@ dmn_ctrl_launch(DMN_CtrlCtx *ctx, OS_ProcessLaunchParams *params)
21402139 else { pending_proc = push_array (dmn_lnx_state -> arena , DMN_LNX_ProcessLaunch , 1 ); }
21412140
21422141 // add pending proc node to the list
2143- * pending_proc = (DMN_LNX_ProcessLaunch ){ params -> debug_subprocesses , pid , DMN_LNX_ProcessLaunchState_SigStop };
2142+ * pending_proc = (DMN_LNX_ProcessLaunch ){ params -> debug_subprocesses , pid , DMN_LNX_ProcessLaunchState_Exec };
21442143 dmn_lnx_process_launch_list_push_node (& dmn_lnx_state -> pending_procs , pending_proc );
21452144
21462145 // tracee was successfully seized
@@ -2414,52 +2413,33 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls)
24142413 // process unexpectedly exited
24152414 if (wifexited ) { pending_proc -> state = DMN_LNX_ProcessLaunchState_Exit ; }
24162415
2417- if (pending_proc -> state == DMN_LNX_ProcessLaunchState_Exec && wstopsig == SIGTRAP && event_code == PTRACE_EVENT_EXEC )
2418- {
2419- // move pending process node to the free list
2420- dmn_lnx_process_launch_list_remove (& dmn_lnx_state -> pending_procs , pending_proc );
2421- dmn_lnx_process_launch_list_push_node (& dmn_lnx_state -> free_pids , pending_proc );
2422-
2423- // push create process events
2424- dmn_lnx_handle_create_process (arena , & events , pending_proc -> debug_subprocesses , wait_id );
2425-
2426- // override event code so the main code path does not create another process
2427- event_code = PTRACE_EVENT_STOP ;
2428- }
2429- else
2416+ if (pending_proc -> state == DMN_LNX_ProcessLaunchState_Exec )
24302417 {
2431- B32 shutdown_process = 1 ;
2432-
2433- if (pending_proc -> state == DMN_LNX_ProcessLaunchState_SigStop && wstopsig == SIGSTOP ) // @first_sigstop
2434- {
2435- // set trace options and singal to proceed to the execve
2436- //
2437- // TODO: PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFROK | PTRACE_O_TRACEVFORKDONE
2438- if (OS_LNX_RETRY_ON_EINTR (ptrace (PTRACE_SETOPTIONS , wait_id , 0 , (void * )(PTRACE_O_EXITKILL | PTRACE_O_TRACEEXEC | PTRACE_O_TRACECLONE ))) >= 0 )
2439- {
2440- if (OS_LNX_RETRY_ON_EINTR (ptrace (PTRACE_CONT , wait_id , 0 , 0 )) >= 0 )
2441- {
2442- // update pending process state
2443- pending_proc -> state = DMN_LNX_ProcessLaunchState_Exec ;
2444- shutdown_process = 0 ;
2445- }
2446- }
2447- }
2448- else if (pending_proc -> state == DMN_LNX_ProcessLaunchState_Exit )
2418+ if (wstopsig == SIGTRAP && event_code == PTRACE_EVENT_EXEC )
24492419 {
24502420 // move pending process node to the free list
24512421 dmn_lnx_process_launch_list_remove (& dmn_lnx_state -> pending_procs , pending_proc );
24522422 dmn_lnx_process_launch_list_push_node (& dmn_lnx_state -> free_pids , pending_proc );
2453- shutdown_process = 0 ;
2454- }
24552423
2456- // exit on abnormal process init
2457- if (shutdown_process )
2424+ // push create process events
2425+ dmn_lnx_handle_create_process (arena , & events , pending_proc -> debug_subprocesses , wait_id );
2426+
2427+ // override event code so the main code path does not create another process
2428+ event_code = PTRACE_EVENT_STOP ;
2429+ }
2430+ else
24582431 {
2432+ // shutdown process on abnormal init
24592433 OS_LNX_RETRY_ON_EINTR (kill (wait_id , SIGKILL ));
24602434 pending_proc -> state = DMN_LNX_ProcessLaunchState_Exit ;
2435+ continue ;
24612436 }
2462-
2437+ }
2438+ else if (pending_proc -> state == DMN_LNX_ProcessLaunchState_Exit )
2439+ {
2440+ // move pending process node to the free list
2441+ dmn_lnx_process_launch_list_remove (& dmn_lnx_state -> pending_procs , pending_proc );
2442+ dmn_lnx_process_launch_list_push_node (& dmn_lnx_state -> free_pids , pending_proc );
24632443 continue ;
24642444 }
24652445 }
0 commit comments