Commit 1b38f006 authored by Bodo Stroesser's avatar Bodo Stroesser Committed by Linus Torvalds

[PATCH] Uml support: add PTRACE_SYSEMU_SINGLESTEP option to i386

This patch implements the new ptrace option PTRACE_SYSEMU_SINGLESTEP, which
can be used by UML to singlestep a process: it will receive SINGLESTEP
interceptions for normal instructions and syscalls, but syscall execution will
be skipped just like with PTRACE_SYSEMU.
Signed-off-by: default avatarBodo Stroesser <bstroesser@fujitsu-siemens.com>
Signed-off-by: default avatarPaolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Cc: Jeff Dike <jdike@addtoit.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent c8c86cec
...@@ -547,11 +547,17 @@ asmlinkage int sys_ptrace(long request, long pid, long addr, long data) ...@@ -547,11 +547,17 @@ asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
wake_up_process(child); wake_up_process(child);
break; break;
case PTRACE_SYSEMU_SINGLESTEP: /* Same as SYSEMU, but singlestep if not syscall */
case PTRACE_SINGLESTEP: /* set the trap flag. */ case PTRACE_SINGLESTEP: /* set the trap flag. */
ret = -EIO; ret = -EIO;
if (!valid_signal(data)) if (!valid_signal(data))
break; break;
if (request == PTRACE_SYSEMU_SINGLESTEP)
set_tsk_thread_flag(child, TIF_SYSCALL_EMU);
else
clear_tsk_thread_flag(child, TIF_SYSCALL_EMU); clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
set_singlestep(child); set_singlestep(child);
child->exit_code = data; child->exit_code = data;
...@@ -686,7 +692,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code) ...@@ -686,7 +692,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code)
__attribute__((regparm(3))) __attribute__((regparm(3)))
int do_syscall_trace(struct pt_regs *regs, int entryexit) int do_syscall_trace(struct pt_regs *regs, int entryexit)
{ {
int is_sysemu, is_singlestep, ret = 0; int is_sysemu = test_thread_flag(TIF_SYSCALL_EMU), ret = 0;
/* With TIF_SYSCALL_EMU set we want to ignore TIF_SINGLESTEP */
int is_singlestep = !is_sysemu && test_thread_flag(TIF_SINGLESTEP);
/* do the secure computing check first */ /* do the secure computing check first */
secure_computing(regs->orig_eax); secure_computing(regs->orig_eax);
...@@ -696,8 +705,11 @@ int do_syscall_trace(struct pt_regs *regs, int entryexit) ...@@ -696,8 +705,11 @@ int do_syscall_trace(struct pt_regs *regs, int entryexit)
if (!(current->ptrace & PT_PTRACED)) if (!(current->ptrace & PT_PTRACED))
goto out; goto out;
is_sysemu = test_thread_flag(TIF_SYSCALL_EMU); /* If a process stops on the 1st tracepoint with SYSCALL_TRACE
is_singlestep = test_thread_flag(TIF_SINGLESTEP); * and then is resumed with SYSEMU_SINGLESTEP, it will come in
* here. We have to check this and return */
if (is_sysemu && entryexit)
return 0;
/* Fake a debug trap */ /* Fake a debug trap */
if (is_singlestep) if (is_singlestep)
...@@ -728,6 +740,7 @@ int do_syscall_trace(struct pt_regs *regs, int entryexit) ...@@ -728,6 +740,7 @@ int do_syscall_trace(struct pt_regs *regs, int entryexit)
if (ret == 0) if (ret == 0)
return 0; return 0;
regs->orig_eax = -1; /* force skip of syscall restarting */
if (unlikely(current->audit_context)) if (unlikely(current->audit_context))
audit_syscall_exit(current, AUDITSC_RESULT(regs->eax), regs->eax); audit_syscall_exit(current, AUDITSC_RESULT(regs->eax), regs->eax);
return 1; return 1;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#define PTRACE_SYSCALL 24 #define PTRACE_SYSCALL 24
#define PTRACE_SYSEMU 31 #define PTRACE_SYSEMU 31
#define PTRACE_SYSEMU_SINGLESTEP 32
/* 0x4200-0x4300 are reserved for architecture-independent additions. */ /* 0x4200-0x4300 are reserved for architecture-independent additions. */
#define PTRACE_SETOPTIONS 0x4200 #define PTRACE_SETOPTIONS 0x4200
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment