Author: kib Date: Sat Jan 13 11:59:49 2018 New Revision: 327917 URL: https://svnweb.freebsd.org/changeset/base/327917
Log: Add sysctl debug.kdb.stack_overflow to conveniently test kernel handling of the kstack overflow. Sponsored by: The FreeBSD Foundation MFC after: 1 week Modified: head/sys/kern/subr_kdb.c Modified: head/sys/kern/subr_kdb.c ============================================================================== --- head/sys/kern/subr_kdb.c Sat Jan 13 09:30:34 2018 (r327916) +++ head/sys/kern/subr_kdb.c Sat Jan 13 11:59:49 2018 (r327917) @@ -85,6 +85,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"); @@ -110,6 +111,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"); @@ -224,6 +229,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) _______________________________________________ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"