Module Name:    src
Committed By:   chs
Date:           Sat May 14 21:19:06 UTC 2016

Modified Files:
        src/external/cddl/osnet/dev/dtrace/amd64: dtrace_isa.c
        src/external/cddl/osnet/dev/dtrace/i386: dtrace_asm.S dtrace_isa.c
        src/external/cddl/osnet/dist/uts/common/dtrace: dtrace.c

Log Message:
apply the ustack() parts of freebsd r211608:

        r211608 | rpaulo | 2010-08-22 03:53:32 -0700 (Sun, 22 Aug 2010) | 8 
lines

        Kernel DTrace support for:
        o uregs  (sson@)
        o ustack (sson@)
        o /dev/dtrace/helper device (needed for USDT probes)

        The work done by me was:
        Sponsored by:   The FreeBSD Foundation

plus a few netbsd-specific tweaks from me.
fixes PR 50790.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 \
    src/external/cddl/osnet/dev/dtrace/amd64/dtrace_isa.c
cvs rdiff -u -r1.3 -r1.4 src/external/cddl/osnet/dev/dtrace/i386/dtrace_asm.S \
    src/external/cddl/osnet/dev/dtrace/i386/dtrace_isa.c
cvs rdiff -u -r1.30 -r1.31 \
    src/external/cddl/osnet/dist/uts/common/dtrace/dtrace.c

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

Modified files:

Index: src/external/cddl/osnet/dev/dtrace/amd64/dtrace_isa.c
diff -u src/external/cddl/osnet/dev/dtrace/amd64/dtrace_isa.c:1.4 src/external/cddl/osnet/dev/dtrace/amd64/dtrace_isa.c:1.5
--- src/external/cddl/osnet/dev/dtrace/amd64/dtrace_isa.c:1.4	Mon Jun 11 15:18:05 2012
+++ src/external/cddl/osnet/dev/dtrace/amd64/dtrace_isa.c	Sat May 14 21:19:05 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: dtrace_isa.c,v 1.4 2012/06/11 15:18:05 chs Exp $	*/
+/*	$NetBSD: dtrace_isa.c,v 1.5 2016/05/14 21:19:05 chs Exp $	*/
 
 /*
  * CDDL HEADER START
@@ -32,20 +32,11 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
-//#include <sys/stack.h>
-//#include <sys/pcpu.h>
 
 #include <machine/frame.h>
-//#include <machine/md_var.h>
 #include <machine/reg.h>
-//#include <machine/stack.h>
 
-//#include <vm/vm.h>
-//#include <vm/vm_param.h>
-//#include <vm/pmap.h>
 #include <machine/vmparam.h>
-#include <machine/pmap.h>
-
 
 uint8_t dtrace_fuword8_nocheck(void *);
 uint16_t dtrace_fuword16_nocheck(void *);
@@ -113,19 +104,17 @@ dtrace_getpcstack(pc_t *pcstack, int pcs
 	}
 }
 
-#ifdef notyet
 static int
 dtrace_getustack_common(uint64_t *pcstack, int pcstack_limit, uintptr_t pc,
     uintptr_t sp)
 {
 	volatile uint16_t *flags =
 	    (volatile uint16_t *)&cpu_core[cpu_number()].cpuc_dtrace_flags;
-	struct amd64_frame *frame;
 	int ret = 0;
 
 	ASSERT(pcstack == NULL || pcstack_limit > 0);
 
-	while (pc != 0 && sp != 0) {
+	while (pc != 0) {
 		ret++;
 		if (pcstack != NULL) {
 			*pcstack++ = (uint64_t)pc;
@@ -134,10 +123,12 @@ dtrace_getustack_common(uint64_t *pcstac
 				break;
 		}
 
-		frame = (struct amd64_frame *) sp;
+		if (sp == 0)
+			break;
 
-		pc = dtrace_fulword(&frame->f_retaddr);
-		sp = dtrace_fulword(&frame->f_frame);
+		pc = dtrace_fuword64((void *)(sp +
+			offsetof(struct amd64_frame, f_retaddr)));
+		sp = dtrace_fuword64((void *)sp);
 
 		/*
 		 * This is totally bogus:  if we faulted, we're going to clear
@@ -156,10 +147,9 @@ dtrace_getustack_common(uint64_t *pcstac
 void
 dtrace_getupcstack(uint64_t *pcstack, int pcstack_limit)
 {
-	klwp_t *lwp = ttolwp(curthread);
 	proc_t *p = curproc;
-	struct regs *rp;
-	uintptr_t pc, sp;
+	struct trapframe *tf;
+	uintptr_t pc, sp, fp;
 	volatile uint16_t *flags =
 	    (volatile uint16_t *)&cpu_core[cpu_number()].cpuc_dtrace_flags;
 	int n;
@@ -173,7 +163,7 @@ dtrace_getupcstack(uint64_t *pcstack, in
 	/*
 	 * If there's no user context we still need to zero the stack.
 	 */
-	if (lwp == NULL || p == NULL || (rp = lwp->lwp_regs) == NULL)
+	if (p == NULL || (tf = curlwp->l_md.md_regs) == NULL)
 		goto zero;
 
 	*pcstack++ = (uint64_t)p->p_pid;
@@ -182,19 +172,29 @@ dtrace_getupcstack(uint64_t *pcstack, in
 	if (pcstack_limit <= 0)
 		return;
 
-	pc = rp->r_rip;
-	sp = rp->r_rsp;
+	pc = tf->tf_rip;
+	fp = tf->tf_rbp;
+	sp = tf->tf_rsp;
 
 	if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_ENTRY)) {
+		/* 
+		 * In an entry probe.  The frame pointer has not yet been
+		 * pushed (that happens in the function prologue).  The
+		 * best approach is to add the current pc as a missing top
+		 * of stack and back the pc up to the caller, which is stored
+		 * at the current stack pointer address since the call 
+		 * instruction puts it there right before the branch.
+		 */
+
 		*pcstack++ = (uint64_t)pc;
 		pcstack_limit--;
 		if (pcstack_limit <= 0)
 			return;
 
-		pc = dtrace_fulword((void *) sp);
+		pc = dtrace_fuword64((void *) sp);
 	}
 
-	n = dtrace_getustack_common(pcstack, pcstack_limit, pc, sp);
+	n = dtrace_getustack_common(pcstack, pcstack_limit, pc, fp);
 	ASSERT(n >= 0);
 	ASSERT(n <= pcstack_limit);
 
@@ -209,18 +209,52 @@ zero:
 int
 dtrace_getustackdepth(void)
 {
+	proc_t *p = curproc;
+	struct trapframe *tf;
+	uintptr_t pc, fp, sp;
+	int n = 0;
+
+	if (p == NULL || (tf = curlwp->l_md.md_regs) == NULL)
+		return (0);
+
+	if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_FAULT))
+		return (-1);
+
+	pc = tf->tf_rip;
+	fp = tf->tf_rbp;
+	sp = tf->tf_rsp;
+
+	if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_ENTRY)) {
+		/* 
+		 * In an entry probe.  The frame pointer has not yet been
+		 * pushed (that happens in the function prologue).  The
+		 * best approach is to add the current pc as a missing top
+		 * of stack and back the pc up to the caller, which is stored
+		 * at the current stack pointer address since the call 
+		 * instruction puts it there right before the branch.
+		 */
+
+		pc = dtrace_fuword64((void *) sp);
+		n++;
+	}
+
+	n += dtrace_getustack_common(NULL, 0, pc, fp);
+
+	return (n);
 }
 
 void
 dtrace_getufpstack(uint64_t *pcstack, uint64_t *fpstack, int pcstack_limit)
 {
-	klwp_t *lwp = ttolwp(curthread);
 	proc_t *p = curproc;
-	struct regs *rp;
-	uintptr_t pc, sp, oldcontext;
+	struct trapframe *tf;
+	uintptr_t pc, sp, fp;
 	volatile uint16_t *flags =
 	    (volatile uint16_t *)&cpu_core[cpu_number()].cpuc_dtrace_flags;
+#ifdef notyet	/* XXX signal stack */
+	uintptr_t oldcontext;
 	size_t s1, s2;
+#endif
 
 	if (*flags & CPU_DTRACE_FAULT)
 		return;
@@ -231,7 +265,7 @@ dtrace_getufpstack(uint64_t *pcstack, ui
 	/*
 	 * If there's no user context we still need to zero the stack.
 	 */
-	if (lwp == NULL || p == NULL || (rp = lwp->lwp_regs) == NULL)
+	if (p == NULL || (tf = curlwp->l_md.md_regs) == NULL)
 		goto zero;
 
 	*pcstack++ = (uint64_t)p->p_pid;
@@ -240,12 +274,15 @@ dtrace_getufpstack(uint64_t *pcstack, ui
 	if (pcstack_limit <= 0)
 		return;
 
-	pc = rp->r_pc;
-	sp = rp->r_fp;
-	oldcontext = lwp->lwp_oldcontext;
+	pc = tf->tf_rip;
+	sp = tf->tf_rsp;
+	fp = tf->tf_rbp;
 
+#ifdef notyet /* XXX signal stack */
+	oldcontext = lwp->lwp_oldcontext;
 	s1 = sizeof (struct xframe) + 2 * sizeof (long);
 	s2 = s1 + sizeof (siginfo_t);
+#endif
 
 	if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_ENTRY)) {
 		*pcstack++ = (uint64_t)pc;
@@ -254,19 +291,20 @@ dtrace_getufpstack(uint64_t *pcstack, ui
 		if (pcstack_limit <= 0)
 			return;
 
-		if (p->p_model == DATAMODEL_NATIVE)
-			pc = dtrace_fulword((void *)rp->r_sp);
-		else
-			pc = dtrace_fuword32((void *)rp->r_sp);
+		pc = dtrace_fuword64((void *)sp);
 	}
 
-	while (pc != 0 && sp != 0) {
+	while (pc != 0) {
 		*pcstack++ = (uint64_t)pc;
-		*fpstack++ = sp;
+		*fpstack++ = fp;
 		pcstack_limit--;
 		if (pcstack_limit <= 0)
 			break;
 
+		if (fp == 0)
+			break;
+
+#ifdef notyet /* XXX signal stack */
 		if (oldcontext == sp + s1 || oldcontext == sp + s2) {
 			ucontext_t *ucp = (ucontext_t *)oldcontext;
 			greg_t *gregs = ucp->uc_mcontext.gregs;
@@ -275,11 +313,12 @@ dtrace_getufpstack(uint64_t *pcstack, ui
 			pc = dtrace_fulword(&gregs[REG_PC]);
 
 			oldcontext = dtrace_fulword(&ucp->uc_link);
-		} else {
-			struct xframe *fr = (struct xframe *)sp;
-
-			pc = dtrace_fulword(&fr->fr_savpc);
-			sp = dtrace_fulword(&fr->fr_savfp);
+		} else
+#endif /* XXX */
+		{
+			pc = dtrace_fuword64((void *)(fp +
+				offsetof(struct amd64_frame, f_retaddr)));
+			fp = dtrace_fuword64((void *)fp);
 		}
 
 		/*
@@ -295,9 +334,8 @@ dtrace_getufpstack(uint64_t *pcstack, ui
 
 zero:
 	while (pcstack_limit-- > 0)
-		*pcstack++ = NULL;
+		*pcstack++ = 0;
 }
-#endif
 
 /*ARGSUSED*/
 uint64_t
@@ -328,7 +366,7 @@ dtrace_getarg(int arg, int aframes)
 			 * we'll pull the true stack pointer out of the saved
 			 * registers and decrement our argument by the number
 			 * of arguments passed in registers; if the argument
-			 * we're seeking is passed in regsiters, we can just
+			 * we're seeking is passed in registers, we can just
 			 * load it directly.
 			 */
 			struct reg *rp = (struct reg *)((uintptr_t)&fp[1] +

Index: src/external/cddl/osnet/dev/dtrace/i386/dtrace_asm.S
diff -u src/external/cddl/osnet/dev/dtrace/i386/dtrace_asm.S:1.3 src/external/cddl/osnet/dev/dtrace/i386/dtrace_asm.S:1.4
--- src/external/cddl/osnet/dev/dtrace/i386/dtrace_asm.S:1.3	Sat Mar 13 22:31:15 2010
+++ src/external/cddl/osnet/dev/dtrace/i386/dtrace_asm.S	Sat May 14 21:19:05 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: dtrace_asm.S,v 1.3 2010/03/13 22:31:15 christos Exp $	*/
+/*	$NetBSD: dtrace_asm.S,v 1.4 2016/05/14 21:19:05 chs Exp $	*/
 
 /*
  * CDDL HEADER START
@@ -48,14 +48,8 @@
 	 * dtrace_invop wants us to do.
 	 */
 	call	dtrace_invop
-
-	/*
-	 * We pushed 3 times for the arguments to dtrace_invop,
-	 * so we need to increment the stack pointer to get rid of
-	 * those values.
-	 */
+	ALTENTRY(dtrace_invop_callsite)
 	addl	$12, %esp
-//	ALTENTRY(dtrace_invop_callsite)
 	cmpl	$DTRACE_INVOP_PUSHL_EBP, %eax
 	je	invop_push
 	cmpl	$DTRACE_INVOP_POPL_EBP, %eax
Index: src/external/cddl/osnet/dev/dtrace/i386/dtrace_isa.c
diff -u src/external/cddl/osnet/dev/dtrace/i386/dtrace_isa.c:1.3 src/external/cddl/osnet/dev/dtrace/i386/dtrace_isa.c:1.4
--- src/external/cddl/osnet/dev/dtrace/i386/dtrace_isa.c:1.3	Thu Mar 18 10:57:58 2010
+++ src/external/cddl/osnet/dev/dtrace/i386/dtrace_isa.c	Sat May 14 21:19:05 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: dtrace_isa.c,v 1.3 2010/03/18 10:57:58 tron Exp $	*/
+/*	$NetBSD: dtrace_isa.c,v 1.4 2016/05/14 21:19:05 chs Exp $	*/
 
 /*
  * CDDL HEADER START
@@ -32,18 +32,14 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
-//#include <sys/pcpu.h>
 
-//#include <machine/md_var.h>
-//#include <machine/stack.h>
-
-//#include <vm/vm.h>
 #include <machine/vmparam.h>
 #include <machine/pmap.h>
 
 uintptr_t kernelbase = (uintptr_t)KERNBASE;
 
-#define INKERNEL(va) (((vm_offset_t)(va)) >= USRSTACK && \
+#define INKERNEL(va) \
+	(((vm_offset_t)(va)) >= VM_MIN_KERNEL_ADDRESS && \
 	 ((vm_offset_t)(va)) < VM_MAX_KERNEL_ADDRESS)
 
 struct i386_frame {
@@ -67,11 +63,7 @@ dtrace_getpcstack(pc_t *pcstack, int pcs
 	register_t ebp;
 	struct i386_frame *frame;
 	vm_offset_t callpc;
-#if 0	/* XXX TBD needs solaris_cpu (for fbt) */
 	pc_t caller = (pc_t) solaris_cpu[cpu_number()].cpu_dtrace_caller;
-#else
-	pc_t caller = (pc_t) 0;
-#endif
 
 	if (intrpc != 0)
 		pcstack[depth++] = (pc_t) intrpc;
@@ -112,21 +104,22 @@ dtrace_getpcstack(pc_t *pcstack, int pcs
 	}
 }
 
-#ifdef notyet
 static int
 dtrace_getustack_common(uint64_t *pcstack, int pcstack_limit, uintptr_t pc,
     uintptr_t sp)
 {
-	klwp_t *lwp = ttolwp(curthread);
+#ifdef notyet
 	proc_t *p = curproc;
-	uintptr_t oldcontext = lwp->lwp_oldcontext;
+	uintptr_t oldcontext = lwp->lwp_oldcontext; /* XXX signal stack. */
+	size_t s1, s2;
+#endif
 	volatile uint16_t *flags =
 	    (volatile uint16_t *)&cpu_core[cpu_number()].cpuc_dtrace_flags;
-	size_t s1, s2;
 	int ret = 0;
 
 	ASSERT(pcstack == NULL || pcstack_limit > 0);
 
+#ifdef notyet /* XXX signal stack. */
 	if (p->p_model == DATAMODEL_NATIVE) {
 		s1 = sizeof (struct frame) + 2 * sizeof (long);
 		s2 = s1 + sizeof (siginfo_t);
@@ -134,8 +127,9 @@ dtrace_getustack_common(uint64_t *pcstac
 		s1 = sizeof (struct frame32) + 3 * sizeof (int);
 		s2 = s1 + sizeof (siginfo32_t);
 	}
+#endif
 
-	while (pc != 0 && sp != 0) {
+	while (pc != 0) {
 		ret++;
 		if (pcstack != NULL) {
 			*pcstack++ = (uint64_t)pc;
@@ -144,6 +138,10 @@ dtrace_getustack_common(uint64_t *pcstac
 				break;
 		}
 
+		if (sp == 0)
+			break;
+
+#ifdef notyet /* XXX signal stack. */ 
 		if (oldcontext == sp + s1 || oldcontext == sp + s2) {
 			if (p->p_model == DATAMODEL_NATIVE) {
 				ucontext_t *ucp = (ucontext_t *)oldcontext;
@@ -175,6 +173,11 @@ dtrace_getustack_common(uint64_t *pcstac
 				sp = dtrace_fuword32(&fr->fr_savfp);
 			}
 		}
+#else
+		pc = dtrace_fuword32((void *)(sp +
+			offsetof(struct i386_frame, f_retaddr)));
+		sp = dtrace_fuword32((void *)sp);
+#endif /* ! notyet */
 
 		/*
 		 * This is totally bogus:  if we faulted, we're going to clear
@@ -193,10 +196,9 @@ dtrace_getustack_common(uint64_t *pcstac
 void
 dtrace_getupcstack(uint64_t *pcstack, int pcstack_limit)
 {
-	klwp_t *lwp = ttolwp(curthread);
 	proc_t *p = curproc;
-	struct regs *rp;
-	uintptr_t pc, sp;
+	struct trapframe *tf;
+	uintptr_t pc, sp, fp;
 	volatile uint16_t *flags =
 	    (volatile uint16_t *)&cpu_core[cpu_number()].cpuc_dtrace_flags;
 	int n;
@@ -210,7 +212,7 @@ dtrace_getupcstack(uint64_t *pcstack, in
 	/*
 	 * If there's no user context we still need to zero the stack.
 	 */
-	if (lwp == NULL || p == NULL || (rp = lwp->lwp_regs) == NULL)
+	if (p == NULL || (tf = curlwp->l_md.md_regs) == NULL)
 		goto zero;
 
 	*pcstack++ = (uint64_t)p->p_pid;
@@ -219,22 +221,29 @@ dtrace_getupcstack(uint64_t *pcstack, in
 	if (pcstack_limit <= 0)
 		return;
 
-	pc = rp->r_pc;
-	sp = rp->r_fp;
+	pc = tf->tf_eip;
+	fp = tf->tf_ebp;
+	sp = tf->tf_esp;
 
 	if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_ENTRY)) {
+		/*
+		 * In an entry probe.  The frame pointer has not yet been
+		 * pushed (that happens in the function prologue).  The
+		 * best approach is to add the current pc as a missing top
+		 * of stack and back the pc up to the caller, which is stored
+		 * at the current stack pointer address since the call 
+		 * instruction puts it there right before the branch.
+		 */
+
 		*pcstack++ = (uint64_t)pc;
 		pcstack_limit--;
 		if (pcstack_limit <= 0)
 			return;
 
-		if (p->p_model == DATAMODEL_NATIVE)
-			pc = dtrace_fulword((void *)rp->r_sp);
-		else
-			pc = dtrace_fuword32((void *)rp->r_sp);
+		pc = dtrace_fuword32((void *) sp);
 	}
 
-	n = dtrace_getustack_common(pcstack, pcstack_limit, pc, sp);
+	n = dtrace_getustack_common(pcstack, pcstack_limit, pc, fp);
 	ASSERT(n >= 0);
 	ASSERT(n <= pcstack_limit);
 
@@ -243,24 +252,58 @@ dtrace_getupcstack(uint64_t *pcstack, in
 
 zero:
 	while (pcstack_limit-- > 0)
-		*pcstack++ = NULL;
+		*pcstack++ = 0;
 }
 
 int
 dtrace_getustackdepth(void)
 {
+	proc_t *p = curproc;
+	struct trapframe *tf;
+	uintptr_t pc, fp, sp;
+	int n = 0;
+
+	if (p == NULL || (tf = curlwp->l_md.md_regs) == NULL)
+		return (0);
+
+	if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_FAULT))
+		return (-1);
+
+	pc = tf->tf_eip;
+	fp = tf->tf_ebp;
+	sp = tf->tf_esp;
+
+	if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_ENTRY)) {
+		/*
+		 * In an entry probe.  The frame pointer has not yet been
+		 * pushed (that happens in the function prologue).  The
+		 * best approach is to add the current pc as a missing top
+		 * of stack and back the pc up to the caller, which is stored
+		 * at the current stack pointer address since the call 
+		 * instruction puts it there right before the branch.
+		 */
+
+		pc = dtrace_fuword32((void *) sp);
+		n++;
+	}
+
+	n += dtrace_getustack_common(NULL, 0, pc, fp);
+
+	return (n);
 }
 
 void
 dtrace_getufpstack(uint64_t *pcstack, uint64_t *fpstack, int pcstack_limit)
 {
-	klwp_t *lwp = ttolwp(curthread);
 	proc_t *p = curproc;
-	struct regs *rp;
-	uintptr_t pc, sp, oldcontext;
+	struct trapframe *tf;
+	uintptr_t pc, sp, fp;
 	volatile uint16_t *flags =
 	    (volatile uint16_t *)&cpu_core[cpu_number()].cpuc_dtrace_flags;
+#ifdef notyet /* XXX signal stack */
+	uintptr_t oldcontext;
 	size_t s1, s2;
+#endif
 
 	if (*flags & CPU_DTRACE_FAULT)
 		return;
@@ -271,7 +314,7 @@ dtrace_getufpstack(uint64_t *pcstack, ui
 	/*
 	 * If there's no user context we still need to zero the stack.
 	 */
-	if (lwp == NULL || p == NULL || (rp = lwp->lwp_regs) == NULL)
+	if (p == NULL || (tf = curlwp->l_md.md_regs) == NULL)
 		goto zero;
 
 	*pcstack++ = (uint64_t)p->p_pid;
@@ -280,8 +323,11 @@ dtrace_getufpstack(uint64_t *pcstack, ui
 	if (pcstack_limit <= 0)
 		return;
 
-	pc = rp->r_pc;
-	sp = rp->r_fp;
+	pc = tf->tf_eip;
+	fp = tf->tf_ebp;
+	sp = tf->tf_esp;
+
+#ifdef notyet /* XXX signal stack */
 	oldcontext = lwp->lwp_oldcontext;
 
 	if (p->p_model == DATAMODEL_NATIVE) {
@@ -291,6 +337,7 @@ dtrace_getufpstack(uint64_t *pcstack, ui
 		s1 = sizeof (struct frame32) + 3 * sizeof (int);
 		s2 = s1 + sizeof (siginfo32_t);
 	}
+#endif
 
 	if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_ENTRY)) {
 		*pcstack++ = (uint64_t)pc;
@@ -299,19 +346,20 @@ dtrace_getufpstack(uint64_t *pcstack, ui
 		if (pcstack_limit <= 0)
 			return;
 
-		if (p->p_model == DATAMODEL_NATIVE)
-			pc = dtrace_fulword((void *)rp->r_sp);
-		else
-			pc = dtrace_fuword32((void *)rp->r_sp);
+		pc = dtrace_fuword32((void *)sp);
 	}
 
-	while (pc != 0 && sp != 0) {
+	while (pc != 0) {
 		*pcstack++ = (uint64_t)pc;
-		*fpstack++ = sp;
+		*fpstack++ = fp;
 		pcstack_limit--;
 		if (pcstack_limit <= 0)
 			break;
 
+		if (fp == 0)
+			break;
+
+#ifdef notyet /* XXX signal stack */
 		if (oldcontext == sp + s1 || oldcontext == sp + s2) {
 			if (p->p_model == DATAMODEL_NATIVE) {
 				ucontext_t *ucp = (ucontext_t *)oldcontext;
@@ -330,18 +378,12 @@ dtrace_getufpstack(uint64_t *pcstack, ui
 
 				oldcontext = dtrace_fuword32(&ucp->uc_link);
 			}
-		} else {
-			if (p->p_model == DATAMODEL_NATIVE) {
-				struct frame *fr = (struct frame *)sp;
-
-				pc = dtrace_fulword(&fr->fr_savpc);
-				sp = dtrace_fulword(&fr->fr_savfp);
-			} else {
-				struct frame32 *fr = (struct frame32 *)sp;
-
-				pc = dtrace_fuword32(&fr->fr_savpc);
-				sp = dtrace_fuword32(&fr->fr_savfp);
-			}
+		} else
+#endif /* XXX */
+		{
+			pc = dtrace_fuword32((void *)(fp +
+				offsetof(struct i386_frame, f_retaddr)));
+			fp = dtrace_fuword32((void *)fp);
 		}
 
 		/*
@@ -357,9 +399,8 @@ dtrace_getufpstack(uint64_t *pcstack, ui
 
 zero:
 	while (pcstack_limit-- > 0)
-		*pcstack++ = NULL;
+		*pcstack++ = 0;
 }
-#endif
 
 uint64_t
 dtrace_getarg(int arg, int aframes)
@@ -367,9 +408,8 @@ dtrace_getarg(int arg, int aframes)
 	uintptr_t val;
 	struct i386_frame *fp = (struct i386_frame *)dtrace_getfp();
 	uintptr_t *stack;
-
-#if 0 /* XXX TBD needs ALTENTRY in dtrace_asm.S */
 	int i;
+
 	for (i = 1; i <= aframes; i++) {
 		fp = fp->f_frame;
 
@@ -386,7 +426,6 @@ dtrace_getarg(int arg, int aframes)
 			goto load;
 		}
 	}
-#endif
 
 	/*
 	 * We know that we did not come through a trap to get into
@@ -398,11 +437,9 @@ dtrace_getarg(int arg, int aframes)
 	 */
 	arg++;
 
-	stack = (uintptr_t *)&fp[1];
+	stack = (uintptr_t *)fp + 2;
 
-#if 0
 load:
-#endif
 	DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
 	val = stack[arg];
 	DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);

Index: src/external/cddl/osnet/dist/uts/common/dtrace/dtrace.c
diff -u src/external/cddl/osnet/dist/uts/common/dtrace/dtrace.c:1.30 src/external/cddl/osnet/dist/uts/common/dtrace/dtrace.c:1.31
--- src/external/cddl/osnet/dist/uts/common/dtrace/dtrace.c:1.30	Sat Mar  7 15:14:29 2015
+++ src/external/cddl/osnet/dist/uts/common/dtrace/dtrace.c	Sat May 14 21:19:05 2016
@@ -585,9 +585,9 @@ static void dtrace_enabling_provide(dtra
 static int dtrace_enabling_match(dtrace_enabling_t *, int *);
 static void dtrace_enabling_matchall(void);
 static dtrace_state_t *dtrace_anon_grab(void);
-#if defined(sun)
 static uint64_t dtrace_helper(int, dtrace_mstate_t *,
     dtrace_state_t *, uint64_t, uint64_t);
+#if defined(sun)
 static dtrace_helpers_t *dtrace_helpers_create(proc_t *);
 #endif
 static void dtrace_buffer_drop(dtrace_buffer_t *);
@@ -2894,7 +2894,6 @@ dtrace_dif_variable(dtrace_mstate_t *mst
 		}
 		return (mstate->dtms_stackdepth);
 
-#if defined(sun)
 	case DIF_VAR_USTACKDEPTH:
 		if (!dtrace_priv_proc(state))
 			return (0);
@@ -2914,7 +2913,6 @@ dtrace_dif_variable(dtrace_mstate_t *mst
 			mstate->dtms_present |= DTRACE_MSTATE_USTACKDEPTH;
 		}
 		return (mstate->dtms_ustackdepth);
-#endif
 
 	case DIF_VAR_CALLER:
 		if (!dtrace_priv_kernel(state))
@@ -2951,7 +2949,6 @@ dtrace_dif_variable(dtrace_mstate_t *mst
 		}
 		return (mstate->dtms_caller);
 
-#if defined(sun)
 	case DIF_VAR_UCALLER:
 		if (!dtrace_priv_proc(state))
 			return (0);
@@ -2975,7 +2972,6 @@ dtrace_dif_variable(dtrace_mstate_t *mst
 		}
 
 		return (mstate->dtms_ucaller);
-#endif
 
 	case DIF_VAR_PROBEPROV:
 		ASSERT(mstate->dtms_present & DTRACE_MSTATE_PROBE);
@@ -5820,7 +5816,6 @@ dtrace_action_chill(dtrace_mstate_t *mst
 #endif
 }
 
-#if defined(sun)
 static void
 dtrace_action_ustack(dtrace_mstate_t *mstate, dtrace_state_t *state,
     uint64_t *buf, uint64_t arg)
@@ -5933,7 +5928,6 @@ dtrace_action_ustack(dtrace_mstate_t *ms
 out:
 	mstate->dtms_scratch_ptr = old;
 }
-#endif
 
 /*
  * If you're looking for the epicenter of DTrace, you just found it.  This
@@ -6256,7 +6250,6 @@ dtrace_probe(dtrace_id_t id, uintptr_t a
 				    (uint32_t *)arg0);
 				continue;
 
-#if defined(sun)
 			case DTRACEACT_JSTACK:
 			case DTRACEACT_USTACK:
 				if (!dtrace_priv_proc(state))
@@ -6298,7 +6291,6 @@ dtrace_probe(dtrace_id_t id, uintptr_t a
 				    DTRACE_USTACK_NFRAMES(rec->dtrd_arg) + 1);
 				DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
 				continue;
-#endif
 
 			default:
 				break;
@@ -13889,7 +13881,6 @@ dtrace_anon_property(void)
 	}
 }
 
-#if defined(sun)
 /*
  * DTrace Helper Functions
  */
@@ -13953,9 +13944,7 @@ dtrace_helper_trace(dtrace_helper_action
 		    ((uint64_t *)(uintptr_t)svar->dtsv_data)[curcpu_id];
 	}
 }
-#endif
 
-#if defined(sun)
 static uint64_t
 dtrace_helper(int which, dtrace_mstate_t *mstate,
     dtrace_state_t *state, uint64_t arg0, uint64_t arg1)
@@ -13963,7 +13952,7 @@ dtrace_helper(int which, dtrace_mstate_t
 	uint16_t *flags = &cpu_core[curcpu_id].cpuc_dtrace_flags;
 	uint64_t sarg0 = mstate->dtms_arg[0];
 	uint64_t sarg1 = mstate->dtms_arg[1];
-	uint64_t rval;
+	uint64_t rval = 0;
 	dtrace_helpers_t *helpers = curproc->p_dtrace_helpers;
 	dtrace_helper_action_t *helper;
 	dtrace_vstate_t *vstate;
@@ -14047,6 +14036,7 @@ err:
 	return (0);
 }
 
+#if defined(sun)
 static void
 dtrace_helper_action_destroy(dtrace_helper_action_t *helper,
     dtrace_vstate_t *vstate)
@@ -14154,9 +14144,7 @@ dtrace_helper_destroygen(int gen)
 
 	return (0);
 }
-#endif
 
-#if defined(sun)
 static int
 dtrace_helper_validate(dtrace_helper_action_t *helper)
 {
@@ -14171,9 +14159,7 @@ dtrace_helper_validate(dtrace_helper_act
 
 	return (err == 0);
 }
-#endif
 
-#if defined(sun)
 static int
 dtrace_helper_action_add(int which, dtrace_ecbdesc_t *ep)
 {
@@ -14854,7 +14840,7 @@ dtrace_helpers_duplicate(proc_t *from, p
 			new->dtha_actions = kmem_alloc(sz, KM_SLEEP);
 
 			for (j = 0; j < new->dtha_nactions; j++) {
-				dtrace_difo_t *dp = helper->dtha_actions[j];
+				dp = helper->dtha_actions[j];
 
 				ASSERT(dp != NULL);
 				dp = dtrace_difo_duplicate(dp, vstate);
@@ -14893,9 +14879,7 @@ dtrace_helpers_duplicate(proc_t *from, p
 	if (hasprovs)
 		dtrace_helper_provider_register(to, newhelp, NULL);
 }
-#endif
 
-#if defined(sun)
 /*
  * DTrace Hook Functions
  */

Reply via email to