-static inline int may_ptrace_stop(void)
-{
- if (!likely(current->ptrace & PT_PTRACED))
- return 0;
-
- if (unlikely(current->parent == current->real_parent &&
- (current->ptrace & PT_ATTACHED)))
- return 0;
-
- if (unlikely(current->signal == current->parent->signal) &&
- unlikely(current->signal->flags & SIGNAL_GROUP_EXIT))
- return 0;
-
- /*
- * Are we in the middle of do_coredump?
- * If so and our tracer is also part of the coredump stopping
- * is a deadlock situation, and pointless because our tracer
- * is dead so don't allow us to stop.
- * If SIGKILL was already sent before the caller unlocked
- * ->siglock we must see ->core_waiters != 0. Otherwise it
- * is safe to enter schedule().
- */
- if (unlikely(current->mm->core_waiters) &&
- unlikely(current->mm == current->parent->mm))
- return 0;
-
- return 1;
-}
-
-/*
- * This must be called with current->sighand->siglock held.
- *
- * This should be the path for all ptrace stops.
- * We always set current->last_siginfo while stopped here.
- * That makes it a way to test a stopped process for
- * being ptrace-stopped vs being job-control-stopped.
- *
- * If we actually decide not to stop at all because the tracer is gone,
- * we leave nostop_code in current->exit_code.
- */
-static void ptrace_stop(int exit_code, int nostop_code, siginfo_t *info)
-{
- /*
- * If there is a group stop in progress,
- * we must participate in the bookkeeping.
- */
- if (current->signal->group_stop_count > 0)
- --current->signal->group_stop_count;
-
- current->last_siginfo = info;
- current->exit_code = exit_code;
-
- /* Let the debugger run. */
- set_current_state(TASK_TRACED);
- spin_unlock_irq(¤t->sighand->siglock);
- try_to_freeze();
- read_lock(&tasklist_lock);
- if (may_ptrace_stop()) {
- do_notify_parent_cldstop(current, CLD_TRAPPED);
- read_unlock(&tasklist_lock);
- schedule();
- } else {
- /*
- * By the time we got the lock, our tracer went away.
- * Don't stop here.
- */
- read_unlock(&tasklist_lock);
- set_current_state(TASK_RUNNING);
- current->exit_code = nostop_code;
- }
-
- /*
- * We are back. Now reacquire the siglock before touching
- * last_siginfo, so that we are sure to have synchronized with
- * any signal-sending on another CPU that wants to examine it.
- */
- spin_lock_irq(¤t->sighand->siglock);
- current->last_siginfo = NULL;
-
- /*
- * Queued signals ignored us while we were stopped for tracing.
- * So check for any that we should take before resuming user mode.
- */
- recalc_sigpending();
-}
-
-void ptrace_notify(int exit_code)
-{
- siginfo_t info;
-
- BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
-
- memset(&info, 0, sizeof info);
- info.si_signo = SIGTRAP;
- info.si_code = exit_code;
- info.si_pid = current->pid;
- info.si_uid = current->uid;
-
- /* Let the debugger run. */
- spin_lock_irq(¤t->sighand->siglock);
- ptrace_stop(exit_code, 0, &info);
- spin_unlock_irq(¤t->sighand->siglock);
-}
-