Author: rstone
Date: Mon Nov  7 01:53:25 2011
New Revision: 227290
URL: http://svn.freebsd.org/changeset/base/227290

Log:
  Fix the DTrace pid return trap interrupt vector.  Previously we were using
  31, but that vector is reserved.
  
  Without this fix, running dtrace -p <pid> would either cause the target
  process to crash or the kernel to page fault.
  
  Obtained from:        rpaulo
  MFC after:    3days

Modified:
  head/sys/amd64/amd64/trap.c
  head/sys/amd64/include/segments.h
  head/sys/amd64/include/trap.h
  head/sys/i386/i386/trap.c
  head/sys/i386/include/segments.h
  head/sys/i386/include/trap.h

Modified: head/sys/amd64/amd64/trap.c
==============================================================================
--- head/sys/amd64/amd64/trap.c Mon Nov  7 00:27:25 2011        (r227289)
+++ head/sys/amd64/amd64/trap.c Mon Nov  7 01:53:25 2011        (r227290)
@@ -125,7 +125,7 @@ void dblfault_handler(struct trapframe *
 static int trap_pfault(struct trapframe *, int);
 static void trap_fatal(struct trapframe *, vm_offset_t);
 
-#define MAX_TRAP_MSG           30
+#define MAX_TRAP_MSG           33
 static char *trap_msg[] = {
        "",                                     /*  0 unused */
        "privileged instruction fault",         /*  1 T_PRIVINFLT */
@@ -158,6 +158,9 @@ static char *trap_msg[] = {
        "machine check trap",                   /* 28 T_MCHK */
        "SIMD floating-point exception",        /* 29 T_XMMFLT */
        "reserved (unknown) fault",             /* 30 T_RESERVED */
+       "",                                     /* 31 unused (reserved) */
+       "DTrace pid return trap",               /* 32 T_DTRACE_RET */
+       "DTrace fasttrap probe trap",           /* 33 T_DTRACE_PROBE */
 };
 
 #ifdef KDB
@@ -245,28 +248,26 @@ trap(struct trapframe *frame)
         * handled the trap and modified the trap frame so that this
         * function can return normally.
         */
-       if (dtrace_trap_func != NULL)
-               if ((*dtrace_trap_func)(frame, type))
-                       goto out;
        if (type == T_DTRACE_PROBE || type == T_DTRACE_RET ||
            type == T_BPTFLT) {
                struct reg regs;
-               
+
                fill_frame_regs(frame, &regs);
                if (type == T_DTRACE_PROBE &&
                    dtrace_fasttrap_probe_ptr != NULL &&
                    dtrace_fasttrap_probe_ptr(&regs) == 0)
-                               goto out;
-               if (type == T_BPTFLT &&
+                       goto out;
+               else if (type == T_BPTFLT &&
                    dtrace_pid_probe_ptr != NULL &&
                    dtrace_pid_probe_ptr(&regs) == 0)
-                               goto out;
-               if (type == T_DTRACE_RET &&
+                       goto out;
+               else if (type == T_DTRACE_RET &&
                    dtrace_return_probe_ptr != NULL &&
                    dtrace_return_probe_ptr(&regs) == 0)
                        goto out;
-
        }
+       if (dtrace_trap_func != NULL && (*dtrace_trap_func)(frame, type))
+               goto out;
 #endif
 
        if ((frame->tf_rflags & PSL_I) == 0) {

Modified: head/sys/amd64/include/segments.h
==============================================================================
--- head/sys/amd64/include/segments.h   Mon Nov  7 00:27:25 2011        
(r227289)
+++ head/sys/amd64/include/segments.h   Mon Nov  7 01:53:25 2011        
(r227290)
@@ -214,7 +214,7 @@ struct region_descriptor {
 #define        IDT_XF          19      /* #XF: SIMD Floating-Point Exception */
 #define        IDT_IO_INTS     NRSVIDT /* Base of IDT entries for I/O 
interrupts. */
 #define        IDT_SYSCALL     0x80    /* System Call Interrupt Vector */
-#define        IDT_DTRACE_RET  0x92    /* DTrace pid provider Interrupt Vector 
*/
+#define        IDT_DTRACE_RET  0x20    /* DTrace pid provider Interrupt Vector 
*/
 
 /*
  * Entries in the Global Descriptor Table (GDT)

Modified: head/sys/amd64/include/trap.h
==============================================================================
--- head/sys/amd64/include/trap.h       Mon Nov  7 00:27:25 2011        
(r227289)
+++ head/sys/amd64/include/trap.h       Mon Nov  7 01:53:25 2011        
(r227290)
@@ -62,8 +62,8 @@
 #define        T_MCHK          28      /* machine check trap */
 #define        T_XMMFLT        29      /* SIMD floating-point exception */
 #define        T_RESERVED      30      /* reserved (unknown) */
-#define        T_DTRACE_RET    31      /* DTrace pid return */
-#define        T_DTRACE_PROBE  32      /* DTrace fasttrap probe */
+#define        T_DTRACE_RET    32      /* DTrace pid return */
+#define        T_DTRACE_PROBE  33      /* DTrace fasttrap probe */
 
 /* XXX most of the following codes aren't used, but could be. */
 

Modified: head/sys/i386/i386/trap.c
==============================================================================
--- head/sys/i386/i386/trap.c   Mon Nov  7 00:27:25 2011        (r227289)
+++ head/sys/i386/i386/trap.c   Mon Nov  7 01:53:25 2011        (r227290)
@@ -136,7 +136,7 @@ void dblfault_handler(void);
 
 extern inthand_t IDTVEC(lcall_syscall);
 
-#define MAX_TRAP_MSG           30
+#define MAX_TRAP_MSG           33
 static char *trap_msg[] = {
        "",                                     /*  0 unused */
        "privileged instruction fault",         /*  1 T_PRIVINFLT */
@@ -169,6 +169,10 @@ static char *trap_msg[] = {
        "machine check trap",                   /* 28 T_MCHK */
        "SIMD floating-point exception",        /* 29 T_XMMFLT */
        "reserved (unknown) fault",             /* 30 T_RESERVED */
+       "",                                     /* 31 unused (reserved) */
+       "DTrace pid return trap",               /* 32 T_DTRACE_RET */
+       "DTrace fasttrap probe trap",           /* 33 T_DTRACE_PROBE */
+
 };
 
 #if defined(I586_CPU) && !defined(NO_F00F_HACK)
@@ -265,10 +269,6 @@ trap(struct trapframe *frame)
         * handled the trap and modified the trap frame so that this
         * function can return normally.
         */
-       if ((type == T_PROTFLT || type == T_PAGEFLT) &&
-           dtrace_trap_func != NULL)
-               if ((*dtrace_trap_func)(frame, type))
-                       goto out;
        if (type == T_DTRACE_PROBE || type == T_DTRACE_RET ||
            type == T_BPTFLT) {
                struct reg regs;
@@ -287,6 +287,9 @@ trap(struct trapframe *frame)
                    dtrace_return_probe_ptr(&regs) == 0)
                        goto out;
        }
+       if ((type == T_PROTFLT || type == T_PAGEFLT) &&
+           dtrace_trap_func != NULL && (*dtrace_trap_func)(frame, type))
+               goto out;
 #endif
 
        if ((frame->tf_eflags & PSL_I) == 0) {

Modified: head/sys/i386/include/segments.h
==============================================================================
--- head/sys/i386/include/segments.h    Mon Nov  7 00:27:25 2011        
(r227289)
+++ head/sys/i386/include/segments.h    Mon Nov  7 01:53:25 2011        
(r227290)
@@ -207,7 +207,7 @@ struct region_descriptor {
 #define        IDT_XF          19      /* #XF: SIMD Floating-Point Exception */
 #define        IDT_IO_INTS     NRSVIDT /* Base of IDT entries for I/O 
interrupts. */
 #define        IDT_SYSCALL     0x80    /* System Call Interrupt Vector */
-#define        IDT_DTRACE_RET  0x92    /* DTrace pid provider Interrupt Vector 
*/
+#define        IDT_DTRACE_RET  0x20    /* DTrace pid provider Interrupt Vector 
*/
 
 /*
  * Entries in the Global Descriptor Table (GDT)

Modified: head/sys/i386/include/trap.h
==============================================================================
--- head/sys/i386/include/trap.h        Mon Nov  7 00:27:25 2011        
(r227289)
+++ head/sys/i386/include/trap.h        Mon Nov  7 01:53:25 2011        
(r227290)
@@ -62,8 +62,8 @@
 #define        T_MCHK          28      /* machine check trap */
 #define        T_XMMFLT        29      /* SIMD floating-point exception */
 #define        T_RESERVED      30      /* reserved (unknown) */
-#define        T_DTRACE_RET    31      /* DTrace pid return */
-#define        T_DTRACE_PROBE  32      /* DTrace fasttrap probe */
+#define        T_DTRACE_RET    32      /* DTrace pid return */
+#define        T_DTRACE_PROBE  33      /* DTrace fasttrap probe */
 
 /* XXX most of the following codes aren't used, but could be. */
 
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to