Skip to contentSkip to conversation

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

PATCH New Andrey Vagin 1 participant 2 messages Mar 4, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 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.

v2: * don't wrapped on CONFIG_CHECKPOINT_RESTORE. This functionality is
going to be used in gdb.
* use ptrace_peeksiginfo_args, because addr is too small for encoding a signal number and flags.
v3: incorporate comments received from Andrew Morton
v4: make code a bit more obvious

Cc Roland McGrath <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Andrew Morton <akpm-de/[email protected]>
Cc "Paul E. McKenney" <[email protected]>
Cc David Howells <[email protected]>
Cc Dave Jones <[email protected]>
Cc "Michael Kerrisk (man-pages)" <[email protected]>
Cc Pavel Emelyanov <[email protected]>
Cc Linus Torvalds <torvalds-de/[email protected]>
Cc Pedro Alves <[email protected]>
---
 include/uapi/linux/ptrace.h | 12 +++++++
 kernel/ptrace.c             | 80 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+)
include/uapi/linux/ptrace.h +12 -0
index 022ab18..52ebcc8 100644
@@ -5,6 +5,7 @@
 
 /* has the defines to get at the registers. */
 
+#include <linux/types.h>
 
 #define PTRACE_TRACEME		   0
 #define PTRACE_PEEKTEXT		   1
@@ -52,6 +53,17 @@
 #define PTRACE_INTERRUPT	0x4207
 #define PTRACE_LISTEN		0x4208
 
+#define PTRACE_PEEKSIGINFO	0x4209
+
+struct ptrace_peeksiginfo_args {
+	__u64 off;	/* from which siginfo to start */
+	__u32 flags;
+	__s32 nr;	/* how may siginfos to take */
+};
+
+/* Read signals from a shared (process wide) queue */
+#define PTRACE_PEEKSIGINFO_SHARED	(1 << 0)
+
 /* Wait extended result codes for the above trace options.  */
 #define PTRACE_EVENT_FORK	1
 #define PTRACE_EVENT_VFORK	2
kernel/ptrace.c +80 -0

98 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#1 lore raw

PATCH 2/2 selftest: add a test case for PTRACE_PEEKSIGINFO

* Dump signals from process-wide and per-thread queues with different sizes of buffers.
* Check error paths for buffers with restricted permissions. A part of buffer or a whole buffer is for read-only.
* Try to get nonexistent signal.

Cc Roland McGrath <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Andrew Morton <akpm-de/[email protected]>
Cc "Paul E. McKenney" <[email protected]>
Cc David Howells <[email protected]>
Cc Dave Jones <[email protected]>
Cc "Michael Kerrisk (man-pages)" <[email protected]>
Cc Pavel Emelyanov <[email protected]>
Cc Linus Torvalds <torvalds-de/[email protected]>
Cc Pedro Alves <[email protected]>
---
 tools/testing/selftests/Makefile             |   1 +
 tools/testing/selftests/ptrace/Makefile      |  10 ++
 tools/testing/selftests/ptrace/peeksiginfo.c | 214 +++++++++++++++++++++++++++
 3 files changed, 225 insertions(+)
 create mode 100644 tools/testing/selftests/ptrace/Makefile
 create mode 100644 tools/testing/selftests/ptrace/peeksiginfo.c
tools/testing/selftests/Makefile +1 -0
index 3cc0ad7..575ef80 100644
@@ -5,6 +5,7 @@ TARGETS += vm
 TARGETS += cpu-hotplug
 TARGETS += memory-hotplug
 TARGETS += efivarfs
+TARGETS += ptrace
 
 all:
 	for TARGET in $(TARGETS); do \
tools/testing/selftests/ptrace/Makefile new file +10 -0
new file mode 100644
index 0000000..47ae2d3
@@ -0,0 +1,10 @@
+CFLAGS += -iquote../../../../include/uapi -Wall
+peeksiginfo: peeksiginfo.c
+
+all: peeksiginfo
+
+clean:
+	rm -f peeksiginfo
+
+run_tests: all
+	@./peeksiginfo || echo "peeksiginfo selftests: [FAIL]"
tools/testing/selftests/ptrace/peeksiginfo.c new file +214 -0

214 lines not on this page · raw message

Signature · 1 line
1.7.11.7