patch-2.4.15 linux/kernel/ptrace.c

Next file: linux/kernel/sched.c
Previous file: linux/kernel/printk.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.14/linux/kernel/ptrace.c linux/kernel/ptrace.c
@@ -16,6 +16,42 @@
 #include <asm/pgtable.h>
 #include <asm/uaccess.h>
 
+/*
+ * Check that we have indeed attached to the thing..
+ */
+int ptrace_check_attach(struct task_struct *child, int kill)
+{
+	if (!(child->ptrace & PT_PTRACED))
+		return -ESRCH;
+
+	if (child->p_pptr != current)
+		return -ESRCH;
+
+	if (!kill) {
+		if (child->state != TASK_STOPPED)
+			return -ESRCH;
+#ifdef CONFIG_SMP
+		/* Make sure the child gets off its CPU.. */
+		for (;;) {
+			task_lock(child);
+			if (!task_has_cpu(child))
+				break;
+			task_unlock(child);
+			do {
+				if (child->state != TASK_STOPPED)
+					return -ESRCH;
+				barrier();
+				cpu_relax();
+			} while (task_has_cpu(child));
+		}
+		task_unlock(child);
+#endif		
+	}
+
+	/* All systems go.. */
+	return 0;
+}
+
 int ptrace_attach(struct task_struct *task)
 {
 	task_lock(task);

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)