Module Name:    src
Committed By:   maxv
Date:           Fri Aug 18 14:52:19 UTC 2017

Modified Files:
        src/sys/arch/amd64/amd64: amd64_trap.S
        src/sys/arch/i386/i386: i386_trap.S vector.S

Log Message:
Revert my previous change. I hadn't checked carefully enough: the
symbols are used in src/external. There is a number of things that seem
wrong to me here, but I'm not changing them for now.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/amd64/amd64/amd64_trap.S
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/i386/i386/i386_trap.S
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/i386/i386/vector.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/amd64_trap.S
diff -u src/sys/arch/amd64/amd64/amd64_trap.S:1.6 src/sys/arch/amd64/amd64/amd64_trap.S:1.7
--- src/sys/arch/amd64/amd64/amd64_trap.S:1.6	Fri Aug 18 10:02:37 2017
+++ src/sys/arch/amd64/amd64/amd64_trap.S	Fri Aug 18 14:52:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: amd64_trap.S,v 1.6 2017/08/18 10:02:37 maxv Exp $	*/
+/*	$NetBSD: amd64_trap.S,v 1.7 2017/08/18 14:52:19 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
 
 #if 0
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: amd64_trap.S,v 1.6 2017/08/18 10:02:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amd64_trap.S,v 1.7 2017/08/18 14:52:19 maxv Exp $");
 #endif
 
 /*
@@ -154,7 +154,47 @@ nmileave:
 IDTVEC_END(trap02)
 
 IDTVEC(trap03)
+#ifndef KDTRACE_HOOKS
 	ZTRAP(T_BPTFLT)
+#else
+	ZTRAP_NJ(T_BPTFLT)
+	INTRENTRY
+	STI(si)
+	/*
+	 * DTrace Function Boundary Trace (fbt) probes are triggered
+	 * by int3 (0xcc).
+	 */
+	/* Check if there is no DTrace hook registered. */
+	cmpq	$0,dtrace_invop_jump_addr
+	je	calltrap
+
+	/*
+	 * Set our jump address for the jump back in the event that
+	 * the exception wasn't caused by DTrace at all.
+	 */
+	/* XXX: This doesn't look right for SMP - unless it is a
+	 * constant - so why set it everytime. (dsl) */
+	movq	$calltrap, dtrace_invop_calltrap_addr(%rip)
+
+	/* Jump to the code hooked in by DTrace. */
+	movq	dtrace_invop_jump_addr, %rax
+	jmpq	*dtrace_invop_jump_addr
+
+	.bss
+	.globl	dtrace_invop_jump_addr
+	.align	8
+	.type	dtrace_invop_jump_addr, @object
+	.size	dtrace_invop_jump_addr, 8
+dtrace_invop_jump_addr:
+	.zero	8
+	.globl	dtrace_invop_calltrap_addr
+	.align	8
+	.type	dtrace_invop_calltrap_addr, @object
+	.size	dtrace_invop_calltrap_addr, 8
+dtrace_invop_calltrap_addr:
+	.zero	8
+	.text
+#endif
 IDTVEC_END(trap03)
 
 IDTVEC(trap04)

Index: src/sys/arch/i386/i386/i386_trap.S
diff -u src/sys/arch/i386/i386/i386_trap.S:1.10 src/sys/arch/i386/i386/i386_trap.S:1.11
--- src/sys/arch/i386/i386/i386_trap.S:1.10	Fri Aug 18 10:02:37 2017
+++ src/sys/arch/i386/i386/i386_trap.S	Fri Aug 18 14:52:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: i386_trap.S,v 1.10 2017/08/18 10:02:37 maxv Exp $	*/
+/*	$NetBSD: i386_trap.S,v 1.11 2017/08/18 14:52:19 maxv Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -66,7 +66,7 @@
 
 #if 0
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.10 2017/08/18 10:02:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.11 2017/08/18 14:52:19 maxv Exp $");
 #endif
 
 /*
@@ -132,9 +132,48 @@ IDTVEC(trap05)
 	ZTRAP(T_BOUND)
 IDTVEC_END(trap05)
 
+/*
+ * Privileged instruction fault.
+ */
+#ifdef KDTRACE_HOOKS
+	SUPERALIGN_TEXT
+IDTVEC(trap06)
+	/* Check if there is no DTrace hook registered. */
+	cmpl	$0,dtrace_invop_jump_addr
+	je	norm_ill
+
+	/* Check if this is a user fault. */
+	/* XXX this was 0x0020 in FreeBSD */
+	cmpl	$GSEL(GCODE_SEL, SEL_KPL),4(%esp) /* Check code segment. */
+
+	/* If so, just handle it as a normal trap. */
+	jne	norm_ill
+
+	/*
+	 * This is a kernel instruction fault that might have been caused
+	 * by a DTrace provider.
+	 */
+
+	/*
+	 * Set our jump address for the jump back in the event that
+	 * the exception wasn't caused by DTrace at all.
+	 */
+	movl	$norm_ill,dtrace_invop_calltrap_addr
+
+	/* Jump to the code hooked in by DTrace. */
+	jmpl	*dtrace_invop_jump_addr
+
+	/*
+	 * Process the instruction fault in the normal way.
+	 */
+norm_ill:
+	ZTRAP(T_PRIVINFLT)
+IDTVEC_END(trap06)
+#else
 IDTVEC(trap06)
 	ZTRAP(T_PRIVINFLT)
 IDTVEC_END(trap06)
+#endif
 
 IDTVEC(trap07)
 	pushl	$0			/* dummy error code */

Index: src/sys/arch/i386/i386/vector.S
diff -u src/sys/arch/i386/i386/vector.S:1.72 src/sys/arch/i386/i386/vector.S:1.73
--- src/sys/arch/i386/i386/vector.S:1.72	Fri Aug 18 10:02:37 2017
+++ src/sys/arch/i386/i386/vector.S	Fri Aug 18 14:52:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.72 2017/08/18 10:02:37 maxv Exp $	*/
+/*	$NetBSD: vector.S,v 1.73 2017/08/18 14:52:19 maxv Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: vector.S,v 1.72 2017/08/18 10:02:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vector.S,v 1.73 2017/08/18 14:52:19 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -125,6 +125,23 @@ __KERNEL_RCSID(0, "$NetBSD: vector.S,v 1
 	shl	$24,%eax				;\
 	orl	%edx,%eax
 
+#ifdef KDTRACE_HOOKS
+	.bss
+	.globl	dtrace_invop_jump_addr
+	.align	4
+	.type	dtrace_invop_jump_addr, @object
+	.size	dtrace_invop_jump_addr, 4
+dtrace_invop_jump_addr:
+	.zero	4
+	.globl	dtrace_invop_calltrap_addr
+	.align	4
+	.type	dtrace_invop_calltrap_addr, @object
+	.size	dtrace_invop_calltrap_addr, 4
+dtrace_invop_calltrap_addr:
+	.zero	8
+	.text
+#endif
+
 #ifndef XEN
 #if NLAPIC > 0
 #ifdef MULTIPROCESSOR

Reply via email to