aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKornel Dulęba <kd@FreeBSD.org>2023-02-20 14:44:36 +0000
committerKornel Dulęba <kd@FreeBSD.org>2023-02-23 16:50:26 +0000
commit4d2427f2c4451babe1bad600ae02c8a7c66031fe (patch)
treecc692abecb1f6300410139a3d6f41711b9861f2e
parentf4a9e9fc79137889d273c06397b3bee8189b4deb (diff)
downloadsrc-4d2427f2c4451babe1bad600ae02c8a7c66031fe.tar.gz
src-4d2427f2c4451babe1bad600ae02c8a7c66031fe.zip
arm: Unbreak debugging programs that use FP instructions
Contrary to arm64, on armv7 get_vfpcontext/set_vfpcontext can be called from cpu_ptrace. This can be triggered when gdb hits a breakpoint in a userspace program. Relax td == currthread assertion to account for that situation. While here update an outdated comment in vfp_discard. Reported by: Mark Millard <marklmi@yahoo.com> Tested by: Mark Millard <marklmi@yahoo.com> Differential Revision: https://reviews.freebsd.org/D38696
-rw-r--r--sys/arm/arm/exec_machdep.c17
-rw-r--r--sys/arm/arm/vfp.c2
2 files changed, 6 insertions, 13 deletions
diff --git a/sys/arm/arm/exec_machdep.c b/sys/arm/arm/exec_machdep.c
index c14bd51146ef..96b382c9083f 100644
--- a/sys/arm/arm/exec_machdep.c
+++ b/sys/arm/arm/exec_machdep.c
@@ -100,19 +100,18 @@ get_vfpcontext(struct thread *td, mcontext_vfp_t *vfp)
{
struct pcb *pcb;
- MPASS(td == curthread);
+ MPASS(td == curthread || TD_IS_SUSPENDED(td) ||
+ P_SHOULDSTOP(td->td_proc));
pcb = td->td_pcb;
- if ((pcb->pcb_fpflags & PCB_FP_STARTED) != 0) {
+ if ((pcb->pcb_fpflags & PCB_FP_STARTED) != 0 && td == curthread) {
critical_enter();
vfp_store(&pcb->pcb_vfpstate, false);
critical_exit();
}
KASSERT(pcb->pcb_vfpsaved == &pcb->pcb_vfpstate,
("Called get_vfpcontext while the kernel is using the VFP"));
- memcpy(vfp->mcv_reg, pcb->pcb_vfpstate.reg,
- sizeof(vfp->mcv_reg));
- vfp->mcv_fpscr = pcb->pcb_vfpstate.fpscr;
+ memcpy(vfp, &pcb->pcb_vfpstate, sizeof(*vfp));
}
/*
@@ -123,19 +122,15 @@ set_vfpcontext(struct thread *td, mcontext_vfp_t *vfp)
{
struct pcb *pcb;
- MPASS(td == curthread);
-
pcb = td->td_pcb;
- if ((pcb->pcb_fpflags & PCB_FP_STARTED) != 0) {
+ if (td == curthread) {
critical_enter();
vfp_discard(td);
critical_exit();
}
KASSERT(pcb->pcb_vfpsaved == &pcb->pcb_vfpstate,
("Called set_vfpcontext while the kernel is using the VFP"));
- memcpy(pcb->pcb_vfpstate.reg, vfp->mcv_reg,
- sizeof(pcb->pcb_vfpstate.reg));
- pcb->pcb_vfpstate.fpscr = vfp->mcv_fpscr;
+ memcpy(&pcb->pcb_vfpstate, vfp, sizeof(*vfp));
}
#endif
diff --git a/sys/arm/arm/vfp.c b/sys/arm/arm/vfp.c
index 915d65c1b790..d51c4b6e0618 100644
--- a/sys/arm/arm/vfp.c
+++ b/sys/arm/arm/vfp.c
@@ -334,8 +334,6 @@ vfp_store(struct vfp_state *vfpsave, boolean_t disable_vfp)
* The current thread is dying. If the state currently in the hardware belongs
* to the current thread, set fpcurthread to NULL to indicate that the VFP
* hardware state does not belong to any thread. If the VFP is on, turn it off.
- * Called only from cpu_throw(), so we don't have to worry about a context
- * switch here.
*/
void
vfp_discard(struct thread *td)