diff options
| author | Daniel Jacobowitz <drow@nevyn.them.org> | 2003-01-18 10:40:18 -0500 |
|---|---|---|
| committer | Daniel Jacobowitz <drow@nevyn.them.org> | 2003-01-18 10:40:18 -0500 |
| commit | 1669ce53e2ff7b49a60d0230866d3faee5f45573 (patch) | |
| tree | 91142ab5c0f46caac2583ad81492f3f4e42fdea5 | |
| parent | 98a3d3b1f9b82e88d4e4a338b20532c628b347e5 (diff) | |
Add PTRACE_GETSIGINFO and PTRACE_SETSIGINFO
These new ptrace commands allow a debugger to control signals more precisely;
for instance, store a signal and deliver it later, as if it had come from the
original outside process or in response to the same faulting memory access.
| -rw-r--r-- | include/linux/ptrace.h | 2 | ||||
| -rw-r--r-- | include/linux/sched.h | 1 | ||||
| -rw-r--r-- | kernel/ptrace.c | 23 | ||||
| -rw-r--r-- | kernel/signal.c | 8 |
4 files changed, 33 insertions, 1 deletions
diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h index c6de3a4ea70a..b56bbe7ca800 100644 --- a/include/linux/ptrace.h +++ b/include/linux/ptrace.h @@ -26,6 +26,8 @@ /* 0x4200-0x4300 are reserved for architecture-independent additions. */ #define PTRACE_SETOPTIONS 0x4200 #define PTRACE_GETEVENTMSG 0x4201 +#define PTRACE_GETSIGINFO 0x4202 +#define PTRACE_SETSIGINFO 0x4203 /* options set using PTRACE_SETOPTIONS */ #define PTRACE_O_TRACESYSGOOD 0x00000001 diff --git a/include/linux/sched.h b/include/linux/sched.h index 15a951d2d27e..a325e5a8c645 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -400,6 +400,7 @@ struct task_struct { struct backing_dev_info *backing_dev_info; unsigned long ptrace_message; + siginfo_t *last_siginfo; /* For ptrace use. */ }; extern void __put_task_struct(struct task_struct *tsk); diff --git a/kernel/ptrace.c b/kernel/ptrace.c index a16dfb90d412..9f3769bfdc7e 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -286,6 +286,23 @@ static int ptrace_setoptions(struct task_struct *child, long data) return 0; } +static int ptrace_getsiginfo(struct task_struct *child, long data) +{ + if (child->last_siginfo == NULL) + return -EINVAL; + return copy_siginfo_to_user ((siginfo_t *) data, child->last_siginfo); +} + +static int ptrace_setsiginfo(struct task_struct *child, long data) +{ + if (child->last_siginfo == NULL) + return -EINVAL; + if (copy_from_user (child->last_siginfo, (siginfo_t *) data, + sizeof (siginfo_t)) != 0) + return -EFAULT; + return 0; +} + int ptrace_request(struct task_struct *child, long request, long addr, long data) { @@ -301,6 +318,12 @@ int ptrace_request(struct task_struct *child, long request, case PTRACE_GETEVENTMSG: ret = put_user(child->ptrace_message, (unsigned long *) data); break; + case PTRACE_GETSIGINFO: + ret = ptrace_getsiginfo(child, data); + break; + case PTRACE_SETSIGINFO: + ret = ptrace_setsiginfo(child, data); + break; default: break; } diff --git a/kernel/signal.c b/kernel/signal.c index 7c485d01a4b0..b683402178ec 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1244,10 +1244,13 @@ int get_signal_to_deliver(siginfo_t *info, struct pt_regs *regs) if ((current->ptrace & PT_PTRACED) && signr != SIGKILL) { /* Let the debugger run. */ current->exit_code = signr; + current->last_siginfo = info; set_current_state(TASK_STOPPED); notify_parent(current, SIGCHLD); schedule(); + current->last_siginfo = NULL; + /* We're back. Did the debugger cancel the sig? */ signr = current->exit_code; if (signr == 0) @@ -1258,7 +1261,10 @@ int get_signal_to_deliver(siginfo_t *info, struct pt_regs *regs) if (signr == SIGSTOP) continue; - /* Update the siginfo structure. Is this good? */ + /* Update the siginfo structure if the signal has + changed. If the debugger wanted something + specific in the siginfo structure then it should + have updated *info via PTRACE_SETSIGINFO. */ if (signr != info->si_signo) { info->si_signo = signr; info->si_errno = 0; |
