Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/i386 add KSTACK_CHECK_DR0.



details:   https://anonhg.NetBSD.org/src/rev/94c62b42efab
branches:  trunk
changeset: 533518:94c62b42efab
user:      yamt <yamt%NetBSD.org@localhost>
date:      Wed Jul 03 02:46:11 2002 +0000

description:
add KSTACK_CHECK_DR0.

diffstat:

 sys/arch/i386/conf/files.i386   |   7 +++++--
 sys/arch/i386/i386/pmap.c       |  15 +++++++++++++--
 sys/arch/i386/i386/trap.c       |  20 ++++++++++++++++++--
 sys/arch/i386/include/cpufunc.h |  20 +++++++++++++++++++-
 4 files changed, 55 insertions(+), 7 deletions(-)

diffs (146 lines):

diff -r 3d1f810ba4de -r 94c62b42efab sys/arch/i386/conf/files.i386
--- a/sys/arch/i386/conf/files.i386     Wed Jul 03 02:19:55 2002 +0000
+++ b/sys/arch/i386/conf/files.i386     Wed Jul 03 02:46:11 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.i386,v 1.208 2002/06/18 07:56:12 tshiozak Exp $
+#      $NetBSD: files.i386,v 1.209 2002/07/03 02:46:11 yamt Exp $
 #
 # new style config file for i386 architecture
 #
@@ -57,11 +57,14 @@
 # Large page size
 defflag                        LARGEPAGES
 
+# kernel stack debug
+defflag        opt_kstack_dr0.h                KSTACK_CHECK_DR0
+
 file   arch/i386/i386/autoconf.c
 file   arch/i386/i386/bus_machdep.c
 file   arch/i386/i386/conf.c
 file   arch/i386/i386/consinit.c
-file   arch/i386/i386/db_dbgreg.s      ddb
+file   arch/i386/i386/db_dbgreg.s      ddb | kstack_check_dr0
 file   arch/i386/i386/db_disasm.c      ddb
 file   arch/i386/i386/db_interface.c   ddb
 file   arch/i386/i386/db_memrw.c       ddb | kgdb
diff -r 3d1f810ba4de -r 94c62b42efab sys/arch/i386/i386/pmap.c
--- a/sys/arch/i386/i386/pmap.c Wed Jul 03 02:19:55 2002 +0000
+++ b/sys/arch/i386/i386/pmap.c Wed Jul 03 02:46:11 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.136 2002/03/27 04:47:28 chs Exp $   */
+/*     $NetBSD: pmap.c,v 1.137 2002/07/03 02:46:13 yamt Exp $  */
 
 /*
  *
@@ -60,11 +60,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.136 2002/03/27 04:47:28 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.137 2002/07/03 02:46:13 yamt Exp $");
 
 #include "opt_cputype.h"
 #include "opt_user_ldt.h"
 #include "opt_largepages.h"
+#include "opt_kstack_dr0.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1675,6 +1676,16 @@
                lcr3(pcb->pcb_cr3);
        if (pcb == curpcb)
                lldt(pcb->pcb_ldt_sel);
+
+#ifdef KSTACK_CHECK_DR0
+       /*
+        * setup breakpoint on the top of stack
+        */
+       if (p == &proc0)
+               dr0(0, 0, 0, 0);
+       else
+               dr0(KSTACK_LOWEST_ADDR(p), 1, 3, 1);
+#endif
 }
 
 /*
diff -r 3d1f810ba4de -r 94c62b42efab sys/arch/i386/i386/trap.c
--- a/sys/arch/i386/i386/trap.c Wed Jul 03 02:19:55 2002 +0000
+++ b/sys/arch/i386/i386/trap.c Wed Jul 03 02:46:11 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.165 2002/02/18 15:58:02 simonb Exp $        */
+/*     $NetBSD: trap.c,v 1.166 2002/07/03 02:46:15 yamt Exp $  */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -79,13 +79,14 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.165 2002/02/18 15:58:02 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.166 2002/07/03 02:46:15 yamt Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
 #include "opt_math_emulate.h"
 #include "opt_vm86.h"
 #include "opt_cputype.h"
+#include "opt_kstack_dr0.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -202,6 +203,21 @@
 
        default:
        we_re_toast:
+#ifdef KSTACK_CHECK_DR0
+               if (type == T_TRCTRAP) {
+                       u_int mask, dr6 = rdr6();
+
+                       mask = 1 << 0; /* dr0 */
+                       if (dr6 & mask) {
+                               panic("trap on DR0: maybe kernel stack overflow\n");
+#if 0
+                               dr6 &= ~mask;
+                               ldr6(dr6);
+                               return;
+#endif
+                       }
+               }
+#endif
 #ifdef KGDB
                if (kgdb_trap(type, &frame))
                        return;
diff -r 3d1f810ba4de -r 94c62b42efab sys/arch/i386/include/cpufunc.h
--- a/sys/arch/i386/include/cpufunc.h   Wed Jul 03 02:19:55 2002 +0000
+++ b/sys/arch/i386/include/cpufunc.h   Wed Jul 03 02:46:11 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpufunc.h,v 1.20 2001/07/31 18:28:59 thorpej Exp $     */
+/*     $NetBSD: cpufunc.h,v 1.21 2002/07/03 02:46:16 yamt Exp $        */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -134,6 +134,24 @@
 void   setidt  __P((int idx, /*XXX*/caddr_t func, int typ, int dpl));
 #endif
 
+/* debug register */
+void dr0(caddr_t, u_int32_t, u_int32_t, u_int32_t);
+
+static __inline u_int
+rdr6(void)
+{
+       u_int val;
+
+       __asm __volatile("movl %%dr6,%0" : "=r" (val));
+       return val;
+}
+
+static __inline void
+ldr6(u_int val)
+{
+
+       __asm __volatile("movl %0,%%dr6" : : "r" (val));
+}
 
 /* XXXX ought to be in psl.h with spl() functions */
 



Home | Main Index | Thread Index | Old Index