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
This commit is contained in:
parent
fe5a91c61d
commit
d4d64ed3c6
@ -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_pending;
|
||||
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, struct thread *td)
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user