From owner-p4-projects@FreeBSD.ORG Mon Jan 7 07:22:28 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id A75E316A419; Mon, 7 Jan 2008 07:22:27 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6CDC916A417 for ; Mon, 7 Jan 2008 07:22:27 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 6544813C45A for ; Mon, 7 Jan 2008 07:22:27 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m077MRpK021844 for ; Mon, 7 Jan 2008 07:22:27 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m077MRtB021840 for perforce@freebsd.org; Mon, 7 Jan 2008 07:22:27 GMT (envelope-from jb@freebsd.org) Date: Mon, 7 Jan 2008 07:22:27 GMT Message-Id: <200801070722.m077MRtB021840@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jb@freebsd.org using -f From: John Birrell To: Perforce Change Reviews Cc: Subject: PERFORCE change 132678 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Jan 2008 07:22:28 -0000 http://perforce.freebsd.org/chv.cgi?CH=132678 Change 132678 by jb@jb_freebsd1 on 2008/01/07 07:21:49 Add the hook to allow the dtrace module to process breakpoint interrupts if it is loaded. The Function Boundary Trace (fbt) and Statically Defined Trace (sdt) providers trigger probes on amd64 by replacing the "pushl %ebp" and 'ret' opcodes with int3 (#BP, 0xcc) and then checking the trap address against the list of installed probes. If the address has a probe associated with it, the dtrace module calls it's probes and the function that was broken by the breakpoint, then repairs the trap frame and returns via 'doreti'. In the case that the trap address isn't from a DTrace probe, the return path takes execution back to the calltrap code and the trap is handled in the usual way. No doubt there is a simpler way to do this pointer ping pong. Affected files ... .. //depot/projects/dtrace/src/sys/amd64/amd64/exception.S#7 edit Differences ... ==== //depot/projects/dtrace/src/sys/amd64/amd64/exception.S#7 (text+ko) ==== @@ -37,6 +37,7 @@ #include "opt_atpic.h" #include "opt_compat.h" #include "opt_hwpmc_hooks.h" +#include "opt_kdtrace.h" #include #include @@ -44,6 +45,27 @@ #include "assym.s" +#ifdef KDTRACE_HOOKS + .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 + .globl dtrace_invop_return_addr + .align 8 + .type dtrace_invop_return_addr, @object + .size dtrace_invop_return_addr, 8 +dtrace_invop_return_addr: + .zero 8 +#endif .text #ifdef HWPMC_HOOKS ENTRY(start_exceptions) @@ -170,6 +192,28 @@ movq %r14,TF_R14(%rsp) movq %r15,TF_R15(%rsp) FAKE_MCOUNT(TF_RIP(%rsp)) +#ifdef KDTRACE_HOOKS + /* + * DTrace Function Boundary Trace (fbt) and Statically Defined + * Trace (sdt) probes are triggered by int3 (0xcc) which causes + * the #BP (T_BPTFLT) breakpoint interrupt. For all other trap + * types, just handle them in the usual way. + */ + cmpq $T_BPTFLT,TF_TRAPNO(%rsp) + jne calltrap + + /* Check if there is no DTrace hook registered. */ + cmpq $0,dtrace_invop_jump_addr + je calltrap + + /* Set our alternate jump addresses for the jump back. */ + movq $calltrap, dtrace_invop_calltrap_addr(%rip) + movq $doreti, dtrace_invop_return_addr(%rip) + + /* Jump to the code hooked in by DTrace. */ + movq dtrace_invop_jump_addr, %rax + jmpq *dtrace_invop_jump_addr +#endif .globl calltrap .type calltrap,@function calltrap: