Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Refactor ptrace_watchpoint structure to allow extensions
details: https://anonhg.NetBSD.org/src/rev/2f0650f6419d
branches: trunk
changeset: 350711:2f0650f6419d
user: kamil <kamil%NetBSD.org@localhost>
date: Mon Jan 16 21:35:59 2017 +0000
description:
Refactor ptrace_watchpoint structure to allow extensions
Add new field pw_type in the ptrace_watchpoint structure.
amd64 and i386 offer the current set of watchpoints as
PTRACE_PW_TYPE_DBREGS.
On other archs than x86, there are readily available different types of
hardware assisted watchpoints like for code-only or data-only registers on
ARM. Also in future there is an option to implement MMU-based watchpoints
and future per-port or per-cpu extensions.
Next step is to alter this interface on x86 to generate SIGTRAP with
si_code TRAP_HWWTRAP with additional information on occurred event:
- which watchpoint fired,
- additional watchpoint-type specific information, like on amd64 with
PTRACE_PW_TYPE_DBREGS.:
* only watchpoint fired
* watchpoint fired and single step occurred
Adjust ATF tests for the pw_type change.
Sponsored by <The NetBSD Foundation>
diffstat:
sys/arch/amd64/amd64/process_machdep.c | 8 ++++++--
sys/arch/amd64/include/ptrace.h | 28 ++++++++++++++++++++++------
sys/arch/i386/i386/process_machdep.c | 8 ++++++--
sys/arch/i386/include/ptrace.h | 28 ++++++++++++++++++++++------
sys/sys/ptrace.h | 3 ++-
tests/kernel/arch/amd64/t_ptrace_wait.c | 30 ++++++++++++++++++++++++++++--
6 files changed, 86 insertions(+), 19 deletions(-)
diffs (truncated from 413 to 300 lines):
diff -r 28d1b91564f5 -r 2f0650f6419d sys/arch/amd64/amd64/process_machdep.c
--- a/sys/arch/amd64/amd64/process_machdep.c Mon Jan 16 21:19:35 2017 +0000
+++ b/sys/arch/amd64/amd64/process_machdep.c Mon Jan 16 21:35:59 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: process_machdep.c,v 1.30 2016/12/15 12:04:17 kamil Exp $ */
+/* $NetBSD: process_machdep.c,v 1.31 2017/01/16 21:35:59 kamil Exp $ */
/*-
* Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.30 2016/12/15 12:04:17 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.31 2017/01/16 21:35:59 kamil Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -182,6 +182,7 @@
process_read_watchpoint(struct lwp *l, struct ptrace_watchpoint *pw)
{
+ pw->pw_type = PTRACE_PW_TYPE_DBREGS;
pw->pw_md.md_address =
(void*)(intptr_t)l->l_md.md_watchpoint[pw->pw_index].address;
pw->pw_md.md_condition = l->l_md.md_watchpoint[pw->pw_index].condition;
@@ -210,6 +211,9 @@
if (pw->pw_index > X86_HW_WATCHPOINTS)
return (EINVAL);
+ if (pw->pw_type != PTRACE_PW_TYPE_DBREGS)
+ return (EINVAL);
+
if (pw->pw_md.md_address == 0) {
l->l_md.md_watchpoint[pw->pw_index].address = 0;
update_mdl_x86_hw_watchpoints(l);
diff -r 28d1b91564f5 -r 2f0650f6419d sys/arch/amd64/include/ptrace.h
--- a/sys/arch/amd64/include/ptrace.h Mon Jan 16 21:19:35 2017 +0000
+++ b/sys/arch/amd64/include/ptrace.h Mon Jan 16 21:35:59 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ptrace.h,v 1.8 2016/12/15 12:04:17 kamil Exp $ */
+/* $NetBSD: ptrace.h,v 1.9 2017/01/16 21:35:59 kamil Exp $ */
/*
* Copyright (c) 1993 Christopher G. Demetriou
@@ -68,6 +68,22 @@
#define __HAVE_PTRACE_WATCHPOINTS
/*
+ * The current list of supported hardware watchpoints
+ */
+#define PTRACE_PW_TYPE_DBREGS 1
+
+struct mdpw {
+ union {
+ /* Debug Registers DR0-3, DR6, DR7 */
+ struct {
+ void *_md_address;
+ int _md_condition;
+ int _md_length;
+ } _dbregs;
+ } _type;
+};
+
+/*
* This MD structure translates into x86_hw_watchpoint
*
* pw_address - 0 represents disabled hardware watchpoint
@@ -87,11 +103,11 @@
* Helper symbols for conditions and length are available in <x86/dbregs.h>
*
*/
-struct mdpw {
- void *md_address;
- int md_condition;
- int md_length;
-};
+
+#define md_address _type._dbregs._md_address
+#define md_condition _type._dbregs._md_condition
+#define md_length _type._dbregs._md_length
+
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd32.h"
diff -r 28d1b91564f5 -r 2f0650f6419d sys/arch/i386/i386/process_machdep.c
--- a/sys/arch/i386/i386/process_machdep.c Mon Jan 16 21:19:35 2017 +0000
+++ b/sys/arch/i386/i386/process_machdep.c Mon Jan 16 21:35:59 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: process_machdep.c,v 1.87 2016/12/15 12:04:18 kamil Exp $ */
+/* $NetBSD: process_machdep.c,v 1.88 2017/01/16 21:35:59 kamil Exp $ */
/*-
* Copyright (c) 1998, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.87 2016/12/15 12:04:18 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.88 2017/01/16 21:35:59 kamil Exp $");
#include "opt_vm86.h"
#include "opt_ptrace.h"
@@ -362,6 +362,7 @@
process_read_watchpoint(struct lwp *l, struct ptrace_watchpoint *pw)
{
+ pw->pw_type = PTRACE_PW_TYPE_DBREGS;
pw->pw_md.md_address =
(void*)(intptr_t)l->l_md.md_watchpoint[pw->pw_index].address;
pw->pw_md.md_condition = l->l_md.md_watchpoint[pw->pw_index].condition;
@@ -390,6 +391,9 @@
if (pw->pw_index > X86_HW_WATCHPOINTS)
return (EINVAL);
+ if (pw->pw_type != PTRACE_PW_TYPE_DBREGS)
+ return (EINVAL);
+
if (pw->pw_md.md_address == 0) {
l->l_md.md_watchpoint[pw->pw_index].address = 0;
update_mdl_x86_hw_watchpoints(l);
diff -r 28d1b91564f5 -r 2f0650f6419d sys/arch/i386/include/ptrace.h
--- a/sys/arch/i386/include/ptrace.h Mon Jan 16 21:19:35 2017 +0000
+++ b/sys/arch/i386/include/ptrace.h Mon Jan 16 21:35:59 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ptrace.h,v 1.16 2016/12/15 12:04:18 kamil Exp $ */
+/* $NetBSD: ptrace.h,v 1.17 2017/01/16 21:35:59 kamil Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -115,6 +115,22 @@
#define __HAVE_PTRACE_WATCHPOINTS
/*
+ * The current list of supported hardware watchpoints
+ */
+#define PTRACE_PW_TYPE_DBREGS 1
+
+struct mdpw {
+ union {
+ /* Debug Registers DR0-3, DR6, DR7 */
+ struct {
+ void *_md_address;
+ int _md_condition;
+ int _md_length;
+ } _dbregs;
+ } _type;
+};
+
+/*
* This MD structure translates into x86_hw_watchpoint
*
* pw_address - 0 represents disabled hardware watchpoint
@@ -134,11 +150,11 @@
* Helper symbols for conditions and length are available in <x86/dbregs.h>
*
*/
-struct mdpw {
- void *md_address;
- int md_condition;
- int md_length;
-};
+
+#define md_address _type._dbregs._md_address
+#define md_condition _type._dbregs._md_condition
+#define md_length _type._dbregs._md_length
+
#ifdef _KERNEL
diff -r 28d1b91564f5 -r 2f0650f6419d sys/sys/ptrace.h
--- a/sys/sys/ptrace.h Mon Jan 16 21:19:35 2017 +0000
+++ b/sys/sys/ptrace.h Mon Jan 16 21:35:59 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ptrace.h,v 1.54 2017/01/14 06:36:52 kamil Exp $ */
+/* $NetBSD: ptrace.h,v 1.55 2017/01/16 21:35:59 kamil Exp $ */
/*-
* Copyright (c) 1984, 1993
@@ -142,6 +142,7 @@
typedef struct ptrace_watchpoint {
int pw_index; /* HW Watchpoint ID (count from 0) */
lwpid_t pw_lwpid; /* LWP described */
+ int pw_type; /* HW Watchpoint type w/ MD content */
#ifdef __HAVE_PTRACE_WATCHPOINTS
struct mdpw pw_md; /* MD fields */
#endif
diff -r 28d1b91564f5 -r 2f0650f6419d tests/kernel/arch/amd64/t_ptrace_wait.c
--- a/tests/kernel/arch/amd64/t_ptrace_wait.c Mon Jan 16 21:19:35 2017 +0000
+++ b/tests/kernel/arch/amd64/t_ptrace_wait.c Mon Jan 16 21:35:59 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ptrace_wait.c,v 1.9 2017/01/13 21:30:41 christos Exp $ */
+/* $NetBSD: t_ptrace_wait.c,v 1.10 2017/01/16 21:35:59 kamil Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.9 2017/01/13 21:30:41 christos Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.10 2017/01/16 21:35:59 kamil Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -247,6 +247,7 @@
printf("struct ptrace {\n");
printf("\t.pw_index=%d\n", pw.pw_index);
printf("\t.pw_lwpid=%d\n", pw.pw_lwpid);
+ printf("\t.pw_type=%#x\n", pw.pw_type);
printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address);
printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition);
printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length);
@@ -320,6 +321,7 @@
printf("struct ptrace {\n");
printf("\t.pw_index=%d\n", pw.pw_index);
printf("\t.pw_lwpid=%d\n", pw.pw_lwpid);
+ printf("\t.pw_type=%#x\n", pw.pw_type);
printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address);
printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition);
printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length);
@@ -390,6 +392,7 @@
pw.pw_index = i;
pw.pw_lwpid = 0;
+ pw.pw_type = PTRACE_PW_TYPE_DBREGS;
pw.pw_md.md_address = (void *)check_happy;
pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_EXECUTION;
pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE;
@@ -397,6 +400,7 @@
printf("struct ptrace {\n");
printf("\t.pw_index=%d\n", pw.pw_index);
printf("\t.pw_lwpid=%d\n", pw.pw_lwpid);
+ printf("\t.pw_type=%#x\n", pw.pw_type);
printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address);
printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition);
printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length);
@@ -478,6 +482,7 @@
pw.pw_index = i;
pw.pw_lwpid = 0;
+ pw.pw_type = PTRACE_PW_TYPE_DBREGS;
pw.pw_md.md_address = (void *)check_happy;
pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_EXECUTION;
pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE;
@@ -485,6 +490,7 @@
printf("struct ptrace {\n");
printf("\t.pw_index=%d\n", pw.pw_index);
printf("\t.pw_lwpid=%d\n", pw.pw_lwpid);
+ printf("\t.pw_type=%d\n", pw.pw_type);
printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address);
printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition);
printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length);
@@ -566,6 +572,7 @@
pw.pw_index = i;
pw.pw_lwpid = 0;
+ pw.pw_type = PTRACE_PW_TYPE_DBREGS;
pw.pw_md.md_address = (void *)check_happy;
pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_EXECUTION;
pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE;
@@ -573,6 +580,7 @@
printf("struct ptrace {\n");
printf("\t.pw_index=%d\n", pw.pw_index);
printf("\t.pw_lwpid=%d\n", pw.pw_lwpid);
+ printf("\t.pw_type=%#x\n", pw.pw_type);
printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address);
printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition);
printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length);
@@ -654,6 +662,7 @@
pw.pw_index = i;
pw.pw_lwpid = 0;
+ pw.pw_type = PTRACE_PW_TYPE_DBREGS;
pw.pw_md.md_address = (void *)check_happy;
pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_EXECUTION;
pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE;
@@ -661,6 +670,7 @@
printf("struct ptrace {\n");
printf("\t.pw_index=%d\n", pw.pw_index);
printf("\t.pw_lwpid=%d\n", pw.pw_lwpid);
+ printf("\t.pw_type=%#x\n", pw.pw_type);
printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address);
printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition);
printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length);
@@ -741,6 +751,7 @@
printf("Preparing code watchpoint trap %d\n", i);
pw.pw_index = 0;
+ pw.pw_type = PTRACE_PW_TYPE_DBREGS;
pw.pw_md.md_address = &watchme;
pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_DATA_WRITE;
pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE;
@@ -748,6 +759,7 @@
printf("struct ptrace {\n");
printf("\t.pw_index=%d\n", pw.pw_index);
printf("\t.pw_lwpid=%d\n", pw.pw_lwpid);
+ printf("\t.pw_type=%#x\n", pw.pw_type);
printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address);
printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition);
Home |
Main Index |
Thread Index |
Old Index