History

ptrace: add ability to retrieve signals without removing from a queue (v4)

This patch adds a new ptrace request PTRACE_PEEKSIGINFO. This request is used to retrieve information about pending signals starting with the specified sequence number. Siginfo_t structures are copied from the child into the buffer starting at "data". The argument "addr" is a pointer to struct ptrace_peeksiginfo_args. struct ptrace_peeksiginfo_args { u64 off; /* from which siginfo to start */ u32 flags; s32 nr; /* how may siginfos to take */ }; "nr" has type "s32", because ptrace() returns "long", which has 32 bits on i386 and a negative values is used for errors. Currently here is only one flag PTRACE_PEEKSIGINFO_SHARED for dumping signals from process-wide queue. If this flag is not set, signals are read from a per-thread queue. The request PTRACE_PEEKSIGINFO returns a number of dumped signals. If a signal with the specified sequence number doesn't exist, ptrace returns zero. The request returns an error, if no signal has been dumped. Errors: EINVAL - one or more specified flags are not supported or nr is negative EFAULT - buf or addr is outside your accessible address space. A result siginfo contains a kernel part of si_code which usually striped, but it's required for queuing the same siginfo back during restore of pending signals. This functionality is required for checkpointing pending signals. Pedro Alves suggested using it in "gdb" to peek at pending signals. gdb already uses PTRACE_GETSIGINFO to get the siginfo for the signal which was already dequeued. This functionality allows gdb to look at the pending signals which were not reported yet. The prototype of this code was developed by Oleg Nesterov.

Andrey Vagin committed 13 years ago

Commit 84c751b1 parent 865f38a2 files · +92 −0Browse files

Showing the changes to include/uapi (1 of 2 files). Show all

Unified · Split

include/uapi/linux/ptrace.h+12−0
@@ -5,6 +5,7 @@ · 4 unmodified lines
5 5
6/* has the defines to get at the registers. */6/* has the defines to get at the registers. */
7 7
8#include <linux/types.h>
8 9
9#define PTRACE_TRACEME 010#define PTRACE_TRACEME 0
10#define PTRACE_PEEKTEXT 111#define PTRACE_PEEKTEXT 1
@@ -52,6 +53,17 @@ · 41 unmodified lines
52#define PTRACE_INTERRUPT 0x420753#define PTRACE_INTERRUPT 0x4207
53#define PTRACE_LISTEN 0x420854#define PTRACE_LISTEN 0x4208
54 55
56#define PTRACE_PEEKSIGINFO 0x4209
57
58struct ptrace_peeksiginfo_args {
59 __u64 off; /* from which siginfo to start */
60 __u32 flags;
61 __s32 nr; /* how may siginfos to take */
62};
63
64/* Read signals from a shared (process wide) queue */
65#define PTRACE_PEEKSIGINFO_SHARED (1 << 0)
66
55/* Wait extended result codes for the above trace options. */67/* Wait extended result codes for the above trace options. */
56#define PTRACE_EVENT_FORK 168#define PTRACE_EVENT_FORK 1
57#define PTRACE_EVENT_VFORK 269#define PTRACE_EVENT_VFORK 2