rpms/kernel/devel linux-2.6-utrace-ptrace.patch, NONE, 1.1 kernel.spec, 1.1872, 1.1873 linux-2.6-tracehook.patch, 1.9, 1.10 linux-2.6-utrace.patch, 1.118, 1.119

roland roland at fedoraproject.org
Wed Dec 16 22:09:43 UTC 2009


Author: roland

Update of /cvs/pkgs/rpms/kernel/devel
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv25951

Modified Files:
	kernel.spec linux-2.6-tracehook.patch linux-2.6-utrace.patch 
Added Files:
	linux-2.6-utrace-ptrace.patch 
Log Message:
utrace update, now testing the utrace-based ptrace!

linux-2.6-utrace-ptrace.patch:
 include/linux/ptrace.h |    2 
 kernel/Makefile        |    1 
 kernel/ptrace-utrace.c | 1080 +++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/ptrace.c        |  597 +++++++++++++--------------
 kernel/utrace.c        |   16 
 5 files changed, 1391 insertions(+), 305 deletions(-)

--- NEW FILE linux-2.6-utrace-ptrace.patch ---
utrace: ptrace cooperation

This adds the CONFIG_UTRACE_PTRACE option under CONFIG_UTRACE.
When set, parts of ptrace are replaced so it uses the utrace
facilities for noticing events, stopping and resuming threads.

This makes ptrace play nicely with other utrace-based things
tracing the same threads.  It also makes all ptrace uses rely on
some of the utrace code working right, even when you are not
using any other utrace-based things.  So it's experimental and
not real well proven yet.  But it's recommended if you enable
CONFIG_UTRACE and want to try new utrace things.

Signed-off-by: Roland McGrath <roland at redhat.com>
---
 include/linux/ptrace.h |    2 +-
 kernel/Makefile        |    1 +
 kernel/ptrace-utrace.c | 1080 ++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/ptrace.c        |  572 +++++++++++++-------------
 kernel/utrace.c        |   16 +
 5 files changed, 1378 insertions(+), 293 deletions(-)

diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
index 4802e2a..03f8fc7 100644  
--- a/include/linux/ptrace.h
+++ b/include/linux/ptrace.h
@@ -79,7 +79,7 @@
 #include <linux/compiler.h>		/* For unlikely.  */
 #include <linux/sched.h>		/* For struct task_struct.  */
 
-
+extern void ptrace_notify_stop(struct task_struct *tracee);
 extern long arch_ptrace(struct task_struct *child, long request, long addr, long data);
 extern int ptrace_traceme(void);
 extern int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len);
diff --git a/kernel/Makefile b/kernel/Makefile
index 263bb19..42cb1ec 100644  
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -69,6 +69,7 @@ obj-$(CONFIG_RESOURCE_COUNTERS) += res_c
 obj-$(CONFIG_STOP_MACHINE) += stop_machine.o
 obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o
 obj-$(CONFIG_UTRACE) += utrace.o
+obj-$(CONFIG_UTRACE) += ptrace-utrace.o
 obj-$(CONFIG_AUDIT) += audit.o auditfilter.o audit_watch.o
 obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
 obj-$(CONFIG_GCOV_KERNEL) += gcov/
diff --git a/kernel/ptrace-utrace.c b/kernel/ptrace-utrace.c
new file mode 100644
index ...ea419ee 100644  
--- /dev/null
+++ b/kernel/ptrace-utrace.c
@@ -0,0 +1,1080 @@
+/*
+ * linux/kernel/ptrace.c
+ *
+ * (C) Copyright 1999 Linus Torvalds
+ *
+ * Common interfaces for "ptrace()" which we do not want
+ * to continually duplicate across every architecture.
+ */
+
+#include <linux/capability.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/errno.h>
+#include <linux/mm.h>
+#include <linux/highmem.h>
+#include <linux/pagemap.h>
+#include <linux/smp_lock.h>
+#include <linux/ptrace.h>
+#include <linux/utrace.h>
+#include <linux/security.h>
+#include <linux/signal.h>
+#include <linux/audit.h>
+#include <linux/pid_namespace.h>
+#include <linux/syscalls.h>
+#include <linux/uaccess.h>
+
+/*
+ * ptrace a task: make the debugger its new parent and
+ * move it to the ptrace list.
+ *
+ * Must be called with the tasklist lock write-held.
+ */
+void __ptrace_link(struct task_struct *child, struct task_struct *new_parent)
+{
+	BUG_ON(!list_empty(&child->ptrace_entry));
+	list_add(&child->ptrace_entry, &new_parent->ptraced);
+	child->parent = new_parent;
+}
+
+/*
+ * unptrace a task: move it back to its original parent and
+ * remove it from the ptrace list.
+ *
+ * Must be called with the tasklist lock write-held.
+ */
+void __ptrace_unlink(struct task_struct *child)
+{
+	BUG_ON(!child->ptrace);
+
+	child->ptrace = 0;
+	child->parent = child->real_parent;
+	list_del_init(&child->ptrace_entry);
+
+	arch_ptrace_untrace(child);
+}
+
+struct ptrace_context {
+	int				options;
+
+	int				signr;
+	siginfo_t			*siginfo;
+
+	int				stop_code;
+	unsigned long			eventmsg;
+
+	enum utrace_resume_action	resume;
+};
+
+#define PT_UTRACED			0x00001000
+
+#define PTRACE_O_SYSEMU			0x100
+
+#define PTRACE_EVENT_SYSCALL		(1 << 16)
+#define PTRACE_EVENT_SIGTRAP		(2 << 16)
+#define PTRACE_EVENT_SIGNAL		(3 << 16)
+/* events visible to user-space */
+#define PTRACE_EVENT_MASK		0xFFFF
+
+static inline bool ptrace_event_pending(struct ptrace_context *ctx)
+{
+	return ctx->stop_code != 0;
+}
+
+static inline int get_stop_event(struct ptrace_context *ctx)
+{
+	return ctx->stop_code >> 8;
+}
+
+static inline void set_stop_code(struct ptrace_context *ctx, int event)
+{
+	ctx->stop_code = (event << 8) | SIGTRAP;
+}
+
+static inline struct ptrace_context *
+ptrace_context(struct utrace_engine *engine)
+{
+	return engine->data;
+}
+
+static const struct utrace_engine_ops ptrace_utrace_ops; /* forward decl */
+
+static struct utrace_engine *ptrace_lookup_engine(struct task_struct *tracee)
+{
+	return utrace_attach_task(tracee, UTRACE_ATTACH_MATCH_OPS,
+					&ptrace_utrace_ops, NULL);
+}
+
+static struct utrace_engine *
+ptrace_reuse_engine(struct task_struct *tracee)
+{
+	struct utrace_engine *engine;
+	struct ptrace_context *ctx;
+	int err = -EPERM;
+
+	engine = ptrace_lookup_engine(tracee);
+	if (IS_ERR(engine))
+		return engine;
+
+	ctx = ptrace_context(engine);
+	if (unlikely(ctx->resume == UTRACE_DETACH)) {
+		/*
+		 * Try to reuse this self-detaching engine.
+		 * The only caller which can hit this case is ptrace_attach(),
+		 * it holds ->cred_guard_mutex.
+		 */
+		ctx->options = 0;
+		ctx->eventmsg = 0;
+
+		/* make sure we don't get unwanted reports */
+		err = utrace_set_events(tracee, engine, UTRACE_EVENT(QUIESCE));
+		if (!err || err == -EINPROGRESS) {
+			ctx->resume = UTRACE_RESUME;
+			/* synchronize with ptrace_report_signal() */
+			err = utrace_barrier(tracee, engine);
+		}
+		WARN_ON(!err != (engine->ops == &ptrace_utrace_ops));
+
+		if (!err)
+			return engine;
+	}
+
+	utrace_engine_put(engine);
+	return ERR_PTR(err);
+}
+
+static struct utrace_engine *
+ptrace_attach_engine(struct task_struct *tracee)
+{
+	struct utrace_engine *engine;
+	struct ptrace_context *ctx;
+
+	if (unlikely(task_utrace_flags(tracee))) {
+		engine = ptrace_reuse_engine(tracee);
+		if (!IS_ERR(engine) || IS_ERR(engine) == -EPERM)
+			return engine;
+	}
+
+	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+	if (unlikely(!ctx))
+		return ERR_PTR(-ENOMEM);
+
+	ctx->resume = UTRACE_RESUME;
+
+	engine = utrace_attach_task(tracee, UTRACE_ATTACH_CREATE |
+						UTRACE_ATTACH_EXCLUSIVE |
+						UTRACE_ATTACH_MATCH_OPS,
+						&ptrace_utrace_ops, ctx);
+	if (unlikely(IS_ERR(engine))) {
+		if (engine != ERR_PTR(-ESRCH) &&
+		    engine != ERR_PTR(-ERESTARTNOINTR))
+			engine = ERR_PTR(-EPERM);
+		kfree(ctx);
+	}
+
+	return engine;
+}
+
+static inline int ptrace_set_events(struct task_struct *target,
+					struct utrace_engine *engine,
+					unsigned long options)
+{
+	struct ptrace_context *ctx = ptrace_context(engine);
+	/*
+	 * We need QUIESCE for resume handling, CLONE to check
+	 * for CLONE_PTRACE, other events are always reported.
+	 */
+	unsigned long events = UTRACE_EVENT(QUIESCE) | UTRACE_EVENT(CLONE) |
+			       UTRACE_EVENT(EXEC) | UTRACE_EVENT_SIGNAL_ALL;
+
+	ctx->options = options;
+	if (options & PTRACE_O_TRACEEXIT)
+		events |= UTRACE_EVENT(EXIT);
+
+	return utrace_set_events(target, engine, events);
+}
+
+/*
+ * Attach a utrace engine for ptrace and set up its event mask.
+ * Returns error code or 0 on success.
+ */
+static int ptrace_attach_task(struct task_struct *tracee, int options)
+{
+	struct utrace_engine *engine;
+	int err;
+
+	engine = ptrace_attach_engine(tracee);
+	if (IS_ERR(engine))
+		return PTR_ERR(engine);
+	/*
+	 * It can fail only if the tracee is dead, the caller
+	 * must notice this before setting PT_UTRACED.
+	 */
+	err = ptrace_set_events(tracee, engine, options);
+	WARN_ON(err && !tracee->exit_state);
+	utrace_engine_put(engine);
+	return 0;
+}
+
+static int ptrace_wake_up(struct task_struct *tracee,
+				struct utrace_engine *engine,
+				enum utrace_resume_action action,
+				bool force_wakeup)
+{
+	if (force_wakeup) {
+		unsigned long flags;
+		/*
+		 * Preserve the compatibility bug. Historically ptrace
+		 * wakes up the tracee even if it should not. Clear
+		 * SIGNAL_STOP_STOPPED for utrace_wakeup().
+		 */
+		if (lock_task_sighand(tracee, &flags)) {
+			tracee->signal->flags &= ~SIGNAL_STOP_STOPPED;
+			unlock_task_sighand(tracee, &flags);
+		}
+	}
+
+	if (action != UTRACE_REPORT)
+		ptrace_context(engine)->stop_code = 0;
+
+	return utrace_control(tracee, engine, action);
+}
+
+static void ptrace_detach_task(struct task_struct *tracee, int sig)
+{
+	/*
+	 * If true, the caller is PTRACE_DETACH, otherwise
+	 * the tracer detaches implicitly during exit.
+	 */
+	bool voluntary = (sig >= 0);
+	struct utrace_engine *engine = ptrace_lookup_engine(tracee);
+	enum utrace_resume_action action = UTRACE_DETACH;
+
+	if (unlikely(IS_ERR(engine)))
+		return;
+
+	if (sig) {
+		struct ptrace_context *ctx = ptrace_context(engine);
+
+		switch (get_stop_event(ctx)) {
+		case PTRACE_EVENT_SYSCALL:
+			if (voluntary)
+				send_sig_info(sig, SEND_SIG_PRIV, tracee);
+			break;
+
+		case PTRACE_EVENT_SIGNAL:
+			if (voluntary)
+				ctx->signr = sig;
+			ctx->resume = UTRACE_DETACH;
+			action = UTRACE_RESUME;
+			break;
+		}
+	}
+
+	ptrace_wake_up(tracee, engine, action, voluntary);
+	utrace_engine_put(engine);
+}
+
+static void ptrace_abort_attach(struct task_struct *tracee)
+{
+	ptrace_detach_task(tracee, 0);
+}
+
+static u32 ptrace_report_exit(u32 action, struct utrace_engine *engine,
+			      long orig_code, long *code)
+{
+	struct ptrace_context *ctx = ptrace_context(engine);
+
+	WARN_ON(ptrace_event_pending(ctx) &&
+		!signal_group_exit(current->signal));
+
+	set_stop_code(ctx, PTRACE_EVENT_EXIT);
+	ctx->eventmsg = *code;
+
+	return UTRACE_STOP;
+}
+
+static void ptrace_clone_attach(struct task_struct *child,
+				int options)
+{
+	struct task_struct *parent = current;
+	struct task_struct *tracer;
+	bool abort = true;
+
+	if (unlikely(ptrace_attach_task(child, options))) {
+		WARN_ON(1);
+		return;
+	}
+
+	write_lock_irq(&tasklist_lock);
+	tracer = parent->parent;
+	if (!(tracer->flags & PF_EXITING) && parent->ptrace) {
+		child->ptrace = parent->ptrace;
+		__ptrace_link(child, tracer);
+		abort = false;
+	}
+	write_unlock_irq(&tasklist_lock);
+	if (unlikely(abort)) {
+		ptrace_abort_attach(child);
+		return;
+	}
+
+	sigaddset(&child->pending.signal, SIGSTOP);
+	set_tsk_thread_flag(child, TIF_SIGPENDING);
+}
+
+static u32 ptrace_report_clone(u32 action, struct utrace_engine *engine,
+			       unsigned long clone_flags,
+			       struct task_struct *child)
+{
+	struct ptrace_context *ctx = ptrace_context(engine);
+	int event = 0;
+
+	WARN_ON(ptrace_event_pending(ctx));
+
+	if (clone_flags & CLONE_UNTRACED) {
+		/* no events reported */
+	} else if (clone_flags & CLONE_VFORK) {
+		if (ctx->options & PTRACE_O_TRACEVFORK)
+			event = PTRACE_EVENT_VFORK;
+		else if (ctx->options & PTRACE_O_TRACEVFORKDONE)
+			event = PTRACE_EVENT_VFORK_DONE;
+	} else if ((clone_flags & CSIGNAL) != SIGCHLD) {
+		if (ctx->options & PTRACE_O_TRACECLONE)
+			event = PTRACE_EVENT_CLONE;
+	} else if (ctx->options & PTRACE_O_TRACEFORK) {
+		event = PTRACE_EVENT_FORK;
+	}
+	/*
+	 * Any of these reports implies auto-attaching the new child.
+	 * So does CLONE_PTRACE, even with no event to report.
+	 */
+	if ((event && event != PTRACE_EVENT_VFORK_DONE) ||
+				(clone_flags & CLONE_PTRACE))
+		ptrace_clone_attach(child, ctx->options);
+
+	if (!event)
+		return UTRACE_RESUME;
+
+	set_stop_code(ctx, event);
+	ctx->eventmsg = child->pid;
+	/*
+	 * We shouldn't stop now, inside the do_fork() path.
+	 * We will stop later, before return to user-mode.
+	 */
+	if (event == PTRACE_EVENT_VFORK_DONE)
+		return UTRACE_REPORT;
+	else
+		return UTRACE_STOP;
+}
+
+static inline void set_syscall_code(struct ptrace_context *ctx)
+{
+	set_stop_code(ctx, PTRACE_EVENT_SYSCALL);
+	if (ctx->options & PTRACE_O_TRACESYSGOOD)
+		ctx->stop_code |= 0x80;
+}
+
+static u32 ptrace_report_syscall_entry(u32 action, struct utrace_engine *engine,
+				       struct pt_regs *regs)
+{
+	struct ptrace_context *ctx = ptrace_context(engine);
+
+	if (action & UTRACE_SYSCALL_RESUMED) {
+		/*
+		 * We already reported the first time.
+		 * Nothing more to do now.
+		 */
+		if (unlikely(ctx->options & PTRACE_O_SYSEMU))
+			return UTRACE_SYSCALL_ABORT | UTRACE_REPORT;
+		return utrace_syscall_action(action) | UTRACE_RESUME;
+	}
+
+	WARN_ON(ptrace_event_pending(ctx));
+
+	set_syscall_code(ctx);
+
+	if (unlikely(ctx->options & PTRACE_O_SYSEMU))
+		return UTRACE_SYSCALL_ABORT | UTRACE_REPORT;
+	/*
+	 * Stop now to report.  We will get another callback after
+	 * we resume, with the UTRACE_SYSCALL_RESUMED flag set.
+	 */
+	return UTRACE_SYSCALL_RUN | UTRACE_STOP;
+}
+
+static u32 ptrace_report_syscall_exit(u32 action, struct utrace_engine *engine,
+				      struct pt_regs *regs)
+{
+	struct ptrace_context *ctx = ptrace_context(engine);
+
+	if (ptrace_event_pending(ctx))
+		return UTRACE_STOP;
+
+	if (ctx->resume != UTRACE_RESUME) {
+		WARN_ON(ctx->resume != UTRACE_BLOCKSTEP &&
+			ctx->resume != UTRACE_SINGLESTEP);
+		ctx->resume = UTRACE_RESUME;
+
+		ctx->signr = SIGTRAP;
+		return UTRACE_INTERRUPT;
+	}
+
+	set_syscall_code(ctx);
+	return UTRACE_STOP;
+}
+
+static u32 ptrace_report_exec(u32 action, struct utrace_engine *engine,
+			      const struct linux_binfmt *fmt,
+			      const struct linux_binprm *bprm,
+			      struct pt_regs *regs)
+{
+	struct ptrace_context *ctx = ptrace_context(engine);
+
+	WARN_ON(ptrace_event_pending(ctx));
+
+	if (!(ctx->options & PTRACE_O_TRACEEXEC)) {
+		/*
+		 * Old-fashioned ptrace'd exec just posts a plain signal.
+		 */
+		send_sig(SIGTRAP, current, 0);
+		return UTRACE_RESUME;
+	}
+
+	set_stop_code(ctx, PTRACE_EVENT_EXEC);
+	return UTRACE_STOP;
+}
+
+static enum utrace_signal_action resume_signal(struct ptrace_context *ctx,
+					       struct k_sigaction *return_ka)
+{
+	siginfo_t *info = ctx->siginfo;
+	int signr = ctx->signr;
+
+	ctx->siginfo = NULL;
+	ctx->signr = 0;
+
+	/* Did the debugger cancel the sig? */
+	if (!signr)
+		return UTRACE_SIGNAL_IGN;
+	/*
+	 * Update the siginfo structure if the signal has changed.
+	 * If the debugger wanted something specific in the siginfo
+	 * then it should have updated *info via PTRACE_SETSIGINFO.
+	 */
+	if (info->si_signo != signr) {
+		info->si_signo = signr;
+		info->si_errno = 0;
+		info->si_code = SI_USER;
+		info->si_pid = task_pid_vnr(current->parent);
+		info->si_uid = task_uid(current->parent);
+	}
+
+	/* If the (new) signal is now blocked, requeue it. */
+	if (sigismember(&current->blocked, signr)) {
+		send_sig_info(signr, info, current);
+		return UTRACE_SIGNAL_IGN;
+	}
+
+	spin_lock_irq(&current->sighand->siglock);
+	*return_ka = current->sighand->action[signr - 1];
+	spin_unlock_irq(&current->sighand->siglock);
+
+	return UTRACE_SIGNAL_DELIVER;
+}
+
+static u32 ptrace_report_signal(u32 action, struct utrace_engine *engine,
+				struct pt_regs *regs,
+				siginfo_t *info,
+				const struct k_sigaction *orig_ka,
+				struct k_sigaction *return_ka)
+{
+	struct ptrace_context *ctx = ptrace_context(engine);
+	enum utrace_resume_action resume = ctx->resume;
+
+	if (ptrace_event_pending(ctx)) {
+		action = utrace_signal_action(action);
+		WARN_ON(action != UTRACE_SIGNAL_REPORT);
+		return action | UTRACE_STOP;
+	}
+
+	switch (utrace_signal_action(action)) {
+	case UTRACE_SIGNAL_HANDLER:
+		if (WARN_ON(ctx->siginfo))
+			ctx->siginfo = NULL;
+
+		if (resume != UTRACE_RESUME) {
+			WARN_ON(resume != UTRACE_BLOCKSTEP &&
+				resume != UTRACE_SINGLESTEP);
+
+			set_stop_code(ctx, PTRACE_EVENT_SIGTRAP);
+			return UTRACE_STOP | UTRACE_SIGNAL_IGN;
+		}
+
+	case UTRACE_SIGNAL_REPORT:
+		if (!ctx->siginfo) {
+			if (ctx->signr) {
+				/* set by ptrace_resume(SYSCALL_EXIT) */
+				WARN_ON(ctx->signr != SIGTRAP);
+				user_single_step_siginfo(current, regs, info);
+				force_sig_info(SIGTRAP, info, current);
+			}
+
+			return resume | UTRACE_SIGNAL_IGN;
+		}
+
+		if (WARN_ON(ctx->siginfo != info))
+			return resume | UTRACE_SIGNAL_IGN;
+
+		return resume | resume_signal(ctx, return_ka);
+
+	default:
+		break;
+	}
+
+	WARN_ON(ctx->siginfo);
+	ctx->siginfo = info;
+	/*
+	 * ctx->siginfo points to the caller's stack.
+	 * Make sure the subsequent UTRACE_SIGNAL_REPORT clears
+	 * ->siginfo before return from get_signal_to_deliver().
+	 */
+	if (utrace_control(current, engine, UTRACE_INTERRUPT))
+		WARN_ON(1);
+
+	ctx->signr = info->si_signo;
+	ctx->stop_code = (PTRACE_EVENT_SIGNAL << 8) | ctx->signr;
+
+	return UTRACE_STOP | UTRACE_SIGNAL_IGN;
+}
+
+static u32 ptrace_report_quiesce(u32 action, struct utrace_engine *engine,
+				 unsigned long event)
+{
+	struct ptrace_context *ctx = ptrace_context(engine);
+
+	if (ptrace_event_pending(ctx))
+		return UTRACE_STOP;
+
+	return event ? UTRACE_RESUME : ctx->resume;
+}
+
+static void ptrace_release(void *data)
+{
+	kfree(data);
+}
+
+static const struct utrace_engine_ops ptrace_utrace_ops = {
+	.report_signal = ptrace_report_signal,
+	.report_quiesce = ptrace_report_quiesce,
+	.report_exec = ptrace_report_exec,
+	.report_exit = ptrace_report_exit,
+	.report_clone = ptrace_report_clone,
+	.report_syscall_entry = ptrace_report_syscall_entry,
+	.report_syscall_exit = ptrace_report_syscall_exit,
+	.release = ptrace_release,
+};
+
+int ptrace_check_attach(struct task_struct *child, int kill)
+{
+	struct utrace_engine *engine;
+	struct utrace_examiner exam;
+	int ret = -ESRCH;
+
+	engine = ptrace_lookup_engine(child);
+	if (IS_ERR(engine))
+		return ret;
+
+	if (child->parent != current)
+		goto out;
+
+	if (unlikely(kill))
+		ret = 0;
+
+	if (!task_is_stopped_or_traced(child))
+		goto out;
+	/*
+	 * Make sure our engine has already stopped the child.
+	 * Then wait for it to be off the CPU.
+	 */
+	if (!utrace_control(child, engine, UTRACE_STOP) &&
+	    !utrace_prepare_examine(child, engine, &exam))
+		ret = 0;
+out:
+	utrace_engine_put(engine);
+	return ret;
+}
+
+int ptrace_attach(struct task_struct *task)
+{
+	int retval;
+
+	audit_ptrace(task);
+
+	retval = -EPERM;
+	if (unlikely(task->flags & PF_KTHREAD))
+		goto out;
+	if (same_thread_group(task, current))
+		goto out;
+
+	/*
+	 * Protect exec's credential calculations against our interference;
+	 * interference; SUID, SGID and LSM creds get determined differently
+	 * under ptrace.
+	 */
+	retval = -ERESTARTNOINTR;
+	if (mutex_lock_interruptible(&task->cred_guard_mutex))
+		goto out;
+
+	task_lock(task);
+	retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
+	task_unlock(task);
+	if (retval)
+		goto unlock_creds;
+
+	retval = ptrace_attach_task(task, 0);
+	if (unlikely(retval))
+		goto unlock_creds;
+
+	write_lock_irq(&tasklist_lock);
+	retval = -EPERM;
+	if (unlikely(task->exit_state))
+		goto unlock_tasklist;
+
+	BUG_ON(task->ptrace);
+	task->ptrace = PT_UTRACED;
+	if (capable(CAP_SYS_PTRACE))
+		task->ptrace |= PT_PTRACE_CAP;
+
+	__ptrace_link(task, current);
+	send_sig_info(SIGSTOP, SEND_SIG_FORCED, task);
+
+	retval = 0;
+unlock_tasklist:
+	write_unlock_irq(&tasklist_lock);
+unlock_creds:
+	mutex_unlock(&task->cred_guard_mutex);
+out:
+	return retval;
+}
+
+/*
+ * Performs checks and sets PT_UTRACED.
+ * Should be used by all ptrace implementations for PTRACE_TRACEME.
+ */
+int ptrace_traceme(void)
+{
+	bool detach = true;
+	int ret = ptrace_attach_task(current, 0);
+
+	if (unlikely(ret))
+		return ret;
+
+	ret = -EPERM;
+	write_lock_irq(&tasklist_lock);
+	BUG_ON(current->ptrace);
+	ret = security_ptrace_traceme(current->parent);
+	/*
+	 * Check PF_EXITING to ensure ->real_parent has not passed
+	 * exit_ptrace(). Otherwise we don't report the error but
+	 * pretend ->real_parent untraces us right after return.
+	 */
+	if (!ret && !(current->real_parent->flags & PF_EXITING)) {
+		current->ptrace = PT_UTRACED;
+		__ptrace_link(current, current->real_parent);
+		detach = false;
+	}
+	write_unlock_irq(&tasklist_lock);
+
+	if (detach)
+		ptrace_abort_attach(current);
+	return ret;
+}
+
+static void ptrace_do_detach(struct task_struct *tracee, unsigned int data)
+{
+	bool detach, release;
+
+	write_lock_irq(&tasklist_lock);
+	/*
+	 * This tracee can be already killed. Make sure de_thread() or
+	 * our sub-thread doing do_wait() didn't do release_task() yet.
+	 */
+	detach = tracee->ptrace != 0;
+	release = false;
+	if (likely(detach))
+		release = __ptrace_detach(current, tracee);
+	write_unlock_irq(&tasklist_lock);
+
+	if (unlikely(release))
+		release_task(tracee);
+	else if (likely(detach))
+		ptrace_detach_task(tracee, data);
+}
+
+int ptrace_detach(struct task_struct *child, unsigned int data)
+{
+	if (!valid_signal(data))
+		return -EIO;
+
+	ptrace_do_detach(child, data);
+
+	return 0;
+}
+
+/*
+ * Detach all tasks we were using ptrace on.
+ */
+void exit_ptrace(struct task_struct *tracer)
+{
+	for (;;) {
+		struct task_struct *tracee = NULL;
+
+		read_lock(&tasklist_lock);
+		if (!list_empty(&tracer->ptraced)) {
+			tracee = list_first_entry(&tracer->ptraced,
+					struct task_struct, ptrace_entry);
+			get_task_struct(tracee);
+		}
+		read_unlock(&tasklist_lock);
+		if (!tracee)
+			break;
+
+		ptrace_do_detach(tracee, -1);
+		put_task_struct(tracee);
+	}
+}
+
+static int ptrace_set_options(struct task_struct *tracee,
+				struct utrace_engine *engine, long data)
+{
+	BUILD_BUG_ON(PTRACE_O_MASK & PTRACE_O_SYSEMU);
+
+	ptrace_set_events(tracee, engine, data & PTRACE_O_MASK);
+	return (data & ~PTRACE_O_MASK) ? -EINVAL : 0;
+}
+
+static int ptrace_rw_siginfo(struct task_struct *tracee,
+				struct ptrace_context *ctx,
+				siginfo_t *info, bool write)
+{
+	unsigned long flags;
+	int err;
+
+	switch (get_stop_event(ctx)) {
+	case 0: /* jctl stop */
+		return -EINVAL;
+
+	case PTRACE_EVENT_SIGNAL:
+		err = -ESRCH;
+		if (lock_task_sighand(tracee, &flags)) {
+			if (likely(task_is_traced(tracee))) {
+				if (write)
+					*ctx->siginfo = *info;
+				else
+					*info = *ctx->siginfo;
+				err = 0;
+			}
+			unlock_task_sighand(tracee, &flags);
+		}
+
+		return err;
+
+	default:
+		if (!write) {
+			memset(info, 0, sizeof(*info));
+			info->si_signo = SIGTRAP;
+			info->si_code = ctx->stop_code & PTRACE_EVENT_MASK;
+			info->si_pid = task_pid_vnr(tracee);
+			info->si_uid = task_uid(tracee);
+		}
+
+		return 0;
+	}
+}
+
+static void do_ptrace_notify_stop(struct ptrace_context *ctx,
+					struct task_struct *tracee)
+{
+	/*
+	 * This can race with SIGKILL, but we borrow this race from
+	 * the old ptrace implementation. ->exit_code is only needed
+	 * for wait_task_stopped()->task_stopped_code(), we should
+	 * change it to use ptrace_context.
+	 */
+	tracee->exit_code = ctx->stop_code & PTRACE_EVENT_MASK;
+	WARN_ON(!tracee->exit_code);
+
+	read_lock(&tasklist_lock);
+	/*
+	 * Don't want to allow preemption here, because
+	 * sys_ptrace() needs this task to be inactive.
+	 */
+	preempt_disable();
+	/*
+	 * It can be killed and then released by our subthread,
+	 * or ptrace_attach() has not completed yet.
+	 */
+	if (task_ptrace(tracee))
+		do_notify_parent_cldstop(tracee, CLD_TRAPPED);
+	read_unlock(&tasklist_lock);
+	preempt_enable_no_resched();
+}
+
+void ptrace_notify_stop(struct task_struct *tracee)
+{
+	struct utrace_engine *engine = ptrace_lookup_engine(tracee);
+
+	if (IS_ERR(engine))
+		return;
+
+	do_ptrace_notify_stop(ptrace_context(engine), tracee);
+	utrace_engine_put(engine);
+}
+
+static int ptrace_resume_action(struct task_struct *tracee,
+				struct utrace_engine *engine, long request)
+{
+	struct ptrace_context *ctx = ptrace_context(engine);
+	unsigned long events;
+	int action;
+
+	ctx->options &= ~PTRACE_O_SYSEMU;
+	events = engine->flags & ~UTRACE_EVENT_SYSCALL;
+	action = UTRACE_RESUME;
+
+	switch (request) {
+#ifdef PTRACE_SINGLEBLOCK
+	case PTRACE_SINGLEBLOCK:
+		if (unlikely(!arch_has_block_step()))
+			return -EIO;
+		action = UTRACE_BLOCKSTEP;
+		events |= UTRACE_EVENT(SYSCALL_EXIT);
+		break;
+#endif
+
+#ifdef PTRACE_SINGLESTEP
+	case PTRACE_SINGLESTEP:
+		if (unlikely(!arch_has_single_step()))
+			return -EIO;
+		action = UTRACE_SINGLESTEP;
+		events |= UTRACE_EVENT(SYSCALL_EXIT);
+		break;
+#endif
+
+#ifdef PTRACE_SYSEMU
+	case PTRACE_SYSEMU_SINGLESTEP:
+		if (unlikely(!arch_has_single_step()))
+			return -EIO;
+		action = UTRACE_SINGLESTEP;
+	case PTRACE_SYSEMU:
+		ctx->options |= PTRACE_O_SYSEMU;
+		events |= UTRACE_EVENT(SYSCALL_ENTRY);
+		break;
+#endif
+
+	case PTRACE_SYSCALL:
+		events |= UTRACE_EVENT_SYSCALL;
+		break;
+
+	case PTRACE_CONT:
+		break;
+	default:
+		return -EIO;
+	}
+
+	if (events != engine->flags &&
+	    utrace_set_events(tracee, engine, events))
+		return -ESRCH;
+
+	return action;
+}
+
+static int ptrace_resume(struct task_struct *tracee,
+				struct utrace_engine *engine,
+				long request, long data)
+{
+	struct ptrace_context *ctx = ptrace_context(engine);
+	int action;
+
+	if (!valid_signal(data))
+		return -EIO;
+
+	action = ptrace_resume_action(tracee, engine, request);
+	if (action < 0)
+		return action;
+
+	switch (get_stop_event(ctx)) {
+	case PTRACE_EVENT_VFORK:
+		if (ctx->options & PTRACE_O_TRACEVFORKDONE) {
+			set_stop_code(ctx, PTRACE_EVENT_VFORK_DONE);
+			action = UTRACE_REPORT;
+		}
+		break;
+
+	case PTRACE_EVENT_EXEC:
+	case PTRACE_EVENT_FORK:
+	case PTRACE_EVENT_CLONE:
+	case PTRACE_EVENT_VFORK_DONE:
+		if (request == PTRACE_SYSCALL) {
+			set_syscall_code(ctx);
+			do_ptrace_notify_stop(ctx, tracee);
+			return 0;
+		}
+
+		if (action != UTRACE_RESUME) {
+			/*
+			 * single-stepping. UTRACE_SIGNAL_REPORT will
+			 * synthesize a trap to follow the syscall insn.
+			*/
+			ctx->signr = SIGTRAP;
+			action = UTRACE_INTERRUPT;
+		}
+		break;
+
+	case PTRACE_EVENT_SYSCALL:
+		if (data)
+			send_sig_info(data, SEND_SIG_PRIV, tracee);
+		break;
+
+	case PTRACE_EVENT_SIGNAL:
+		ctx->signr = data;
+		break;
+	}
+
+	ctx->resume = action;
+	ptrace_wake_up(tracee, engine, action, true);
+	return 0;
+}
+
+int ptrace_request(struct task_struct *child, long request,
+		   long addr, long data)
+{
+	struct utrace_engine *engine = ptrace_lookup_engine(child);
+	siginfo_t siginfo;
+	int ret;
+
+	if (unlikely(IS_ERR(engine)))
+		return -ESRCH;
+
+	switch (request) {
+	case PTRACE_PEEKTEXT:
+	case PTRACE_PEEKDATA:
+		ret = generic_ptrace_peekdata(child, addr, data);
+		break;
+	case PTRACE_POKETEXT:
+	case PTRACE_POKEDATA:
+		ret = generic_ptrace_pokedata(child, addr, data);
+		break;
+
+#ifdef PTRACE_OLDSETOPTIONS
+	case PTRACE_OLDSETOPTIONS:
+#endif
+	case PTRACE_SETOPTIONS:
+		ret = ptrace_set_options(child, engine, data);
+		break;
+	case PTRACE_GETEVENTMSG:
+		ret = put_user(ptrace_context(engine)->eventmsg,
+				(unsigned long __user *) data);
+		break;
+
+	case PTRACE_GETSIGINFO:
+		ret = ptrace_rw_siginfo(child, ptrace_context(engine),
+					&siginfo, false);
+		if (!ret)
+			ret = copy_siginfo_to_user((siginfo_t __user *) data,
+						   &siginfo);
+		break;
+
+	case PTRACE_SETSIGINFO:
+		if (copy_from_user(&siginfo, (siginfo_t __user *) data,
+				   sizeof siginfo))
+			ret = -EFAULT;
+		else
+			ret = ptrace_rw_siginfo(child, ptrace_context(engine),
+						&siginfo, true);
+		break;
+
+	case PTRACE_DETACH:	 /* detach a process that was attached. */
+		ret = ptrace_detach(child, data);
+		break;
+
+	case PTRACE_KILL:
+		/* Ugly historical behaviour. */
+		if (task_is_traced(child))
+			ptrace_resume(child, engine, PTRACE_CONT, SIGKILL);
+		ret = 0;
+		break;
+
+	default:
+		ret = ptrace_resume(child, engine, request, data);
+		break;
+	}
+
+	utrace_engine_put(engine);
+	return ret;
+}
+
+#if defined CONFIG_COMPAT
+#include <linux/compat.h>
+
+int compat_ptrace_request(struct task_struct *child, compat_long_t request,
+			  compat_ulong_t addr, compat_ulong_t data)
+{
+	struct utrace_engine *engine = ptrace_lookup_engine(child);
+	compat_ulong_t __user *datap = compat_ptr(data);
+	compat_ulong_t word;
+	siginfo_t siginfo;
+	int ret;
+
+	if (unlikely(IS_ERR(engine)))
+		return -ESRCH;
+
+	switch (request) {
+	case PTRACE_PEEKTEXT:
+	case PTRACE_PEEKDATA:
+		ret = access_process_vm(child, addr, &word, sizeof(word), 0);
+		if (ret != sizeof(word))
+			ret = -EIO;
+		else
+			ret = put_user(word, datap);
+		break;
+
+	case PTRACE_POKETEXT:
+	case PTRACE_POKEDATA:
+		ret = access_process_vm(child, addr, &data, sizeof(data), 1);
+		ret = (ret != sizeof(data) ? -EIO : 0);
+		break;
+
+	case PTRACE_GETEVENTMSG:
+		ret = put_user((compat_ulong_t)ptrace_context(engine)->eventmsg,
+				datap);
+		break;
+
+	case PTRACE_GETSIGINFO:
+		ret = ptrace_rw_siginfo(child, ptrace_context(engine),
+					&siginfo, false);
+		if (!ret)
+			ret = copy_siginfo_to_user32(
+				(struct compat_siginfo __user *) datap,
+				&siginfo);
+		break;
+
+	case PTRACE_SETSIGINFO:
+		memset(&siginfo, 0, sizeof siginfo);
+		if (copy_siginfo_from_user32(
+			    &siginfo, (struct compat_siginfo __user *) datap))
+			ret = -EFAULT;
+		else
+			ret = ptrace_rw_siginfo(child, ptrace_context(engine),
+						&siginfo, true);
+		break;
+
+	default:
+		ret = ptrace_request(child, request, addr, data);
+	}
+
+	utrace_engine_put(engine);
+	return ret;
+}
+#endif	/* CONFIG_COMPAT */
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index a408bf7..4e87441 100644  
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -16,7 +16,6 @@
 #include <linux/pagemap.h>
 #include <linux/smp_lock.h>
 #include <linux/ptrace.h>
-#include <linux/utrace.h>
 #include <linux/security.h>
 #include <linux/signal.h>
 #include <linux/audit.h>
@@ -24,7 +23,286 @@
 #include <linux/syscalls.h>
 #include <linux/uaccess.h>
 
+int __ptrace_may_access(struct task_struct *task, unsigned int mode)
+{
+	const struct cred *cred = current_cred(), *tcred;
+
+	/* May we inspect the given task?
+	 * This check is used both for attaching with ptrace
+	 * and for allowing access to sensitive information in /proc.
+	 *
+	 * ptrace_attach denies several cases that /proc allows
+	 * because setting up the necessary parent/child relationship
+	 * or halting the specified task is impossible.
+	 */
+	int dumpable = 0;
+	/* Don't let security modules deny introspection */
+	if (task == current)
+		return 0;
+	rcu_read_lock();
+	tcred = __task_cred(task);
+	if ((cred->uid != tcred->euid ||
+	     cred->uid != tcred->suid ||
+	     cred->uid != tcred->uid  ||
+	     cred->gid != tcred->egid ||
+	     cred->gid != tcred->sgid ||
+	     cred->gid != tcred->gid) &&
+	    !capable(CAP_SYS_PTRACE)) {
+		rcu_read_unlock();
+		return -EPERM;
+	}
+	rcu_read_unlock();
+	smp_rmb();
+	if (task->mm)
+		dumpable = get_dumpable(task->mm);
+	if (!dumpable && !capable(CAP_SYS_PTRACE))
+		return -EPERM;
+
+	return security_ptrace_access_check(task, mode);
+}
+
+bool ptrace_may_access(struct task_struct *task, unsigned int mode)
+{
+	int err;
+	task_lock(task);
+	err = __ptrace_may_access(task, mode);
+	task_unlock(task);
+	return !err;
+}
+
+/*
+ * Called with irqs disabled, returns true if childs should reap themselves.
+ */
+static int ignoring_children(struct sighand_struct *sigh)
+{
+	int ret;
+	spin_lock(&sigh->siglock);
+	ret = (sigh->action[SIGCHLD-1].sa.sa_handler == SIG_IGN) ||
+	      (sigh->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT);
+	spin_unlock(&sigh->siglock);
+	return ret;
+}
+
+/*
+ * Called with tasklist_lock held for writing.
+ * Unlink a traced task, and clean it up if it was a traced zombie.
+ * Return true if it needs to be reaped with release_task().
+ * (We can't call release_task() here because we already hold tasklist_lock.)
+ *
+ * If it's a zombie, our attachedness prevented normal parent notification
+ * or self-reaping.  Do notification now if it would have happened earlier.
+ * If it should reap itself, return true.
+ *
+ * If it's our own child, there is no notification to do. But if our normal
+ * children self-reap, then this child was prevented by ptrace and we must
+ * reap it now, in that case we must also wake up sub-threads sleeping in
+ * do_wait().
+ */
+bool __ptrace_detach(struct task_struct *tracer, struct task_struct *p)
+{
+	__ptrace_unlink(p);
+
+	if (p->exit_state == EXIT_ZOMBIE) {
+		if (!task_detached(p) && thread_group_empty(p)) {
+			if (!same_thread_group(p->real_parent, tracer))
+				do_notify_parent(p, p->exit_signal);
+			else if (ignoring_children(tracer->sighand)) {
+				__wake_up_parent(p, tracer);
+				p->exit_signal = -1;
+			}
+		}
+		if (task_detached(p)) {
+			/* Mark it as in the process of being reaped. */
+			p->exit_state = EXIT_DEAD;
+			return true;
+		}
+	}
+
+	return false;
+}
+
+int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len)
+{
+	int copied = 0;
+
+	while (len > 0) {
+		char buf[128];
+		int this_len, retval;
+
+		this_len = (len > sizeof(buf)) ? sizeof(buf) : len;
+		retval = access_process_vm(tsk, src, buf, this_len, 0);
+		if (!retval) {
+			if (copied)
+				break;
+			return -EIO;
+		}
+		if (copy_to_user(dst, buf, retval))
+			return -EFAULT;
+		copied += retval;
+		src += retval;
+		dst += retval;
+		len -= retval;
+	}
+	return copied;
+}
+
+int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len)
+{
+	int copied = 0;
+
+	while (len > 0) {
+		char buf[128];
+		int this_len, retval;
+
+		this_len = (len > sizeof(buf)) ? sizeof(buf) : len;
+		if (copy_from_user(buf, src, this_len))
+			return -EFAULT;
+		retval = access_process_vm(tsk, dst, buf, this_len, 1);
+		if (!retval) {
+			if (copied)
+				break;
+			return -EIO;
+		}
+		copied += retval;
+		src += retval;
+		dst += retval;
+		len -= retval;
+	}
+	return copied;
+}
+
+static struct task_struct *ptrace_get_task_struct(pid_t pid)
+{
+	struct task_struct *child;
+
+	rcu_read_lock();
+	child = find_task_by_vpid(pid);
+	if (child)
+		get_task_struct(child);
+	rcu_read_unlock();
+
+	if (!child)
+		return ERR_PTR(-ESRCH);
+	return child;
+}
+
+#ifndef arch_ptrace_attach
+#define arch_ptrace_attach(child)	do { } while (0)
+#endif
 
+SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)
+{
+	struct task_struct *child;
+	long ret;
+
+	/*
+	 * This lock_kernel fixes a subtle race with suid exec
+	 */
+	lock_kernel();
+	if (request == PTRACE_TRACEME) {
+		ret = ptrace_traceme();
+		if (!ret)
+			arch_ptrace_attach(current);
+		goto out;
+	}
+
+	child = ptrace_get_task_struct(pid);
+	if (IS_ERR(child)) {
+		ret = PTR_ERR(child);
+		goto out;
+	}
+
+	if (request == PTRACE_ATTACH) {
+		ret = ptrace_attach(child);
+		/*
+		 * Some architectures need to do book-keeping after
+		 * a ptrace attach.
+		 */
+		if (!ret)
+			arch_ptrace_attach(child);
+		goto out_put_task_struct;
+	}
+
+	ret = ptrace_check_attach(child, request == PTRACE_KILL);
+	if (ret < 0)
+		goto out_put_task_struct;
+
+	ret = arch_ptrace(child, request, addr, data);
+
+ out_put_task_struct:
+	put_task_struct(child);
+ out:
+	unlock_kernel();
+	return ret;
+}
+
+int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data)
+{
+	unsigned long tmp;
+	int copied;
+
+	copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
+	if (copied != sizeof(tmp))
+		return -EIO;
+	return put_user(tmp, (unsigned long __user *)data);
+}
+
+int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data)
+{
+	int copied;
+
+	copied = access_process_vm(tsk, addr, &data, sizeof(data), 1);
+	return (copied == sizeof(data)) ? 0 : -EIO;
+}
+
+#if defined CONFIG_COMPAT
+#include <linux/compat.h>
+
+asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
+				  compat_long_t addr, compat_long_t data)
+{
+	struct task_struct *child;
+	long ret;
+
+	/*
+	 * This lock_kernel fixes a subtle race with suid exec
+	 */
+	lock_kernel();
+	if (request == PTRACE_TRACEME) {
+		ret = ptrace_traceme();
+		goto out;
+	}
+
+	child = ptrace_get_task_struct(pid);
+	if (IS_ERR(child)) {
+		ret = PTR_ERR(child);
+		goto out;
+	}
+
+	if (request == PTRACE_ATTACH) {
+		ret = ptrace_attach(child);
+		/*
+		 * Some architectures need to do book-keeping after
+		 * a ptrace attach.
+		 */
+		if (!ret)
+			arch_ptrace_attach(child);
+		goto out_put_task_struct;
+	}
+
+	ret = ptrace_check_attach(child, request == PTRACE_KILL);
+	if (!ret)
+		ret = compat_arch_ptrace(child, request, addr, data);
+
+ out_put_task_struct:
+	put_task_struct(child);
+ out:
+	unlock_kernel();
+	return ret;
+}
+#endif	/* CONFIG_COMPAT */
+
+#ifndef CONFIG_UTRACE
 /*
  * ptrace a task: make the debugger its new parent and
  * move it to the ptrace list.
@@ -101,76 +379,21 @@ int ptrace_check_attach(struct task_stru
 		/*
 		 * child->sighand can't be NULL, release_task()
 		 * does ptrace_unlink() before __exit_signal().
-		 */
-		spin_lock_irq(&child->sighand->siglock);
-		if (task_is_stopped(child))
-			child->state = TASK_TRACED;
-		else if (!task_is_traced(child) && !kill)
-			ret = -ESRCH;
-		spin_unlock_irq(&child->sighand->siglock);
-	}
-	read_unlock(&tasklist_lock);
-
-	if (!ret && !kill)
-		ret = wait_task_inactive(child, TASK_TRACED) ? 0 : -ESRCH;
-
-	/* All systems go.. */
-	return ret;
-}
-
-int __ptrace_may_access(struct task_struct *task, unsigned int mode)
-{
-	const struct cred *cred = current_cred(), *tcred;
-
-	/* May we inspect the given task?
-	 * This check is used both for attaching with ptrace
-	 * and for allowing access to sensitive information in /proc.
-	 *
-	 * ptrace_attach denies several cases that /proc allows
-	 * because setting up the necessary parent/child relationship
-	 * or halting the specified task is impossible.
-	 */
-	int dumpable = 0;
-	/* Don't let security modules deny introspection */
-	if (task == current)
-		return 0;
-	rcu_read_lock();
-	tcred = __task_cred(task);
-	if ((cred->uid != tcred->euid ||
-	     cred->uid != tcred->suid ||
-	     cred->uid != tcred->uid  ||
-	     cred->gid != tcred->egid ||
-	     cred->gid != tcred->sgid ||
-	     cred->gid != tcred->gid) &&
-	    !capable(CAP_SYS_PTRACE)) {
-		rcu_read_unlock();
-		return -EPERM;
-	}
-	rcu_read_unlock();
-	smp_rmb();
-	if (task->mm)
-		dumpable = get_dumpable(task->mm);
-	if (!dumpable && !capable(CAP_SYS_PTRACE))
-		return -EPERM;
-
-	return security_ptrace_access_check(task, mode);
-}
+		 */
+		spin_lock_irq(&child->sighand->siglock);
+		if (task_is_stopped(child))
+			child->state = TASK_TRACED;
+		else if (!task_is_traced(child) && !kill)
+			ret = -ESRCH;
+		spin_unlock_irq(&child->sighand->siglock);
+	}
+	read_unlock(&tasklist_lock);
 
-bool ptrace_may_access(struct task_struct *task, unsigned int mode)
-{
-	int err;
-	task_lock(task);
-	err = __ptrace_may_access(task, mode);
-	task_unlock(task);
-	return !err;
-}
+	if (!ret && !kill)
+		ret = wait_task_inactive(child, TASK_TRACED) ? 0 : -ESRCH;
 
-/*
- * For experimental use of utrace, exclude ptrace on the same task.
- */
-static inline bool exclude_ptrace(struct task_struct *task)
-{
-	return unlikely(!!task_utrace_flags(task));
+	/* All systems go.. */
+	return ret;
 }
 
 int ptrace_attach(struct task_struct *task)
@@ -196,8 +419,6 @@ int ptrace_attach(struct task_struct *ta
 
 	task_lock(task);
 	retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
-	if (!retval && exclude_ptrace(task))
-		retval = -EBUSY;
 	task_unlock(task);
 	if (retval)
 		goto unlock_creds;
@@ -235,9 +456,6 @@ int ptrace_traceme(void)
 {
 	int ret = -EPERM;
 
-	if (exclude_ptrace(current)) /* XXX locking */
-		return -EBUSY;
-
 	write_lock_irq(&tasklist_lock);
 	/* Are we already being traced? */
 	if (!current->ptrace) {
@@ -257,57 +475,6 @@ int ptrace_traceme(void)
 	return ret;
 }
 
-/*
- * Called with irqs disabled, returns true if childs should reap themselves.
- */
-static int ignoring_children(struct sighand_struct *sigh)
-{
-	int ret;
-	spin_lock(&sigh->siglock);
-	ret = (sigh->action[SIGCHLD-1].sa.sa_handler == SIG_IGN) ||
-	      (sigh->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT);
-	spin_unlock(&sigh->siglock);
-	return ret;
-}
-
-/*
- * Called with tasklist_lock held for writing.
- * Unlink a traced task, and clean it up if it was a traced zombie.
- * Return true if it needs to be reaped with release_task().
- * (We can't call release_task() here because we already hold tasklist_lock.)
- *
- * If it's a zombie, our attachedness prevented normal parent notification
- * or self-reaping.  Do notification now if it would have happened earlier.
- * If it should reap itself, return true.
- *
- * If it's our own child, there is no notification to do. But if our normal
- * children self-reap, then this child was prevented by ptrace and we must
- * reap it now, in that case we must also wake up sub-threads sleeping in
- * do_wait().
- */
-bool __ptrace_detach(struct task_struct *tracer, struct task_struct *p)
-{
-	__ptrace_unlink(p);
-
-	if (p->exit_state == EXIT_ZOMBIE) {
-		if (!task_detached(p) && thread_group_empty(p)) {
-			if (!same_thread_group(p->real_parent, tracer))
-				do_notify_parent(p, p->exit_signal);
-			else if (ignoring_children(tracer->sighand)) {
-				__wake_up_parent(p, tracer);
-				p->exit_signal = -1;
-			}
-		}
-		if (task_detached(p)) {
-			/* Mark it as in the process of being reaped. */
-			p->exit_state = EXIT_DEAD;
-			return true;
-		}
-	}
-
-	return false;
-}
-
 int ptrace_detach(struct task_struct *child, unsigned int data)
 {
 	bool dead = false;
@@ -361,56 +528,6 @@ void exit_ptrace(struct task_struct *tra
 	}
 }
 
-int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len)
-{
-	int copied = 0;
-
-	while (len > 0) {
-		char buf[128];
-		int this_len, retval;
-
-		this_len = (len > sizeof(buf)) ? sizeof(buf) : len;
-		retval = access_process_vm(tsk, src, buf, this_len, 0);
-		if (!retval) {
-			if (copied)
-				break;
-			return -EIO;
-		}
-		if (copy_to_user(dst, buf, retval))
-			return -EFAULT;
-		copied += retval;
-		src += retval;
-		dst += retval;
-		len -= retval;
-	}
-	return copied;
-}
-
-int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len)
-{
-	int copied = 0;
-
-	while (len > 0) {
-		char buf[128];
-		int this_len, retval;
-
-		this_len = (len > sizeof(buf)) ? sizeof(buf) : len;
-		if (copy_from_user(buf, src, this_len))
-			return -EFAULT;
-		retval = access_process_vm(tsk, dst, buf, this_len, 1);
-		if (!retval) {
-			if (copied)
-				break;
-			return -EIO;
-		}
-		copied += retval;
-		src += retval;
-		dst += retval;
-		len -= retval;
-	}
-	return copied;
-}
-
 static int ptrace_setoptions(struct task_struct *child, long data)
 {
 	child->ptrace &= ~PT_TRACE_MASK;
@@ -594,93 +710,7 @@ int ptrace_request(struct task_struct *c
 	return ret;
 }
 
-static struct task_struct *ptrace_get_task_struct(pid_t pid)
-{
-	struct task_struct *child;
-
-	rcu_read_lock();
-	child = find_task_by_vpid(pid);
-	if (child)
-		get_task_struct(child);
-	rcu_read_unlock();
-
-	if (!child)
-		return ERR_PTR(-ESRCH);
-	return child;
-}
-
-#ifndef arch_ptrace_attach
-#define arch_ptrace_attach(child)	do { } while (0)
-#endif
-
-SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)
-{
-	struct task_struct *child;
-	long ret;
-
-	/*
-	 * This lock_kernel fixes a subtle race with suid exec
-	 */
-	lock_kernel();
-	if (request == PTRACE_TRACEME) {
-		ret = ptrace_traceme();
-		if (!ret)
-			arch_ptrace_attach(current);
-		goto out;
-	}
-
-	child = ptrace_get_task_struct(pid);
-	if (IS_ERR(child)) {
-		ret = PTR_ERR(child);
-		goto out;
-	}
-
-	if (request == PTRACE_ATTACH) {
-		ret = ptrace_attach(child);
-		/*
-		 * Some architectures need to do book-keeping after
-		 * a ptrace attach.
-		 */
-		if (!ret)
-			arch_ptrace_attach(child);
-		goto out_put_task_struct;
-	}
-
-	ret = ptrace_check_attach(child, request == PTRACE_KILL);
-	if (ret < 0)
-		goto out_put_task_struct;
-
-	ret = arch_ptrace(child, request, addr, data);
-
- out_put_task_struct:
-	put_task_struct(child);
- out:
-	unlock_kernel();
-	return ret;
-}
-
-int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data)
-{
-	unsigned long tmp;
-	int copied;
-
-	copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
-	if (copied != sizeof(tmp))
-		return -EIO;
-	return put_user(tmp, (unsigned long __user *)data);
-}
-
-int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data)
-{
-	int copied;
-
-	copied = access_process_vm(tsk, addr, &data, sizeof(data), 1);
-	return (copied == sizeof(data)) ? 0 : -EIO;
-}
-
 #if defined CONFIG_COMPAT
-#include <linux/compat.h>
-
 int compat_ptrace_request(struct task_struct *child, compat_long_t request,
 			  compat_ulong_t addr, compat_ulong_t data)
 {
@@ -732,47 +762,5 @@ int compat_ptrace_request(struct task_st
 
 	return ret;
 }
-
-asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
-				  compat_long_t addr, compat_long_t data)
-{
-	struct task_struct *child;
-	long ret;
-
-	/*
-	 * This lock_kernel fixes a subtle race with suid exec
-	 */
-	lock_kernel();
-	if (request == PTRACE_TRACEME) {
-		ret = ptrace_traceme();
-		goto out;
-	}
-
-	child = ptrace_get_task_struct(pid);
-	if (IS_ERR(child)) {
-		ret = PTR_ERR(child);
-		goto out;
-	}
-
-	if (request == PTRACE_ATTACH) {
-		ret = ptrace_attach(child);
-		/*
-		 * Some architectures need to do book-keeping after
-		 * a ptrace attach.
-		 */
-		if (!ret)
-			arch_ptrace_attach(child);
-		goto out_put_task_struct;
-	}
-
-	ret = ptrace_check_attach(child, request == PTRACE_KILL);
-	if (!ret)
-		ret = compat_arch_ptrace(child, request, addr, data);
-
- out_put_task_struct:
-	put_task_struct(child);
- out:
-	unlock_kernel();
-	return ret;
-}
 #endif	/* CONFIG_COMPAT */
+#endif	/* CONFIG_UTRACE */
diff --git a/kernel/utrace.c b/kernel/utrace.c
index cb62fcd..9353cc5 100644  
--- a/kernel/utrace.c
+++ b/kernel/utrace.c
@@ -811,6 +811,22 @@ relock:
 	spin_unlock_irq(&task->sighand->siglock);
 	spin_unlock(&utrace->lock);
 
+	/*
+	 * If ptrace is among the reasons for this stop, do its
+	 * notification now.  This could not just be done in
+	 * ptrace's own event report callbacks because it has to
+	 * be done after we are in TASK_TRACED.  This makes the
+	 * synchronization with ptrace_do_wait() work right.
+	 *
+	 * It's only because of the bad old overloading of the do_wait()
+	 * logic for handling ptrace stops that we need this special case
+	 * here.  One day we will clean up ptrace so it does not need to
+	 * work this way.  New things that are designed sensibly don't need
+	 * a wakeup that synchronizes with tasklist_lock and ->state, so
+	 * the proper utrace API does not try to support this weirdness.
+	 */
+	ptrace_notify_stop(task);
+
 	schedule();
 
 	utrace_finish_stop();


Index: kernel.spec
===================================================================
RCS file: /cvs/pkgs/rpms/kernel/devel/kernel.spec,v
retrieving revision 1.1872
retrieving revision 1.1873
diff -u -p -r1.1872 -r1.1873
--- kernel.spec	14 Dec 2009 20:16:53 -0000	1.1872
+++ kernel.spec	16 Dec 2009 22:09:41 -0000	1.1873
@@ -617,6 +617,7 @@ Patch20: linux-2.6-hotfixes.patch
 
 Patch21: linux-2.6-tracehook.patch
 Patch22: linux-2.6-utrace.patch
+Patch23: linux-2.6-utrace-ptrace.patch
 
 # More workaround for BIOS brokenness, fix intel_iommu=igfx_off oops
 Patch100: linux-2.6-iommu-updates.patch
@@ -1147,8 +1148,9 @@ ApplyOptionalPatch linux-2.6-upstream-re
 ApplyPatch linux-2.6-hotfixes.patch
 
 # Roland's utrace ptrace replacement.
-#ApplyPatch linux-2.6-tracehook.patch # merged
+ApplyPatch linux-2.6-tracehook.patch
 ApplyPatch linux-2.6-utrace.patch
+ApplyPatch linux-2.6-utrace-ptrace.patch
 
 # Architecture patches
 # x86(-64)
@@ -2001,6 +2003,9 @@ fi
 # and build.
 
 %changelog
+* Wed Dec 16 2009 Roland McGrath <roland at redhat.com> 2.6.32.1-10
+- utrace update, now testing the utrace-based ptrace!
+
 * Mon Dec 14 2009 Kyle McMartin <kyle at redhat.com> 2.6.32.1-9
 - 2.6.32.1
 - ext4 patches and more...
@@ -2064,7 +2069,7 @@ fi
   +CONFIG_SLOW_WORK_PROC=y
 
 * Mon Nov 30 2009 Kyle McMartin <kyle at redhat.com>
-- drm-i915-fix-sync-to-vbl-when-vga-is-off.patch: add, (rhbz#541670) 
+- drm-i915-fix-sync-to-vbl-when-vga-is-off.patch: add, (rhbz#541670)
 
 * Sun Nov 29 2009 Kyle McMartin <kyle at redhat.com>
 - linux-2.6-sysrq-c.patch: drop, was made consistent upstream.

linux-2.6-tracehook.patch:
 arch/powerpc/include/asm/ptrace.h |    2 +
 arch/powerpc/kernel/traps.c       |    9 ++++++
 arch/x86/include/asm/ptrace.h     |    2 +
 arch/x86/kernel/ptrace.c          |   51 ++++++++++++++++++++------------------
 include/linux/ptrace.h            |   24 +++++++++++------
 include/linux/sched.h             |    1 
 include/linux/tracehook.h         |   15 ++++++++---
 kernel/ptrace.c                   |    2 -
 kernel/signal.c                   |   13 ++++-----
 9 files changed, 76 insertions(+), 43 deletions(-)

Index: linux-2.6-tracehook.patch
===================================================================
RCS file: /cvs/pkgs/rpms/kernel/devel/linux-2.6-tracehook.patch,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -p -r1.9 -r1.10
--- linux-2.6-tracehook.patch	8 Apr 2009 01:31:58 -0000	1.9
+++ linux-2.6-tracehook.patch	16 Dec 2009 22:09:41 -0000	1.10
@@ -1,194 +1,336 @@
-signals: tracehook_notify_jctl change
+From: Oleg Nesterov <oleg at redhat.com>
 
-This changes tracehook_notify_jctl() so it's called with the siglock held,
-and changes its argument and return value definition.  These clean-ups make
-it a better fit for what new tracing hooks need to check.
+[PATCH] signals: check ->group_stop_count after tracehook_get_signal()
 
-Tracing needs the siglock here, held from the time TASK_STOPPED was set,
-to avoid potential SIGCONT races if it wants to allow any blocking in its
-tracing hooks.
+Move the call to do_signal_stop() down, after tracehook call.
+This makes ->group_stop_count condition visible to tracers before
+do_signal_stop() will participate in this group-stop.
 
-This also folds the finish_stop() function into its caller do_signal_stop().
-The function is short, called only once and only unconditionally.  It aids
-readability to fold it in.
+Currently the patch has no effect, tracehook_get_signal() always
+returns 0.
 
+Signed-off-by: Oleg Nesterov <oleg at redhat.com>
 Signed-off-by: Roland McGrath <roland at redhat.com>
 ---
- include/linux/tracehook.h |   25 ++++++++++------
- kernel/signal.c           |   69 +++++++++++++++++++++++----------------------
- 2 files changed, 51 insertions(+), 43 deletions(-)
+ arch/powerpc/include/asm/ptrace.h |    2 +
+ arch/powerpc/kernel/traps.c       |    9 ++++++
+ arch/x86/include/asm/ptrace.h     |    2 +
+ arch/x86/kernel/ptrace.c          |   51 ++++++++++++++++++++----------------
+ include/linux/ptrace.h            |   24 +++++++++++------
+ include/linux/sched.h             |    1 +
+ include/linux/tracehook.h         |   15 ++++++++---
+ kernel/ptrace.c                   |    2 +-
+ kernel/signal.c                   |   13 ++++-----
+ 9 files changed, 76 insertions(+), 43 deletions(-)
 
-diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
-index c7aa154..4ec4821 100644  
---- a/include/linux/tracehook.h
-+++ b/include/linux/tracehook.h
-@@ -1,7 +1,7 @@
- /*
-  * Tracing hooks
-  *
-- * Copyright (C) 2008 Red Hat, Inc.  All rights reserved.
-+ * Copyright (C) 2008-2009 Red Hat, Inc.  All rights reserved.
-  *
-  * This copyrighted material is made available to anyone wishing to use,
-  * modify, copy, or redistribute it subject to the terms and conditions
-@@ -464,22 +464,29 @@ static inline int tracehook_get_signal(s
+diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h
+index 8c34149..cbd759e 100644  
+--- a/arch/powerpc/include/asm/ptrace.h
++++ b/arch/powerpc/include/asm/ptrace.h
+@@ -140,6 +140,8 @@ extern void user_enable_single_step(stru
+ extern void user_enable_block_step(struct task_struct *);
+ extern void user_disable_single_step(struct task_struct *);
  
- /**
-  * tracehook_notify_jctl - report about job control stop/continue
-- * @notify:		nonzero if this is the last thread in the group to stop
-+ * @notify:		zero, %CLD_STOPPED or %CLD_CONTINUED
-  * @why:		%CLD_STOPPED or %CLD_CONTINUED
-  *
-  * This is called when we might call do_notify_parent_cldstop().
-- * It's called when about to stop for job control; we are already in
-- * %TASK_STOPPED state, about to call schedule().  It's also called when
-- * a delayed %CLD_STOPPED or %CLD_CONTINUED report is ready to be made.
-  *
-- * Return nonzero to generate a %SIGCHLD with @why, which is
-- * normal if @notify is nonzero.
-+ * @notify is zero if we would not ordinarily send a %SIGCHLD,
-+ * or is the %CLD_STOPPED or %CLD_CONTINUED .si_code for %SIGCHLD.
-  *
-- * Called with no locks held.
-+ * @why is %CLD_STOPPED when about to stop for job control;
-+ * we are already in %TASK_STOPPED state, about to call schedule().
-+ * It might also be that we have just exited (check %PF_EXITING),
-+ * but need to report that a group-wide stop is complete.
-+ *
-+ * @why is %CLD_CONTINUED when waking up after job control stop and
-+ * ready to make a delayed @notify report.
-+ *
-+ * Return the %CLD_* value for %SIGCHLD, or zero to generate no signal.
-+ *
-+ * Called with the siglock held.
-  */
- static inline int tracehook_notify_jctl(int notify, int why)
++#define ARCH_HAS_USER_SINGLE_STEP_INFO
++
+ #endif /* __ASSEMBLY__ */
+ 
+ #endif /* __KERNEL__ */
+diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
+index 6f0ae1a..83b57ac 100644  
+--- a/arch/powerpc/kernel/traps.c
++++ b/arch/powerpc/kernel/traps.c
+@@ -174,6 +174,15 @@ int die(const char *str, struct pt_regs 
+ 	return 0;
+ }
+ 
++void user_single_step_siginfo(struct task_struct *tsk,
++				struct pt_regs *regs, siginfo_t *info)
++{
++	memset(info, 0, sizeof(*info));
++	info->si_signo = SIGTRAP;
++	info->si_code = TRAP_TRACE;
++	info->si_addr = (void __user *)regs->nip;
++}
++
+ void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
  {
--	return notify || (current->ptrace & PT_PTRACED);
-+	return notify ?: (current->ptrace & PT_PTRACED) ? why : 0;
+ 	siginfo_t info;
+diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
+index 0f0d908..7a88a82 100644  
+--- a/arch/x86/include/asm/ptrace.h
++++ b/arch/x86/include/asm/ptrace.h
+@@ -230,6 +230,8 @@ extern void user_enable_block_step(struc
+ #define arch_has_block_step()	(boot_cpu_data.x86 >= 6)
+ #endif
+ 
++#define ARCH_HAS_USER_SINGLE_STEP_INFO
++
+ struct user_desc;
+ extern int do_get_thread_area(struct task_struct *p, int idx,
+ 			      struct user_desc __user *info);
+diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
+index 7b058a2..ea35dee 100644  
+--- a/arch/x86/kernel/ptrace.c
++++ b/arch/x86/kernel/ptrace.c
+@@ -1437,21 +1437,33 @@ const struct user_regset_view *task_user
+ #endif
  }
  
- #define DEATH_REAP			-1
-diff --git a/kernel/signal.c b/kernel/signal.c
-index d803473..424eff2 100644  
---- a/kernel/signal.c
-+++ b/kernel/signal.c
-@@ -702,7 +702,7 @@ static int prepare_signal(int sig, struc
+-void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
+-					 int error_code, int si_code)
++static void fill_sigtrap_info(struct task_struct *tsk,
++				struct pt_regs *regs,
++				int error_code, int si_code,
++				struct siginfo *info)
+ {
+-	struct siginfo info;
+-
+ 	tsk->thread.trap_no = 1;
+ 	tsk->thread.error_code = error_code;
  
- 		if (why) {
- 			/*
--			 * The first thread which returns from finish_stop()
-+			 * The first thread which returns from do_signal_stop()
- 			 * will take ->siglock, notice SIGNAL_CLD_MASK, and
- 			 * notify its parent. See get_signal_to_deliver().
- 			 */
-@@ -1665,29 +1665,6 @@ void ptrace_notify(int exit_code)
- 	spin_unlock_irq(&current->sighand->siglock);
+-	memset(&info, 0, sizeof(info));
+-	info.si_signo = SIGTRAP;
+-	info.si_code = si_code;
++	memset(info, 0, sizeof(*info));
++	info->si_signo = SIGTRAP;
++	info->si_code = si_code;
++	info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
++}
+ 
+-	/* User-mode ip? */
+-	info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
++void user_single_step_siginfo(struct task_struct *tsk,
++				struct pt_regs *regs,
++				struct siginfo *info)
++{
++	fill_sigtrap_info(tsk, regs, 0, TRAP_BRKPT, info);
++}
++
++void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
++					 int error_code, int si_code)
++{
++	struct siginfo info;
+ 
++	fill_sigtrap_info(tsk, regs, error_code, si_code, &info);
+ 	/* Send us the fake SIGTRAP */
+ 	force_sig_info(SIGTRAP, &info, tsk);
  }
+@@ -1516,29 +1528,22 @@ asmregparm long syscall_trace_enter(stru
  
--static void
--finish_stop(int stop_count)
--{
--	/*
--	 * If there are no other threads in the group, or if there is
--	 * a group stop in progress and we are the last to stop,
--	 * report to the parent.  When ptraced, every thread reports itself.
+ asmregparm void syscall_trace_leave(struct pt_regs *regs)
+ {
++	bool step;
++
+ 	if (unlikely(current->audit_context))
+ 		audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
+ 
+ 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
+ 		trace_sys_exit(regs, regs->ax);
+ 
+-	if (test_thread_flag(TIF_SYSCALL_TRACE))
+-		tracehook_report_syscall_exit(regs, 0);
+-
+ 	/*
+ 	 * If TIF_SYSCALL_EMU is set, we only get here because of
+ 	 * TIF_SINGLESTEP (i.e. this is PTRACE_SYSEMU_SINGLESTEP).
+ 	 * We already reported this syscall instruction in
+-	 * syscall_trace_enter(), so don't do any more now.
 -	 */
--	if (tracehook_notify_jctl(stop_count == 0, CLD_STOPPED)) {
--		read_lock(&tasklist_lock);
--		do_notify_parent_cldstop(current, CLD_STOPPED);
--		read_unlock(&tasklist_lock);
--	}
+-	if (unlikely(test_thread_flag(TIF_SYSCALL_EMU)))
+-		return;
 -
--	do {
--		schedule();
--	} while (try_to_freeze());
 -	/*
--	 * Now we don't run again until continued.
--	 */
--	current->exit_code = 0;
+-	 * If we are single-stepping, synthesize a trap to follow the
+-	 * system call instruction.
++	 * syscall_trace_enter().
+ 	 */
+-	if (test_thread_flag(TIF_SINGLESTEP) &&
+-	    tracehook_consider_fatal_signal(current, SIGTRAP))
+-		send_sigtrap(current, regs, 0, TRAP_BRKPT);
++	step = unlikely(test_thread_flag(TIF_SINGLESTEP)) &&
++			!test_thread_flag(TIF_SYSCALL_EMU);
++	if (step || test_thread_flag(TIF_SYSCALL_TRACE))
++		tracehook_report_syscall_exit(regs, step);
+ }
+diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
+index 7456d7d..4802e2a 100644  
+--- a/include/linux/ptrace.h
++++ b/include/linux/ptrace.h
+@@ -85,6 +85,7 @@ extern int ptrace_traceme(void);
+ extern int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len);
+ extern int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len);
+ extern int ptrace_attach(struct task_struct *tsk);
++extern bool __ptrace_detach(struct task_struct *tracer, struct task_struct *tracee);
+ extern int ptrace_detach(struct task_struct *, unsigned int);
+ extern void ptrace_disable(struct task_struct *);
+ extern int ptrace_check_attach(struct task_struct *task, int kill);
+@@ -105,12 +106,7 @@ static inline int ptrace_reparented(stru
+ {
+ 	return child->real_parent != child->parent;
+ }
+-static inline void ptrace_link(struct task_struct *child,
+-			       struct task_struct *new_parent)
+-{
+-	if (unlikely(child->ptrace))
+-		__ptrace_link(child, new_parent);
 -}
--
- /*
-  * This performs the stopping for SIGSTOP and other stop signals.
-  * We have to stop all threads in the thread group.
-@@ -1698,6 +1675,7 @@ static int do_signal_stop(int signr)
- {
- 	struct signal_struct *sig = current->signal;
- 	int stop_count;
-+	int notify;
++
+ static inline void ptrace_unlink(struct task_struct *child)
+ {
+ 	if (unlikely(child->ptrace))
+@@ -169,9 +165,9 @@ static inline void ptrace_init_task(stru
+ 	INIT_LIST_HEAD(&child->ptraced);
+ 	child->parent = child->real_parent;
+ 	child->ptrace = 0;
+-	if (unlikely(ptrace)) {
++	if (unlikely(ptrace) && (current->ptrace & PT_PTRACED)) {
+ 		child->ptrace = current->ptrace;
+-		ptrace_link(child, current->parent);
++		__ptrace_link(child, current->parent);
+ 	}
+ }
  
- 	if (sig->group_stop_count > 0) {
- 		/*
-@@ -1737,8 +1715,30 @@ static int do_signal_stop(int signr)
- 	current->exit_code = sig->group_exit_code;
- 	__set_current_state(TASK_STOPPED);
- 
-+	/*
-+	 * If there are no other threads in the group, or if there is
-+	 * a group stop in progress and we are the last to stop,
-+	 * report to the parent.  When ptraced, every thread reports itself.
-+	 */
-+	notify = tracehook_notify_jctl(stop_count == 0 ? CLD_STOPPED : 0,
-+				       CLD_STOPPED);
-+
- 	spin_unlock_irq(&current->sighand->siglock);
--	finish_stop(stop_count);
-+
-+	if (notify) {
-+		read_lock(&tasklist_lock);
-+		do_notify_parent_cldstop(current, notify);
-+		read_unlock(&tasklist_lock);
+@@ -278,6 +274,18 @@ static inline void user_enable_block_ste
+ }
+ #endif	/* arch_has_block_step */
+ 
++#ifdef ARCH_HAS_USER_SINGLE_STEP_INFO
++extern void user_single_step_siginfo(struct task_struct *tsk,
++				struct pt_regs *regs, siginfo_t *info);
++#else
++static inline void user_single_step_siginfo(struct task_struct *tsk,
++				struct pt_regs *regs, siginfo_t *info)
++{
++	memset(info, 0, sizeof(*info));
++	info->si_signo = SIGTRAP;
++}
++#endif
++
+ #ifndef arch_ptrace_stop_needed
+ /**
+  * arch_ptrace_stop_needed - Decide whether arch_ptrace_stop() should be called
+diff --git a/include/linux/sched.h b/include/linux/sched.h
+index 75e6e60..6c8928b 100644  
+--- a/include/linux/sched.h
++++ b/include/linux/sched.h
+@@ -2060,6 +2060,7 @@ extern int kill_pgrp(struct pid *pid, in
+ extern int kill_pid(struct pid *pid, int sig, int priv);
+ extern int kill_proc_info(int, struct siginfo *, pid_t);
+ extern int do_notify_parent(struct task_struct *, int);
++extern void do_notify_parent_cldstop(struct task_struct *, int);
+ extern void __wake_up_parent(struct task_struct *p, struct task_struct *parent);
+ extern void force_sig(int, struct task_struct *);
+ extern void force_sig_specific(int, struct task_struct *);
+diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
+index 1eb44a9..c78b2f4 100644  
+--- a/include/linux/tracehook.h
++++ b/include/linux/tracehook.h
+@@ -134,6 +134,13 @@ static inline __must_check int tracehook
+  */
+ static inline void tracehook_report_syscall_exit(struct pt_regs *regs, int step)
+ {
++	if (step && (task_ptrace(current) & PT_PTRACED)) {
++		siginfo_t info;
++		user_single_step_siginfo(current, regs, &info);
++		force_sig_info(SIGTRAP, &info, current);
++		return;
 +	}
 +
-+	do {
-+		schedule();
-+	} while (try_to_freeze());
-+	/*
-+	 * Now we don't run again until continued.
-+	 */
-+	current->exit_code = 0;
-+
- 	return 1;
- }
- 
-@@ -1807,14 +1807,15 @@ relock:
- 		int why = (signal->flags & SIGNAL_STOP_CONTINUED)
- 				? CLD_CONTINUED : CLD_STOPPED;
- 		signal->flags &= ~SIGNAL_CLD_MASK;
--		spin_unlock_irq(&sighand->siglock);
+ 	ptrace_report_syscall(regs);
+ }
  
--		if (unlikely(!tracehook_notify_jctl(1, why)))
--			goto relock;
-+		why = tracehook_notify_jctl(why, CLD_CONTINUED);
-+		spin_unlock_irq(&sighand->siglock);
+@@ -149,7 +156,7 @@ static inline int tracehook_unsafe_exec(
+ {
+ 	int unsafe = 0;
+ 	int ptrace = task_ptrace(task);
+-	if (ptrace & PT_PTRACED) {
++	if (ptrace) {
+ 		if (ptrace & PT_PTRACE_CAP)
+ 			unsafe |= LSM_UNSAFE_PTRACE_CAP;
+ 		else
+@@ -171,7 +178,7 @@ static inline int tracehook_unsafe_exec(
+  */
+ static inline struct task_struct *tracehook_tracer_task(struct task_struct *tsk)
+ {
+-	if (task_ptrace(tsk) & PT_PTRACED)
++	if (task_ptrace(tsk))
+ 		return rcu_dereference(tsk->parent);
+ 	return NULL;
+ }
+@@ -379,7 +386,7 @@ static inline void tracehook_signal_hand
+ 					    const struct k_sigaction *ka,
+ 					    struct pt_regs *regs, int stepping)
+ {
+-	if (stepping)
++	if (stepping && (task_ptrace(current) & PT_PTRACED))
+ 		ptrace_notify(SIGTRAP);
+ }
  
--		read_lock(&tasklist_lock);
--		do_notify_parent_cldstop(current->group_leader, why);
--		read_unlock(&tasklist_lock);
-+		if (why) {
-+			read_lock(&tasklist_lock);
-+			do_notify_parent_cldstop(current->group_leader, why);
-+			read_unlock(&tasklist_lock);
-+		}
- 		goto relock;
- 	}
+@@ -485,7 +492,7 @@ static inline int tracehook_get_signal(s
+  */
+ static inline int tracehook_notify_jctl(int notify, int why)
+ {
+-	return notify ?: (current->ptrace & PT_PTRACED) ? why : 0;
++	return notify ?: task_ptrace(current) ? why : 0;
+ }
  
-@@ -1979,14 +1980,14 @@ void exit_signals(struct task_struct *ts
- 	if (unlikely(tsk->signal->group_stop_count) &&
- 			!--tsk->signal->group_stop_count) {
- 		tsk->signal->flags = SIGNAL_STOP_STOPPED;
--		group_stop = 1;
-+		group_stop = tracehook_notify_jctl(CLD_STOPPED, CLD_STOPPED);
- 	}
- out:
- 	spin_unlock_irq(&tsk->sighand->siglock);
+ /**
+diff --git a/kernel/ptrace.c b/kernel/ptrace.c
+index 23bd09c..b7c1d32 100644  
+--- a/kernel/ptrace.c
++++ b/kernel/ptrace.c
+@@ -271,7 +271,7 @@ static int ignoring_children(struct sigh
+  * reap it now, in that case we must also wake up sub-threads sleeping in
+  * do_wait().
+  */
+-static bool __ptrace_detach(struct task_struct *tracer, struct task_struct *p)
++bool __ptrace_detach(struct task_struct *tracer, struct task_struct *p)
+ {
+ 	__ptrace_unlink(p);
  
--	if (unlikely(group_stop) && tracehook_notify_jctl(1, CLD_STOPPED)) {
-+	if (unlikely(group_stop)) {
- 		read_lock(&tasklist_lock);
--		do_notify_parent_cldstop(tsk, CLD_STOPPED);
-+		do_notify_parent_cldstop(tsk, group_stop);
- 		read_unlock(&tasklist_lock);
- 	}
+diff --git a/kernel/signal.c b/kernel/signal.c
+index 6705320..9908335 100644  
+--- a/kernel/signal.c
++++ b/kernel/signal.c
+@@ -1461,7 +1461,7 @@ int do_notify_parent(struct task_struct 
+ 	return ret;
  }
+ 
+-static void do_notify_parent_cldstop(struct task_struct *tsk, int why)
++void do_notify_parent_cldstop(struct task_struct *tsk, int why)
+ {
+ 	struct siginfo info;
+ 	unsigned long flags;
+@@ -1731,7 +1731,7 @@ static int do_signal_stop(int signr)
+ static int ptrace_signal(int signr, siginfo_t *info,
+ 			 struct pt_regs *regs, void *cookie)
+ {
+-	if (!task_ptrace(current))
++	if (!(task_ptrace(current) & PT_PTRACED))
+ 		return signr;
+ 
+ 	ptrace_signal_deliver(regs, cookie);
+@@ -1807,11 +1807,6 @@ relock:
+ 
+ 	for (;;) {
+ 		struct k_sigaction *ka;
+-
+-		if (unlikely(signal->group_stop_count > 0) &&
+-		    do_signal_stop(0))
+-			goto relock;
+-
+ 		/*
+ 		 * Tracing can induce an artifical signal and choose sigaction.
+ 		 * The return value in @signr determines the default action,
+@@ -1823,6 +1818,10 @@ relock:
+ 		if (unlikely(signr != 0))
+ 			ka = return_ka;
+ 		else {
++			if (unlikely(signal->group_stop_count > 0) &&
++			    do_signal_stop(0))
++				goto relock;
++
+ 			signr = dequeue_signal(current, &current->blocked,
+ 					       info);
+ 

linux-2.6-utrace.patch:
 Documentation/DocBook/Makefile    |    2 
 Documentation/DocBook/utrace.tmpl |  590 +++++++++
 fs/proc/array.c                   |    3 
 include/linux/sched.h             |    5 
 include/linux/tracehook.h         |   87 +
 include/linux/utrace.h            |  694 ++++++++++
 init/Kconfig                      |    9 
 kernel/Makefile                   |    1 
 kernel/fork.c                     |    3 
 kernel/ptrace.c                   |   14 
 kernel/utrace.c                   | 2424 ++++++++++++++++++++++++++++++++++++++
 11 files changed, 3830 insertions(+), 2 deletions(-)

View full diff with command:
/usr/bin/cvs -n -f diff -kk -u -p -N -r 1.118 -r 1.119 linux-2.6-utrace.patchIndex: linux-2.6-utrace.patch
===================================================================
RCS file: /cvs/pkgs/rpms/kernel/devel/linux-2.6-utrace.patch,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -p -r1.118 -r1.119
--- linux-2.6-utrace.patch	28 Sep 2009 05:09:49 -0000	1.118
+++ linux-2.6-utrace.patch	16 Dec 2009 22:09:42 -0000	1.119
@@ -1,5 +1,45 @@
+utrace core
+
+This adds the utrace facility, a new modular interface in the kernel for
+implementing user thread tracing and debugging.  This fits on top of the
+tracehook_* layer, so the new code is well-isolated.
+
+The new interface is in <linux/utrace.h> and the DocBook utrace book
+describes it.  It allows for multiple separate tracing engines to work in
+parallel without interfering with each other.  Higher-level tracing
+facilities can be implemented as loadable kernel modules using this layer.
+
+The new facility is made optional under CONFIG_UTRACE.
+When this is not enabled, no new code is added.
+It can only be enabled on machines that have all the
+prerequisites and select CONFIG_HAVE_ARCH_TRACEHOOK.
+
+In this initial version, utrace and ptrace do not play together at all.
+If ptrace is attached to a thread, the attach calls in the utrace kernel
+API return -EBUSY.  If utrace is attached to a thread, the PTRACE_ATTACH
+or PTRACE_TRACEME request will return EBUSY to userland.  The old ptrace
+code is otherwise unchanged and nothing using ptrace should be affected
+by this patch as long as utrace is not used at the same time.  In the
+future we can clean up the ptrace implementation and rework it to use
+the utrace API.
+
+Signed-off-by: Roland McGrath <roland at redhat.com>
+---
+ Documentation/DocBook/Makefile    |    2 +-
+ Documentation/DocBook/utrace.tmpl |  590 +++++++++
+ fs/proc/array.c                   |    3 +
+ include/linux/sched.h             |    5 +
+ include/linux/tracehook.h         |   87 ++-
+ include/linux/utrace.h            |  694 +++++++++++
+ init/Kconfig                      |    9 +
+ kernel/Makefile                   |    1 +
+ kernel/fork.c                     |    3 +
+ kernel/ptrace.c                   |   14 +
+ kernel/utrace.c                   | 2424 +++++++++++++++++++++++++++++++++++++
+ 11 files changed, 3830 insertions(+), 2 deletions(-)
+
 diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile
-index ab8300f..95f59e4 100644
+index ab8300f..95f59e4 100644  
 --- a/Documentation/DocBook/Makefile
 +++ b/Documentation/DocBook/Makefile
 @@ -9,7 +9,7 @@
@@ -13,7 +53,7 @@ index ab8300f..95f59e4 100644
  	    mac80211.xml debugobjects.xml sh.xml regulator.xml \
 diff --git a/Documentation/DocBook/utrace.tmpl b/Documentation/DocBook/utrace.tmpl
 new file mode 100644
-index 0000000..6cc58a1
+index ...e149f49 100644  
 --- /dev/null
 +++ b/Documentation/DocBook/utrace.tmpl
 @@ -0,0 +1,590 @@
@@ -472,7 +512,7 @@ index 0000000..6cc58a1
 +  <function>utrace_finish_examine</function> surrounding the calls to
 +  <structname>struct user_regset</structname> functions or direct examination
 +  of task data structures.  <function>utrace_prepare_examine</function> returns
-+  an error if the task is not properly stopped and not dead.  After a
++  an error if the task is not properly stopped, or is dead.  After a
 +  successful examination, the paired <function>utrace_finish_examine</function>
 +  call returns an error if the task ever woke up during the examination.  If
 +  so, any data gathered may be scrambled and should be discarded.  This means
@@ -608,18 +648,18 @@ index 0000000..6cc58a1
 +
 +</book>
 diff --git a/fs/proc/array.c b/fs/proc/array.c
-index 07f77a7..882dc90 100644
+index 822c2d5..9069c91 100644  
 --- a/fs/proc/array.c
 +++ b/fs/proc/array.c
-@@ -83,6 +83,7 @@
+@@ -82,6 +82,7 @@
+ #include <linux/pid_namespace.h>
  #include <linux/ptrace.h>
  #include <linux/tracehook.h>
- #include <linux/swapops.h>
 +#include <linux/utrace.h>
+ #include <linux/swapops.h>
  
  #include <asm/pgtable.h>
- #include <asm/processor.h>
-@@ -189,6 +190,8 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
+@@ -189,6 +190,8 @@ static inline void task_state(struct seq
  		cred->uid, cred->euid, cred->suid, cred->fsuid,
  		cred->gid, cred->egid, cred->sgid, cred->fsgid);
  
@@ -628,36 +668,16 @@ index 07f77a7..882dc90 100644
  	task_lock(p);
  	if (p->files)
  		fdt = files_fdtable(p->files);
-diff --git a/include/linux/init_task.h b/include/linux/init_task.h
-index 21a6f5d..a598a6b 100644
---- a/include/linux/init_task.h
-+++ b/include/linux/init_task.h
-@@ -177,6 +177,7 @@ extern struct cred init_cred;
- 		[PIDTYPE_SID]  = INIT_PID_LINK(PIDTYPE_SID),		\
- 	},								\
- 	.dirties = INIT_PROP_LOCAL_SINGLE(dirties),			\
-+	INIT_UTRACE(tsk)						\
- 	INIT_IDS							\
- 	INIT_PERF_EVENTS(tsk)						\
- 	INIT_TRACE_IRQFLAGS						\
 diff --git a/include/linux/sched.h b/include/linux/sched.h
-index 75e6e60..94ca5c5 100644
+index 6c8928b..139d300 100644  
 --- a/include/linux/sched.h
 +++ b/include/linux/sched.h
-@@ -61,6 +61,7 @@ struct sched_param {
- #include <linux/errno.h>
- #include <linux/nodemask.h>
- #include <linux/mm_types.h>
-+#include <linux/utrace_struct.h>
- 
- #include <asm/system.h>
- #include <asm/page.h>
-@@ -1393,6 +1394,11 @@ struct task_struct {
+@@ -1393,6 +1393,11 @@ struct task_struct {
  #endif
  	seccomp_t seccomp;
  
 +#ifdef CONFIG_UTRACE
-+	struct utrace utrace;
++	struct utrace *utrace;
 +	unsigned long utrace_flags;
 +#endif
 +
@@ -665,7 +685,7 @@ index 75e6e60..94ca5c5 100644
     	u32 parent_exec_id;
     	u32 self_exec_id;
 diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
-index 1eb44a9..17c103e 100644
+index c78b2f4..0f5a48c 100644  
 --- a/include/linux/tracehook.h
 +++ b/include/linux/tracehook.h
 @@ -49,6 +49,7 @@
@@ -685,7 +705,7 @@ index 1eb44a9..17c103e 100644
  	return (task_ptrace(task) & PT_PTRACED) != 0;
  }
  
-@@ -111,6 +114,9 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
+@@ -111,6 +114,9 @@ static inline void ptrace_report_syscall
  static inline __must_check int tracehook_report_syscall_entry(
  	struct pt_regs *regs)
  {
@@ -695,16 +715,17 @@ index 1eb44a9..17c103e 100644
  	ptrace_report_syscall(regs);
  	return 0;
  }
-@@ -134,6 +140,8 @@ static inline __must_check int tracehook_report_syscall_entry(
+@@ -134,6 +140,9 @@ static inline __must_check int tracehook
   */
  static inline void tracehook_report_syscall_exit(struct pt_regs *regs, int step)
  {
 +	if (task_utrace_flags(current) & UTRACE_EVENT(SYSCALL_EXIT))
 +		utrace_report_syscall_exit(regs);
- 	ptrace_report_syscall(regs);
- }
- 
-@@ -194,6 +202,8 @@ static inline void tracehook_report_exec(struct linux_binfmt *fmt,
++
+ 	if (step && (task_ptrace(current) & PT_PTRACED)) {
+ 		siginfo_t info;
+ 		user_single_step_siginfo(current, regs, &info);
+@@ -201,6 +210,8 @@ static inline void tracehook_report_exec
  					 struct linux_binprm *bprm,
  					 struct pt_regs *regs)
  {
@@ -713,7 +734,7 @@ index 1eb44a9..17c103e 100644
  	if (!ptrace_event(PT_TRACE_EXEC, PTRACE_EVENT_EXEC, 0) &&
  	    unlikely(task_ptrace(current) & PT_PTRACED))
  		send_sig(SIGTRAP, current, 0);
-@@ -211,6 +221,8 @@ static inline void tracehook_report_exec(struct linux_binfmt *fmt,
+@@ -218,10 +229,37 @@ static inline void tracehook_report_exec
   */
  static inline void tracehook_report_exit(long *exit_code)
  {
@@ -722,15 +743,36 @@ index 1eb44a9..17c103e 100644
  	ptrace_event(PT_TRACE_EXIT, PTRACE_EVENT_EXIT, *exit_code);
  }
  
-@@ -254,6 +266,7 @@ static inline int tracehook_prepare_clone(unsigned clone_flags)
- static inline void tracehook_finish_clone(struct task_struct *child,
- 					  unsigned long clone_flags, int trace)
- {
-+	utrace_init_task(child);
- 	ptrace_init_task(child, (clone_flags & CLONE_PTRACE) || trace);
- }
- 
-@@ -278,6 +291,8 @@ static inline void tracehook_report_clone(struct pt_regs *regs,
[...2806 lines suppressed...]
++	utrace = task_utrace_struct(task);
++	if (utrace->resume < UTRACE_RESUME ||
++	    utrace->pending_attach || utrace->signal_handler) {
++		enum utrace_resume_action resume;
++
 +		/*
 +		 * We've been asked for an explicit report before we
 +		 * even check for pending signals.
@@ -3660,19 +3704,14 @@ index 0000000..74b5fc5
 +
 +		splice_attaching(utrace);
 +
-+		if (unlikely(!utrace->interrupt) && unlikely(!utrace->report))
-+			report.result = UTRACE_SIGNAL_IGN;
-+		else if (utrace->signal_handler)
-+			report.result = UTRACE_SIGNAL_HANDLER;
-+		else
-+			report.result = UTRACE_SIGNAL_REPORT;
++		report.result = utrace->signal_handler ?
++			UTRACE_SIGNAL_HANDLER : UTRACE_SIGNAL_REPORT;
++		utrace->signal_handler = 0;
 +
-+		/*
-+		 * We are now making the report and it's on the
-+		 * interrupt path, so clear the flags asking for those.
-+		 */
-+		utrace->interrupt = utrace->report = utrace->signal_handler = 0;
-+		utrace->stopped = 0;
++		resume = utrace->resume;
++		utrace->resume = UTRACE_RESUME;
++
++		spin_unlock(&utrace->lock);
 +
 +		/*
 +		 * Make sure signal_pending() only returns true
@@ -3684,13 +3723,21 @@ index 0000000..74b5fc5
 +			spin_unlock_irq(&task->sighand->siglock);
 +		}
 +
-+		spin_unlock(&utrace->lock);
-+
-+		if (unlikely(report.result == UTRACE_SIGNAL_IGN))
++		if (resume > UTRACE_REPORT) {
++			/*
++			 * We only got here to process utrace->resume.
++			 * Despite no callbacks, this report is not spurious.
++			 */
++			report.action = resume;
++			report.spurious = false;
++			finish_resume_report(task, utrace, &report);
++			return -1;
++		} else if (!(task->utrace_flags & UTRACE_EVENT(QUIESCE))) {
 +			/*
 +			 * We only got here to clear utrace->signal_handler.
 +			 */
 +			return -1;
++		}
 +
 +		/*
 +		 * Do a reporting pass for no signal, just for EVENT(QUIESCE).
@@ -3701,22 +3748,15 @@ index 0000000..74b5fc5
 +		event = 0;
 +		ka = NULL;
 +		memset(return_ka, 0, sizeof *return_ka);
-+	} else if ((task->utrace_flags & UTRACE_EVENT_SIGNAL_ALL) == 0 &&
-+		   !utrace->stopped) {
++	} else if (!(task->utrace_flags & UTRACE_EVENT_SIGNAL_ALL) ||
++		   unlikely(task->signal->group_stop_count)) {
 +		/*
-+		 * If no engine is interested in intercepting signals,
-+		 * let the caller just dequeue them normally.
++		 * If no engine is interested in intercepting signals or
++		 * we must stop, let the caller just dequeue them normally
++		 * or participate in group-stop.
 +		 */
 +		return 0;
 +	} else {
-+		if (unlikely(utrace->stopped)) {
-+			spin_unlock_irq(&task->sighand->siglock);
-+			spin_lock(&utrace->lock);
-+			utrace->stopped = 0;
-+			spin_unlock(&utrace->lock);
-+			spin_lock_irq(&task->sighand->siglock);
-+		}
-+
 +		/*
 +		 * Steal the next signal so we can let tracing engines
 +		 * examine it.  From the signal number and sigaction,
@@ -3801,11 +3841,11 @@ index 0000000..74b5fc5
 +
 +		if (ops->report_signal)
 +			ret = (*ops->report_signal)(
-+				report.result | report.action, engine, task,
++				report.result | report.action, engine,
 +				regs, info, ka, return_ka);
 +		else
 +			ret = (report.result | (*ops->report_quiesce)(
-+				       report.action, engine, task, event));
++				       report.action, engine, event));
 +
 +		/*
 +		 * Avoid a tight loop reporting again and again if some
@@ -3820,7 +3860,7 @@ index 0000000..74b5fc5
 +			break;
 +		}
 +
-+		finish_callback(utrace, &report, engine, ret);
++		finish_callback(task, utrace, &report, engine, ret);
 +	}
 +
 +	/*
@@ -3867,7 +3907,7 @@ index 0000000..74b5fc5
 +			 */
 +			if (report.action != UTRACE_RESUME)
 +				report.action = UTRACE_INTERRUPT;
-+			finish_report(&report, task, utrace);
++			finish_report(task, utrace, &report, true);
 +
 +			if (unlikely(report.result & UTRACE_SIGNAL_HOLD))
 +				push_back_signal(task, info);
@@ -3900,9 +3940,9 @@ index 0000000..74b5fc5
 +		 * as in utrace_resume(), above.  After we've dealt with that,
 +		 * our caller will relock and come back through here.
 +		 */
-+		finish_resume_report(&report, task, utrace);
++		finish_resume_report(task, utrace, &report);
 +
-+		if (unlikely(report.killed)) {
++		if (unlikely(fatal_signal_pending(task))) {
 +			/*
 +			 * The only reason we woke up now was because of a
 +			 * SIGKILL.  Don't do normal dequeuing in case it
@@ -3932,12 +3972,25 @@ index 0000000..74b5fc5
 +
 +	/*
 +	 * Complete the bookkeeping after the report.
-+	 * This sets utrace->report if UTRACE_STOP was used.
++	 * This sets utrace->resume if UTRACE_STOP was used.
 +	 */
-+	finish_report(&report, task, utrace);
++	finish_report(task, utrace, &report, true);
 +
 +	return_ka->sa.sa_handler = SIG_DFL;
 +
++	/*
++	 * If this signal is fatal, si_signo gets through as exit_code.
++	 * We can't allow a completely bogus value there or else core
++	 * kernel code can freak out.  (If an engine wants to control
++	 * the exit_code value exactly, it can do so in report_exit.)
++	 * We'll produce a big complaint in dmesg, but won't crash.
++	 * That's nicer for debugging your utrace engine.
++	 */
++	if (unlikely(info->si_signo & 0x80)) {
++		WARN(1, "utrace engine left bogus si_signo value!");
++		info->si_signo = SIGTRAP;
++	}
++
 +	if (unlikely(report.result & UTRACE_SIGNAL_HOLD))
 +		push_back_signal(task, info);
 +	else
@@ -3963,11 +4016,13 @@ index 0000000..74b5fc5
 +	spin_lock(&utrace->lock);
 +
 +	utrace->signal_handler = 1;
-+	if (stepping) {
-+		utrace->interrupt = 1;
-+		set_tsk_thread_flag(task, TIF_SIGPENDING);
-+	} else {
-+		set_tsk_thread_flag(task, TIF_NOTIFY_RESUME);
++	if (utrace->resume > UTRACE_INTERRUPT) {
++		if (stepping) {
++			utrace->resume = UTRACE_INTERRUPT;
++			set_tsk_thread_flag(task, TIF_SIGPENDING);
++		} else if (utrace->resume == UTRACE_RESUME) {
++			set_tsk_thread_flag(task, TIF_NOTIFY_RESUME);
++		}
 +	}
 +
 +	spin_unlock(&utrace->lock);
@@ -3983,7 +4038,7 @@ index 0000000..74b5fc5
 + * &struct user_regset calls, or direct access to thread-synchronous fields.
 + *
 + * When @target is current, this call is superfluous.  When @target is
-+ * another thread, it must held stopped via %UTRACE_STOP by @engine.
++ * another thread, it must be held stopped via %UTRACE_STOP by @engine.
 + *
 + * This call may block the caller until @target stays stopped, so it must
 + * be called only after the caller is sure @target is about to unschedule.
@@ -4094,10 +4149,5 @@ index 0000000..74b5fc5
 + */
 +void task_utrace_proc_status(struct seq_file *m, struct task_struct *p)
 +{
-+	struct utrace *utrace = &p->utrace;
-+	seq_printf(m, "Utrace:\t%lx%s%s%s\n",
-+		   p->utrace_flags,
-+		   utrace->stopped ? " (stopped)" : "",
-+		   utrace->report ? " (report)" : "",
-+		   utrace->interrupt ? " (interrupt)" : "");
++	seq_printf(m, "Utrace:\t%lx\n", p->utrace_flags);
 +}




More information about the fedora-extras-commits mailing list