mv kernel/ptrace.c kernel/ptrace-utrace.c.
Then I will send the patch which restores the old ptrace.c and
moves kernel/ptrace-common.h into it as you suggested before.
I am not sure what is the best way to do these renames but I hope
this doesn't really matter, utrace-ptrace branch is only for us.
The goal is to make it testable with and without CONFIG_UTRACE.
---
kernel/Makefile|1 +
kernel/ptrace-utrace.c | 1117
kernel/ptrace.c| 1117
3 files changed, 1118 insertions(+), 1117 deletions(-)
create mode 100644 kernel/ptrace-utrace.c
delete mode 100644 kernel/ptrace.c
diff --git a/kernel/Makefile b/kernel/Makefile
index 8f41620..04e9139 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -69,6 +69,7 @@ obj-$(CONFIG_RESOURCE_COUNTERS) += res_counter.o
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 000..e10410c
--- /dev/null
+++ b/kernel/ptrace-utrace.c
@@ -0,0 +1,1117 @@
+/*
+ * 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
+#include ptrace-common.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 0x1000
+
+#define PTRACE_O_SYSEMU0x100
+
+#define PTRACE_EVENT_SYSCALL_ENTRY (1 16)
+#define PTRACE_EVENT_SYSCALL_EXIT (2 16)
+#define PTRACE_EVENT_SIGTRAP (3 16)
+#define PTRACE_EVENT_SIGNAL(4 16)
+/* events visible to user-space */
+#define PTRACE_EVENT_MASK 0x
+
+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