Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 Jan 2018 12:31:21 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r328193 - stable/11/sys/kern
Message-ID:  <201801201231.w0KCVLEI097619@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Sat Jan 20 12:31:21 2018
New Revision: 328193
URL: https://svnweb.freebsd.org/changeset/base/328193

Log:
  MFC r327917:
  Add sysctl debug.kdb.stack_overflow.

Modified:
  stable/11/sys/kern/subr_kdb.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/kern/subr_kdb.c
==============================================================================
--- stable/11/sys/kern/subr_kdb.c	Sat Jan 20 12:19:02 2018	(r328192)
+++ stable/11/sys/kern/subr_kdb.c	Sat Jan 20 12:31:21 2018	(r328193)
@@ -82,6 +82,7 @@ static int kdb_sysctl_enter(SYSCTL_HANDLER_ARGS);
 static int kdb_sysctl_panic(SYSCTL_HANDLER_ARGS);
 static int kdb_sysctl_trap(SYSCTL_HANDLER_ARGS);
 static int kdb_sysctl_trap_code(SYSCTL_HANDLER_ARGS);
+static int kdb_sysctl_stack_overflow(SYSCTL_HANDLER_ARGS);
 
 static SYSCTL_NODE(_debug, OID_AUTO, kdb, CTLFLAG_RW, NULL, "KDB nodes");
 
@@ -107,6 +108,10 @@ SYSCTL_PROC(_debug_kdb, OID_AUTO, trap_code,
     CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_SECURE, NULL, 0,
     kdb_sysctl_trap_code, "I", "set to cause a page fault via code access");
 
+SYSCTL_PROC(_debug_kdb, OID_AUTO, stack_overflow,
+    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_SECURE, NULL, 0,
+    kdb_sysctl_stack_overflow, "I", "set to cause a stack overflow");
+
 SYSCTL_INT(_debug_kdb, OID_AUTO, break_to_debugger,
     CTLFLAG_RWTUN | CTLFLAG_SECURE,
     &kdb_break_to_debugger, 0, "Enable break to debugger");
@@ -221,6 +226,36 @@ kdb_sysctl_trap_code(SYSCTL_HANDLER_ARGS)
 	(*fp)(0x11111111, 0x22222222, 0x33333333);
 	return (0);
 }
+
+static void kdb_stack_overflow(volatile int *x)  __noinline;
+static void
+kdb_stack_overflow(volatile int *x)
+{
+
+	if (*x > 10000000)
+		return;
+	kdb_stack_overflow(x);
+	*x += PCPU_GET(cpuid) / 1000000;
+}
+
+static int
+kdb_sysctl_stack_overflow(SYSCTL_HANDLER_ARGS)
+{
+	int error, i;
+	volatile int x;
+
+	error = sysctl_wire_old_buffer(req, sizeof(int));
+	if (error == 0) {
+		i = 0;
+		error = sysctl_handle_int(oidp, &i, 0, req);
+	}
+	if (error != 0 || req->newptr == NULL)
+		return (error);
+	x = 0;
+	kdb_stack_overflow(&x);
+	return (0);
+}
+
 
 void
 kdb_panic(const char *msg)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801201231.w0KCVLEI097619>