changeset 3682:48f0fd311ddb

6512250 dtrace_getustack_common() could be improved
author jhaslam
date Tue, 20 Feb 2007 05:32:53 -0800
parents d93cfde2f771
children 39e9a07d770e
files usr/src/cmd/dtrace/test/pkg/SUNWdtrt/prototype_com usr/src/cmd/dtrace/test/pkg/SUNWdtrt/prototype_i386 usr/src/cmd/dtrace/test/pkg/SUNWdtrt/prototype_sparc usr/src/cmd/dtrace/test/tst/common/Makefile usr/src/cmd/dtrace/test/tst/common/ustack/tst.bigstack.c usr/src/cmd/dtrace/test/tst/common/ustack/tst.bigstack.d usr/src/cmd/dtrace/test/tst/i386/ustack/tst.circstack.d usr/src/cmd/dtrace/test/tst/i386/ustack/tst.circstack.s usr/src/cmd/dtrace/test/tst/sparc/ustack/tst.circstack.d usr/src/cmd/dtrace/test/tst/sparc/ustack/tst.circstack.s usr/src/cmd/mdb/common/modules/dtrace/dtrace.c usr/src/lib/libdtrace/common/dt_error.c usr/src/lib/libdtrace/common/dt_handle.c usr/src/lib/libdtrace/common/dt_open.c usr/src/lib/libdtrace/common/unistd.d usr/src/lib/libdtrace_jni/common/dtj_consume.c usr/src/lib/libdtrace_jni/common/dtj_error.c usr/src/uts/common/dtrace/dtrace.c usr/src/uts/common/sys/cpuvar.h usr/src/uts/common/sys/dtrace.h usr/src/uts/intel/dtrace/dtrace_isa.c usr/src/uts/sparc/dtrace/dtrace_isa.c
diffstat 22 files changed, 365 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/dtrace/test/pkg/SUNWdtrt/prototype_com	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/cmd/dtrace/test/pkg/SUNWdtrt/prototype_com	Tue Feb 20 05:32:53 2007 -0800
@@ -1350,6 +1350,8 @@
 f none opt/SUNWdtrt/tst/common/usdt/tst.user.ksh.out 0444 root bin
 d none opt/SUNWdtrt/tst/common/ustack 0755 root bin
 f none opt/SUNWdtrt/tst/common/ustack/tst.depth.ksh 0444 root bin
+f none opt/SUNWdtrt/tst/common/ustack/tst.bigstack.exe 0555 root bin
+f none opt/SUNWdtrt/tst/common/ustack/tst.bigstack.d 0444 root bin
 f none opt/SUNWdtrt/tst/common/ustack/tst.spin.exe 0555 root bin
 f none opt/SUNWdtrt/tst/common/ustack/tst.spin.ksh 0444 root bin
 d none opt/SUNWdtrt/tst/common/vars 0755 root bin
--- a/usr/src/cmd/dtrace/test/pkg/SUNWdtrt/prototype_i386	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/cmd/dtrace/test/pkg/SUNWdtrt/prototype_i386	Tue Feb 20 05:32:53 2007 -0800
@@ -20,7 +20,7 @@
 #
 
 #
-# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
 # ident	"%Z%%M%	%I%	%E% SMI"
@@ -54,6 +54,8 @@
 f none opt/SUNWdtrt/tst/i386/ustack/tst.annotated.d 0444 root bin
 f none opt/SUNWdtrt/tst/i386/ustack/tst.annotated.d.out 0444 root bin
 f none opt/SUNWdtrt/tst/i386/ustack/tst.annotated.exe 0555 root bin
+f none opt/SUNWdtrt/tst/i386/ustack/tst.circstack.d 0444 root bin
+f none opt/SUNWdtrt/tst/i386/ustack/tst.circstack.exe 0555 root bin
 f none opt/SUNWdtrt/tst/i386/ustack/tst.helper.d 0444 root bin
 f none opt/SUNWdtrt/tst/i386/ustack/tst.helper.d.out 0444 root bin
 f none opt/SUNWdtrt/tst/i386/ustack/tst.helper.exe 0555 root bin
--- a/usr/src/cmd/dtrace/test/pkg/SUNWdtrt/prototype_sparc	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/cmd/dtrace/test/pkg/SUNWdtrt/prototype_sparc	Tue Feb 20 05:32:53 2007 -0800
@@ -20,7 +20,7 @@
 #
 
 #
-# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
 #ident	"%Z%%M%	%I%	%E% SMI"
@@ -45,6 +45,8 @@
 f none opt/SUNWdtrt/tst/sparc/ustack/tst.annotated.d 0444 root bin
 f none opt/SUNWdtrt/tst/sparc/ustack/tst.annotated.d.out 0444 root bin
 f none opt/SUNWdtrt/tst/sparc/ustack/tst.annotated.exe 0555 root bin
+f none opt/SUNWdtrt/tst/sparc/ustack/tst.circstack.d 0444 root bin
+f none opt/SUNWdtrt/tst/sparc/ustack/tst.circstack.exe 0555 root bin
 f none opt/SUNWdtrt/tst/sparc/ustack/tst.helper.d 0444 root bin
 f none opt/SUNWdtrt/tst/sparc/ustack/tst.helper.d.out 0444 root bin
 f none opt/SUNWdtrt/tst/sparc/ustack/tst.helper.exe 0555 root bin
--- a/usr/src/cmd/dtrace/test/tst/common/Makefile	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/cmd/dtrace/test/tst/common/Makefile	Tue Feb 20 05:32:53 2007 -0800
@@ -36,6 +36,8 @@
 sysevent/tst.post.exe := LIBS += -lsysevent
 sysevent/tst.post_chan.exe := LIBS += -lsysevent
 
+ustack/tst.bigstack.exe := COPTFLAG += -xO1
+
 GCC = /usr/sfw/bin/gcc
 GCCFLAGS_sparc = -mcpu=ultrasparc
 GCCFLAGS = $(GCCFLAGS_$(MACH))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/dtrace/test/tst/common/ustack/tst.bigstack.c	Tue Feb 20 05:32:53 2007 -0800
@@ -0,0 +1,59 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+void grow1(int);
+
+void
+grow(int frame)
+{
+	/*
+	 * Create a ridiculously large stack - enough to push us over
+	 * the default setting of 'dtrace_ustackdepth_max' (2048).
+	 */
+	if (frame >= 2048)
+		for (;;)
+			getpid();
+
+	grow1(++frame);
+}
+
+void
+grow1(int frame)
+{
+	grow(++frame);
+}
+
+int
+main(int argc, char *argv[])
+{
+	grow(1);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/dtrace/test/tst/common/ustack/tst.bigstack.d	Tue Feb 20 05:32:53 2007 -0800
@@ -0,0 +1,45 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+syscall::getpid:entry
+/pid == $1/
+{
+        @[ustackdepth] = count();
+}
+
+ERROR
+/arg4 == DTRACEFLT_BADSTACK/
+{
+        exit(0);
+}
+
+profile:::tick-1s
+/++n  == 10/
+{
+        exit(1)
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/dtrace/test/tst/i386/ustack/tst.circstack.d	Tue Feb 20 05:32:53 2007 -0800
@@ -0,0 +1,46 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+syscall::getpid:entry
+/pid == $1/
+{
+        @[ustackdepth] = count();
+}
+
+ERROR
+/arg4 == DTRACEFLT_BADSTACK/
+{
+        exit(0);
+}
+
+profile:::tick-1s
+/++n  == 10/
+{
+        exit(1)
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/dtrace/test/tst/i386/ustack/tst.circstack.s	Tue Feb 20 05:32:53 2007 -0800
@@ -0,0 +1,40 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#include <sys/asm_linkage.h>
+
+	ENTRY(main)
+	pushl	%ebp
+	movl	%esp, %ebp
+	movl	%esp, (%ebp)
+loop:
+	call	getpid
+	jmp	loop
+	leave
+	ret
+	SET_SIZE(main)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/dtrace/test/tst/sparc/ustack/tst.circstack.d	Tue Feb 20 05:32:53 2007 -0800
@@ -0,0 +1,46 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+syscall::getpid:entry
+/pid == $1/
+{
+        @[ustackdepth] = count();
+}
+
+ERROR
+/arg4 == DTRACEFLT_BADSTACK/
+{
+        exit(0);
+}
+
+profile:::tick-1s
+/++n  == 10/
+{
+        exit(1)
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/cmd/dtrace/test/tst/sparc/ustack/tst.circstack.s	Tue Feb 20 05:32:53 2007 -0800
@@ -0,0 +1,41 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#include <sys/asm_linkage.h>
+
+	ENTRY(main)
+	save	%sp, -SA(MINFRAME), %sp
+	mov	%sp, %fp
+loop:
+	call	getpid
+	nop
+	ba	loop
+	nop
+	ret
+	restore
+	SET_SIZE(main)
--- a/usr/src/cmd/mdb/common/modules/dtrace/dtrace.c	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/cmd/mdb/common/modules/dtrace/dtrace.c	Tue Feb 20 05:32:53 2007 -0800
@@ -20,7 +20,7 @@
  */
 
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -1398,6 +1398,7 @@
 			    f == DTRACEFLT_KPRIV ? "KPRIV" :
 			    f == DTRACEFLT_UPRIV ? "UPRIV" :
 			    f == DTRACEFLT_TUPOFLOW ? "TUPOFLOW" :
+			    f == DTRACEFLT_BADSTACK ? "BADSTACK" :
 			    "DTRACEFLT_UNKNOWN");
 			mdb_printf("%?s| %?s %12s     addr: 0x%x\n", "", "", "",
 			    help.dtht_illval);
--- a/usr/src/lib/libdtrace/common/dt_error.c	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/lib/libdtrace/common/dt_error.c	Tue Feb 20 05:32:53 2007 -0800
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -203,6 +203,7 @@
 		{ DTRACEFLT_KPRIV,	"invalid kernel access" },
 		{ DTRACEFLT_UPRIV,	"invalid user access" },
 		{ DTRACEFLT_TUPOFLOW,	"tuple stack overflow" },
+		{ DTRACEFLT_BADSTACK,	"bad stack" },
 		{ DTRACEFLT_LIBRARY,	"library-level fault" },
 		{ 0,			NULL }
 	};
--- a/usr/src/lib/libdtrace/common/dt_handle.c	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/lib/libdtrace/common/dt_handle.c	Tue Feb 20 05:32:53 2007 -0800
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -205,6 +204,7 @@
 	switch (err.dteda_fault) {
 	case DTRACEFLT_BADADDR:
 	case DTRACEFLT_BADALIGN:
+	case DTRACEFLT_BADSTACK:
 		(void) sprintf(details, " (0x%llx)",
 		    (u_longlong_t)err.dteda_addr);
 		break;
--- a/usr/src/lib/libdtrace/common/dt_open.c	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/lib/libdtrace/common/dt_open.c	Tue Feb 20 05:32:53 2007 -0800
@@ -20,7 +20,7 @@
  */
 
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -100,8 +100,9 @@
 #define	DT_VERS_1_2_2	DT_VERSION_NUMBER(1, 2, 2)
 #define	DT_VERS_1_3	DT_VERSION_NUMBER(1, 3, 0)
 #define	DT_VERS_1_4	DT_VERSION_NUMBER(1, 4, 0)
-#define	DT_VERS_LATEST	DT_VERS_1_4
-#define	DT_VERS_STRING	"Sun D 1.4"
+#define	DT_VERS_1_4_1	DT_VERSION_NUMBER(1, 4, 1)
+#define	DT_VERS_LATEST	DT_VERS_1_4_1
+#define	DT_VERS_STRING	"Sun D 1.4.1"
 
 const dt_version_t _dtrace_versions[] = {
 	DT_VERS_1_0,	/* D API 1.0.0 (PSARC 2001/466) Solaris 10 FCS */
@@ -111,6 +112,7 @@
 	DT_VERS_1_2_2,	/* D API 1.2.2 Solaris Express 6/06 */
 	DT_VERS_1_3,	/* D API 1.3 Solaris Express 10/06 */
 	DT_VERS_1_4,	/* D API 1.4 Solaris Express 2/07 */
+	DT_VERS_1_4_1,	/* D API 1.4.1 Solaris Express 4/07 */
 	0
 };
 
--- a/usr/src/lib/libdtrace/common/unistd.d	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/lib/libdtrace/common/unistd.d	Tue Feb 20 05:32:53 2007 -0800
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -52,3 +51,6 @@
 
 inline int DTRACEFLT_TUPOFLOW = 8;	/* Tuple stack overflow */
 #pragma D binding "1.0" DTRACEFLT_TUPOFLOW
+
+inline int DTRACEFLT_BADSTACK = 9;	/* Bad stack */
+#pragma D binding "1.4.1" DTRACEFLT_BADSTACK
--- a/usr/src/lib/libdtrace_jni/common/dtj_consume.c	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/lib/libdtrace_jni/common/dtj_consume.c	Tue Feb 20 05:32:53 2007 -0800
@@ -301,6 +301,7 @@
 	switch (data->dteda_fault) {
 	case DTRACEFLT_BADADDR:
 	case DTRACEFLT_BADALIGN:
+	case DTRACEFLT_BADSTACK:
 		addr = data->dteda_addr;
 		break;
 	default:
--- a/usr/src/lib/libdtrace_jni/common/dtj_error.c	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/lib/libdtrace_jni/common/dtj_error.c	Tue Feb 20 05:32:53 2007 -0800
@@ -20,7 +20,7 @@
  */
 
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -68,6 +68,9 @@
 	case DTRACEFLT_TUPOFLOW:
 		name = "DTRACEFLT_TUPOFLOW";
 		break;
+	case DTRACEFLT_BADSTACK:
+		name = "DTRACEFLT_BADSTACK";
+		break;
 	case DTRACEFLT_LIBRARY:
 		name = "DTRACEFLT_LIBRARY";
 		break;
--- a/usr/src/uts/common/dtrace/dtrace.c	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/uts/common/dtrace/dtrace.c	Tue Feb 20 05:32:53 2007 -0800
@@ -435,6 +435,7 @@
 	((flags) & CPU_DTRACE_TUPOFLOW) ?  DTRACEFLT_TUPOFLOW :		\
 	((flags) & CPU_DTRACE_BADALIGN) ?  DTRACEFLT_BADALIGN :		\
 	((flags) & CPU_DTRACE_NOSCRATCH) ?  DTRACEFLT_NOSCRATCH :	\
+	((flags) & CPU_DTRACE_BADSTACK) ?  DTRACEFLT_BADSTACK :		\
 	DTRACEFLT_UNKNOWN)
 
 #define	DTRACEACT_ISSTRING(act)						\
--- a/usr/src/uts/common/sys/cpuvar.h	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/uts/common/sys/cpuvar.h	Tue Feb 20 05:32:53 2007 -0800
@@ -329,11 +329,13 @@
 #define	CPU_DTRACE_FAKERESTORE	0x0400	/* pid provider hint to getreg */
 #endif
 #define	CPU_DTRACE_ENTRY	0x0800	/* pid provider hint to ustack() */
+#define	CPU_DTRACE_BADSTACK	0x1000	/* DTrace fault: bad stack */
 
 #define	CPU_DTRACE_FAULT	(CPU_DTRACE_BADADDR | CPU_DTRACE_BADALIGN | \
 				CPU_DTRACE_DIVZERO | CPU_DTRACE_ILLOP | \
 				CPU_DTRACE_NOSCRATCH | CPU_DTRACE_KPRIV | \
-				CPU_DTRACE_UPRIV | CPU_DTRACE_TUPOFLOW)
+				CPU_DTRACE_UPRIV | CPU_DTRACE_TUPOFLOW | \
+				CPU_DTRACE_BADSTACK)
 #define	CPU_DTRACE_ERROR	(CPU_DTRACE_FAULT | CPU_DTRACE_DROP)
 
 /*
--- a/usr/src/uts/common/sys/dtrace.h	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/uts/common/sys/dtrace.h	Tue Feb 20 05:32:53 2007 -0800
@@ -1067,6 +1067,7 @@
 #define	DTRACEFLT_KPRIV			6	/* Illegal kernel access */
 #define	DTRACEFLT_UPRIV			7	/* Illegal user access */
 #define	DTRACEFLT_TUPOFLOW		8	/* Tuple stack overflow */
+#define	DTRACEFLT_BADSTACK		9	/* Bad stack */
 
 #define	DTRACEFLT_LIBRARY		1000	/* Library-level fault */
 
--- a/usr/src/uts/intel/dtrace/dtrace_isa.c	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/uts/intel/dtrace/dtrace_isa.c	Tue Feb 20 05:32:53 2007 -0800
@@ -35,6 +35,8 @@
 
 extern uintptr_t kernelbase;
 
+int	dtrace_ustackdepth_max = 2048;
+
 void
 dtrace_getpcstack(pc_t *pcstack, int pcstack_limit, int aframes,
     uint32_t *intrpc)
@@ -113,12 +115,14 @@
 	klwp_t *lwp = ttolwp(curthread);
 	proc_t *p = curproc;
 	uintptr_t oldcontext = lwp->lwp_oldcontext;
+	uintptr_t oldsp;
 	volatile uint16_t *flags =
 	    (volatile uint16_t *)&cpu_core[CPU->cpu_id].cpuc_dtrace_flags;
 	size_t s1, s2;
 	int ret = 0;
 
 	ASSERT(pcstack == NULL || pcstack_limit > 0);
+	ASSERT(dtrace_ustackdepth_max > 0);
 
 	if (p->p_model == DATAMODEL_NATIVE) {
 		s1 = sizeof (struct frame) + 2 * sizeof (long);
@@ -129,7 +133,16 @@
 	}
 
 	while (pc != 0) {
-		ret++;
+		/*
+		 * We limit the number of times we can go around this
+		 * loop to account for a circular stack.
+		 */
+		if (ret++ >= dtrace_ustackdepth_max) {
+			*flags |= CPU_DTRACE_BADSTACK;
+			cpu_core[CPU->cpu_id].cpuc_dtrace_illval = sp;
+			break;
+		}
+
 		if (pcstack != NULL) {
 			*pcstack++ = (uint64_t)pc;
 			pcstack_limit--;
@@ -140,6 +153,8 @@
 		if (sp == 0)
 			break;
 
+		oldsp = sp;
+
 		if (oldcontext == sp + s1 || oldcontext == sp + s2) {
 			if (p->p_model == DATAMODEL_NATIVE) {
 				ucontext_t *ucp = (ucontext_t *)oldcontext;
@@ -172,6 +187,12 @@
 			}
 		}
 
+		if (sp == oldsp) {
+			*flags |= CPU_DTRACE_BADSTACK;
+			cpu_core[CPU->cpu_id].cpuc_dtrace_illval = sp;
+			break;
+		}
+
 		/*
 		 * This is totally bogus:  if we faulted, we're going to clear
 		 * the fault and break.  This is to deal with the apparently
--- a/usr/src/uts/sparc/dtrace/dtrace_isa.c	Mon Feb 19 20:47:33 2007 -0800
+++ b/usr/src/uts/sparc/dtrace/dtrace_isa.c	Tue Feb 20 05:32:53 2007 -0800
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -21,7 +20,7 @@
  */
 
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -66,6 +65,8 @@
 extern void dtrace_putreg_win(uint_t, ulong_t);
 extern int dtrace_fish(int, int, uintptr_t *);
 
+int	dtrace_ustackdepth_max = 2048;
+
 /*
  * This is similar in principle to getpcstack(), but there are several marked
  * differences in implementation:
@@ -361,8 +362,12 @@
 {
 	proc_t *p = curproc;
 	int ret = 0;
+	uintptr_t oldsp;
+	volatile uint16_t *flags =
+	    (volatile uint16_t *)&cpu_core[CPU->cpu_id].cpuc_dtrace_flags;
 
 	ASSERT(pcstack == NULL || pcstack_limit > 0);
+	ASSERT(dtrace_ustackdepth_max > 0);
 
 	if (p->p_model == DATAMODEL_NATIVE) {
 		for (;;) {
@@ -373,13 +378,23 @@
 			    !IS_P2ALIGNED((uintptr_t)fr, STACK_ALIGN))
 				break;
 
+			oldsp = sp;
+
 			pc = dtrace_fulword(&fr->fr_savpc);
 			sp = dtrace_fulword(&fr->fr_savfp);
 
 			if (pc == 0)
 				break;
 
-			ret++;
+			/*
+			 * We limit the number of times we can go around this
+			 * loop to account for a circular stack.
+			 */
+			if (sp == oldsp || ret++ >= dtrace_ustackdepth_max) {
+				*flags |= CPU_DTRACE_BADSTACK;
+				cpu_core[CPU->cpu_id].cpuc_dtrace_illval = sp;
+				break;
+			}
 
 			if (pcstack != NULL) {
 				*pcstack++ = pc;
@@ -404,13 +419,19 @@
 			    !IS_P2ALIGNED((uintptr_t)fr, STACK_ALIGN32))
 				break;
 
+			oldsp = sp;
+
 			pc = dtrace_fuword32(&fr->fr_savpc);
 			sp = dtrace_fuword32(&fr->fr_savfp);
 
 			if (pc == 0)
 				break;
 
-			ret++;
+			if (sp == oldsp || ret++ >= dtrace_ustackdepth_max) {
+				*flags |= CPU_DTRACE_BADSTACK;
+				cpu_core[CPU->cpu_id].cpuc_dtrace_illval = sp;
+				break;
+			}
 
 			if (pcstack != NULL) {
 				*pcstack++ = pc;