svn commit: r309657 - head/sys/x86/x86
Mark Johnston
markj at FreeBSD.org
Tue Dec 6 22:48:29 UTC 2016
Author: markj
Date: Tue Dec 6 22:48:28 2016
New Revision: 309657
URL: https://svnweb.freebsd.org/changeset/base/309657
Log:
Require the STACK option for code that captures stacks of running threads.
stack_machdep.c is compiled if either of the DDB or STACK options is
specified, but stack_save_td_running() isn't useable from DDB. Moreover,
stack_save_td_running() works by raising an NMI on the CPU running the
target thread, and the corresponding handler is compiled only if STACK is
configured.
Reported by: kib
MFC after: 1 week
Modified:
head/sys/x86/x86/stack_machdep.c
Modified: head/sys/x86/x86/stack_machdep.c
==============================================================================
--- head/sys/x86/x86/stack_machdep.c Tue Dec 6 20:44:40 2016 (r309656)
+++ head/sys/x86/x86/stack_machdep.c Tue Dec 6 22:48:28 2016 (r309657)
@@ -28,6 +28,8 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include "opt_stack.h"
+
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
@@ -59,6 +61,7 @@ typedef struct i386_frame *x86_frame_t;
typedef struct amd64_frame *x86_frame_t;
#endif
+#ifdef STACK
static struct stack *nmi_stack;
static volatile struct thread *nmi_pending;
@@ -66,6 +69,7 @@ static volatile struct thread *nmi_pendi
static struct mtx nmi_lock;
MTX_SYSINIT(nmi_lock, &nmi_lock, "stack_nmi", MTX_SPIN);
#endif
+#endif
static void
stack_capture(struct thread *td, struct stack *st, register_t fp)
@@ -95,6 +99,7 @@ int
stack_nmi_handler(struct trapframe *tf)
{
+#ifdef STACK
/* Don't consume an NMI that wasn't meant for us. */
if (nmi_stack == NULL || curthread != nmi_pending)
return (0);
@@ -107,6 +112,9 @@ stack_nmi_handler(struct trapframe *tf)
atomic_store_rel_ptr((long *)&nmi_pending, (long)NULL);
return (1);
+#else
+ return (0);
+#endif
}
void
@@ -125,6 +133,7 @@ int
stack_save_td_running(struct stack *st, struct thread *td)
{
+#ifdef STACK
THREAD_LOCK_ASSERT(td, MA_OWNED);
MPASS(TD_IS_RUNNING(td));
@@ -148,10 +157,13 @@ stack_save_td_running(struct stack *st,
if (st->depth == 0)
/* We interrupted a thread in user mode. */
return (EAGAIN);
-#else
+#else /* !SMP */
KASSERT(0, ("curthread isn't running"));
-#endif
+#endif /* SMP */
return (0);
+#else /* !STACK */
+ return (EOPNOTSUPP);
+#endif /* STACK */
}
void
More information about the svn-src-all
mailing list