Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 106211
b: refs/heads/master
c: dae3357
h: refs/heads/master
i:
  106209: 6fbacc5
  106207: a143731
v: v3
  • Loading branch information
Roland McGrath authored and Linus Torvalds committed Jul 26, 2008
1 parent ad1029e commit e579f67
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: daded34be96b1975ff8539ff62ad8b158ce7d842
refs/heads/master: dae33574dcf5211e1f43c7e45fa29f73ba3e00cb
13 changes: 13 additions & 0 deletions trunk/include/linux/ptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,19 @@ static inline void ptrace_init_task(struct task_struct *child, bool ptrace)
}
}

/**
* ptrace_release_task - final ptrace-related cleanup of a zombie being reaped
* @task: task in %EXIT_DEAD state
*
* Called with write_lock(&tasklist_lock) held.
*/
static inline void ptrace_release_task(struct task_struct *task)
{
BUG_ON(!list_empty(&task->ptraced));
ptrace_unlink(task);
BUG_ON(!list_empty(&task->ptrace_entry));
}

#ifndef force_successful_syscall_return
/*
* System call handlers that, upon successful completion, need to return a
Expand Down
28 changes: 28 additions & 0 deletions trunk/include/linux/tracehook.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,32 @@ static inline void tracehook_report_vfork_done(struct task_struct *child,
ptrace_event(PT_TRACE_VFORK_DONE, PTRACE_EVENT_VFORK_DONE, pid);
}

/**
* tracehook_prepare_release_task - task is being reaped, clean up tracing
* @task: task in %EXIT_DEAD state
*
* This is called in release_task() just before @task gets finally reaped
* and freed. This would be the ideal place to remove and clean up any
* tracing-related state for @task.
*
* Called with no locks held.
*/
static inline void tracehook_prepare_release_task(struct task_struct *task)
{
}

/**
* tracehook_finish_release_task - task is being reaped, clean up tracing
* @task: task in %EXIT_DEAD state
*
* This is called in release_task() when @task is being in the middle of
* being reaped. After this, there must be no tracing entanglements.
*
* Called with write_lock_irq(&tasklist_lock) held.
*/
static inline void tracehook_finish_release_task(struct task_struct *task)
{
ptrace_release_task(task);
}

#endif /* <linux/tracehook.h> */
21 changes: 9 additions & 12 deletions trunk/kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,27 +163,17 @@ static void delayed_put_task_struct(struct rcu_head *rhp)
put_task_struct(container_of(rhp, struct task_struct, rcu));
}

/*
* Do final ptrace-related cleanup of a zombie being reaped.
*
* Called with write_lock(&tasklist_lock) held.
*/
static void ptrace_release_task(struct task_struct *p)
{
BUG_ON(!list_empty(&p->ptraced));
ptrace_unlink(p);
BUG_ON(!list_empty(&p->ptrace_entry));
}

void release_task(struct task_struct * p)
{
struct task_struct *leader;
int zap_leader;
repeat:
tracehook_prepare_release_task(p);
atomic_dec(&p->user->processes);
proc_flush_task(p);
write_lock_irq(&tasklist_lock);
ptrace_release_task(p);
tracehook_finish_release_task(p);
__exit_signal(p);

/*
Expand All @@ -205,6 +195,13 @@ void release_task(struct task_struct * p)
* that case.
*/
zap_leader = task_detached(leader);

/*
* This maintains the invariant that release_task()
* only runs on a task in EXIT_DEAD, just for sanity.
*/
if (zap_leader)
leader->exit_state = EXIT_DEAD;
}

write_unlock_irq(&tasklist_lock);
Expand Down

0 comments on commit e579f67

Please sign in to comment.