Don't try to detach from a thread that is exiting, to avoid triggering

a kernel race condition.
This commit is contained in:
Alexandre Julliard 2005-08-22 10:13:28 +00:00
parent 3f24b9164d
commit 1b2adad892
3 changed files with 10 additions and 20 deletions

View File

@ -197,23 +197,6 @@ int send_thread_signal( struct thread *thread, int sig )
return (ret != -1); return (ret != -1);
} }
/* detach from a Unix thread and kill it */
void detach_thread( struct thread *thread, int sig )
{
if (thread->unix_pid == -1) return;
if (thread->attached)
{
/* make sure it is stopped */
suspend_for_ptrace( thread );
if (sig) send_thread_signal( thread, sig );
if (thread->unix_pid == -1) return;
if (debug_level) fprintf( stderr, "%04x: *detached*\n", thread->id );
ptrace( PTRACE_DETACH, get_ptrace_pid(thread), (caddr_t)1, sig );
thread->attached = 0;
}
else if (sig) send_thread_signal( thread, sig );
}
/* attach to a Unix process with ptrace */ /* attach to a Unix process with ptrace */
int attach_process( struct process *process ) int attach_process( struct process *process )
{ {
@ -242,7 +225,15 @@ void detach_process( struct process *process )
LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry ) LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
{ {
if (thread->attached) detach_thread( thread, 0 ); if (thread->attached)
{
/* make sure it is stopped */
suspend_for_ptrace( thread );
if (thread->unix_pid == -1) return;
if (debug_level) fprintf( stderr, "%04x: *detached*\n", thread->id );
ptrace( PTRACE_DETACH, get_ptrace_pid(thread), (caddr_t)1, 0 );
thread->attached = 0;
}
} }
} }

View File

@ -766,7 +766,7 @@ void kill_thread( struct thread *thread, int violent_death )
abandon_mutexes( thread ); abandon_mutexes( thread );
remove_process_thread( thread->process, thread ); remove_process_thread( thread->process, thread );
wake_up( &thread->obj, 0 ); wake_up( &thread->obj, 0 );
detach_thread( thread, violent_death ? SIGTERM : 0 ); if (violent_death) send_thread_signal( thread, SIGTERM );
cleanup_thread( thread ); cleanup_thread( thread );
release_object( thread ); release_object( thread );
} }

View File

@ -122,7 +122,6 @@ extern struct token *thread_get_impersonation_token( struct thread *thread );
extern void sigchld_callback(void); extern void sigchld_callback(void);
extern int get_ptrace_pid( struct thread *thread ); extern int get_ptrace_pid( struct thread *thread );
extern void detach_thread( struct thread *thread, int sig );
extern int attach_process( struct process *process ); extern int attach_process( struct process *process );
extern void detach_process( struct process *process ); extern void detach_process( struct process *process );
extern int suspend_for_ptrace( struct thread *thread ); extern int suspend_for_ptrace( struct thread *thread );