Skip to content

Commit

Permalink
ptrace: kill task_ptrace()
Browse files Browse the repository at this point in the history
task_ptrace(task) simply dereferences task->ptrace and isn't even used
consistently only adding confusion.  Kill it and directly access
->ptrace instead.

This doesn't introduce any behavior change.

Signed-off-by: Tejun Heo <[email protected]>
Signed-off-by: Oleg Nesterov <[email protected]>
  • Loading branch information
htejun authored and oleg-nesterov committed Jun 22, 2011
1 parent 544b2c9 commit d21142e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 32 deletions.
11 changes: 0 additions & 11 deletions include/linux/ptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,6 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
unsigned long data);

/**
* task_ptrace - return %PT_* flags that apply to a task
* @task: pointer to &task_struct in question
*
* Returns the %PT_* flags that apply to @task.
*/
static inline int task_ptrace(struct task_struct *task)
{
return task->ptrace;
}

/**
* ptrace_event - possibly stop for a ptrace event notification
* @mask: %PT_* bit to check in @current->ptrace
Expand Down
16 changes: 8 additions & 8 deletions include/linux/tracehook.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ struct linux_binprm;
*/
static inline int tracehook_expect_breakpoints(struct task_struct *task)
{
return (task_ptrace(task) & PT_PTRACED) != 0;
return (task->ptrace & PT_PTRACED) != 0;
}

/*
* ptrace report for syscall entry and exit looks identical.
*/
static inline void ptrace_report_syscall(struct pt_regs *regs)
{
int ptrace = task_ptrace(current);
int ptrace = current->ptrace;

if (!(ptrace & PT_PTRACED))
return;
Expand Down Expand Up @@ -155,7 +155,7 @@ static inline void tracehook_report_syscall_exit(struct pt_regs *regs, int step)
static inline int tracehook_unsafe_exec(struct task_struct *task)
{
int unsafe = 0;
int ptrace = task_ptrace(task);
int ptrace = task->ptrace;
if (ptrace & PT_PTRACED) {
if (ptrace & PT_PTRACE_CAP)
unsafe |= LSM_UNSAFE_PTRACE_CAP;
Expand All @@ -178,7 +178,7 @@ static inline int tracehook_unsafe_exec(struct task_struct *task)
*/
static inline struct task_struct *tracehook_tracer_task(struct task_struct *tsk)
{
if (task_ptrace(tsk) & PT_PTRACED)
if (tsk->ptrace & PT_PTRACED)
return rcu_dereference(tsk->parent);
return NULL;
}
Expand All @@ -202,7 +202,7 @@ static inline void tracehook_report_exec(struct linux_binfmt *fmt,
struct pt_regs *regs)
{
if (!ptrace_event(PT_TRACE_EXEC, PTRACE_EVENT_EXEC, 0) &&
unlikely(task_ptrace(current) & PT_PTRACED))
unlikely(current->ptrace & PT_PTRACED))
send_sig(SIGTRAP, current, 0);
}

Expand Down Expand Up @@ -285,7 +285,7 @@ static inline void tracehook_report_clone(struct pt_regs *regs,
unsigned long clone_flags,
pid_t pid, struct task_struct *child)
{
if (unlikely(task_ptrace(child))) {
if (unlikely(child->ptrace)) {
/*
* It doesn't matter who attached/attaching to this
* task, the pending SIGSTOP is right in any case.
Expand Down Expand Up @@ -403,7 +403,7 @@ static inline void tracehook_signal_handler(int sig, siginfo_t *info,
static inline int tracehook_consider_ignored_signal(struct task_struct *task,
int sig)
{
return (task_ptrace(task) & PT_PTRACED) != 0;
return (task->ptrace & PT_PTRACED) != 0;
}

/**
Expand All @@ -422,7 +422,7 @@ static inline int tracehook_consider_ignored_signal(struct task_struct *task,
static inline int tracehook_consider_fatal_signal(struct task_struct *task,
int sig)
{
return (task_ptrace(task) & PT_PTRACED) != 0;
return (task->ptrace & PT_PTRACED) != 0;
}

#define DEATH_REAP -1
Expand Down
8 changes: 4 additions & 4 deletions kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ static void reparent_leader(struct task_struct *father, struct task_struct *p,
p->exit_signal = SIGCHLD;

/* If it has exited notify the new parent about this child's death. */
if (!task_ptrace(p) &&
if (!p->ptrace &&
p->exit_state == EXIT_ZOMBIE && thread_group_empty(p)) {
do_notify_parent(p, p->exit_signal);
if (task_detached(p)) {
Expand Down Expand Up @@ -795,7 +795,7 @@ static void forget_original_parent(struct task_struct *father)
do {
t->real_parent = reaper;
if (t->parent == father) {
BUG_ON(task_ptrace(t));
BUG_ON(t->ptrace);
t->parent = t->real_parent;
}
if (t->pdeath_signal)
Expand Down Expand Up @@ -1565,7 +1565,7 @@ static int wait_consider_task(struct wait_opts *wo, int ptrace,
* Notification and reaping will be cascaded to the real
* parent when the ptracer detaches.
*/
if (likely(!ptrace) && unlikely(task_ptrace(p))) {
if (likely(!ptrace) && unlikely(p->ptrace)) {
/* it will become visible, clear notask_error */
wo->notask_error = 0;
return 0;
Expand Down Expand Up @@ -1608,7 +1608,7 @@ static int wait_consider_task(struct wait_opts *wo, int ptrace,
* own children, it should create a separate process which
* takes the role of real parent.
*/
if (likely(!ptrace) && task_ptrace(p) &&
if (likely(!ptrace) && p->ptrace &&
same_thread_group(p->parent, p->real_parent))
return 0;

Expand Down
14 changes: 7 additions & 7 deletions kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ int do_notify_parent(struct task_struct *tsk, int sig)
/* do_notify_parent_cldstop should have been called instead. */
BUG_ON(task_is_stopped_or_traced(tsk));

BUG_ON(!task_ptrace(tsk) &&
BUG_ON(!tsk->ptrace &&
(tsk->group_leader != tsk || !thread_group_empty(tsk)));

info.si_signo = sig;
Expand Down Expand Up @@ -1631,7 +1631,7 @@ int do_notify_parent(struct task_struct *tsk, int sig)

psig = tsk->parent->sighand;
spin_lock_irqsave(&psig->siglock, flags);
if (!task_ptrace(tsk) && sig == SIGCHLD &&
if (!tsk->ptrace && sig == SIGCHLD &&
(psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN ||
(psig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT))) {
/*
Expand Down Expand Up @@ -1731,7 +1731,7 @@ static void do_notify_parent_cldstop(struct task_struct *tsk,

static inline int may_ptrace_stop(void)
{
if (!likely(task_ptrace(current)))
if (!likely(current->ptrace))
return 0;
/*
* Are we in the middle of do_coredump?
Expand Down Expand Up @@ -1989,7 +1989,7 @@ static bool do_signal_stop(int signr)
if (!(sig->flags & SIGNAL_STOP_STOPPED))
sig->group_exit_code = signr;
else
WARN_ON_ONCE(!task_ptrace(current));
WARN_ON_ONCE(!current->ptrace);

sig->group_stop_count = 0;

Expand All @@ -2014,7 +2014,7 @@ static bool do_signal_stop(int signr)
}
}

if (likely(!task_ptrace(current))) {
if (likely(!current->ptrace)) {
int notify = 0;

/*
Expand Down Expand Up @@ -2093,7 +2093,7 @@ static void do_jobctl_trap(void)
static int ptrace_signal(int signr, siginfo_t *info,
struct pt_regs *regs, void *cookie)
{
if (!task_ptrace(current))
if (!current->ptrace)
return signr;

ptrace_signal_deliver(regs, cookie);
Expand Down Expand Up @@ -2179,7 +2179,7 @@ int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka,
do_notify_parent_cldstop(current, false, why);

leader = current->group_leader;
if (task_ptrace(leader) && !real_parent_is_ptracer(leader))
if (leader->ptrace && !real_parent_is_ptracer(leader))
do_notify_parent_cldstop(leader, true, why);

read_unlock(&tasklist_lock);
Expand Down
3 changes: 1 addition & 2 deletions mm/oom_kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
* then wait for it to finish before killing
* some other task unnecessarily.
*/
if (!(task_ptrace(p->group_leader) &
PT_TRACE_EXIT))
if (!(p->group_leader->ptrace & PT_TRACE_EXIT))
return ERR_PTR(-1UL);
}
}
Expand Down

0 comments on commit d21142e

Please sign in to comment.