aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2021-04-09 23:19:23 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2021-04-23 11:14:08 +0000
commit88d6f049c12f5d6945209c8805d4399a766de524 (patch)
treee79d4825c49feca071ae0e82be53797eb21b99f1
parent13e0ef823047491f8c246dd721ec22778c4d5384 (diff)
downloadsrc-88d6f049c12f5d6945209c8805d4399a766de524.tar.gz
src-88d6f049c12f5d6945209c8805d4399a766de524.zip
x86: add x86_clear_dbregs() helper
(cherry picked from commit a8b75a57c9b2cb3388746f097a55086a0f8c5d38)
-rw-r--r--sys/amd64/amd64/machdep.c50
-rw-r--r--sys/i386/i386/machdep.c50
-rw-r--r--sys/x86/include/x86_var.h1
3 files changed, 59 insertions, 42 deletions
diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c
index 458d700a21e0..2901ef15e69a 100644
--- a/sys/amd64/amd64/machdep.c
+++ b/sys/amd64/amd64/machdep.c
@@ -582,6 +582,34 @@ freebsd4_sigreturn(struct thread *td, struct freebsd4_sigreturn_args *uap)
#endif
/*
+ * Reset the hardware debug registers if they were in use.
+ * They won't have any meaning for the newly exec'd process.
+ */
+void
+x86_clear_dbregs(struct pcb *pcb)
+{
+ if ((pcb->pcb_flags & PCB_DBREGS) == 0)
+ return;
+
+ pcb->pcb_dr0 = 0;
+ pcb->pcb_dr1 = 0;
+ pcb->pcb_dr2 = 0;
+ pcb->pcb_dr3 = 0;
+ pcb->pcb_dr6 = 0;
+ pcb->pcb_dr7 = 0;
+
+ if (pcb == curpcb) {
+ /*
+ * Clear the debug registers on the running CPU,
+ * otherwise they will end up affecting the next
+ * process we switch to.
+ */
+ reset_dbregs();
+ }
+ clear_pcb_flags(pcb, PCB_DBREGS);
+}
+
+/*
* Reset registers to default values on exec.
*/
void
@@ -617,27 +645,7 @@ exec_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
regs->tf_gs = _ugssel;
regs->tf_flags = TF_HASSEGS;
- /*
- * Reset the hardware debug registers if they were in use.
- * They won't have any meaning for the newly exec'd process.
- */
- if (pcb->pcb_flags & PCB_DBREGS) {
- pcb->pcb_dr0 = 0;
- pcb->pcb_dr1 = 0;
- pcb->pcb_dr2 = 0;
- pcb->pcb_dr3 = 0;
- pcb->pcb_dr6 = 0;
- pcb->pcb_dr7 = 0;
- if (pcb == curpcb) {
- /*
- * Clear the debug registers on the running
- * CPU, otherwise they will end up affecting
- * the next process we switch to.
- */
- reset_dbregs();
- }
- clear_pcb_flags(pcb, PCB_DBREGS);
- }
+ x86_clear_dbregs(pcb);
/*
* Drop the FP state if we hold it, so that the process gets a
diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c
index e847d97b8bcf..888550eab6ad 100644
--- a/sys/i386/i386/machdep.c
+++ b/sys/i386/i386/machdep.c
@@ -1122,6 +1122,34 @@ setup_priv_lcall_gate(struct proc *p)
#endif
/*
+ * Reset the hardware debug registers if they were in use.
+ * They won't have any meaning for the newly exec'd process.
+ */
+void
+x86_clear_dbregs(struct pcb *pcb)
+{
+ if ((pcb->pcb_flags & PCB_DBREGS) == 0)
+ return;
+
+ pcb->pcb_dr0 = 0;
+ pcb->pcb_dr1 = 0;
+ pcb->pcb_dr2 = 0;
+ pcb->pcb_dr3 = 0;
+ pcb->pcb_dr6 = 0;
+ pcb->pcb_dr7 = 0;
+
+ if (pcb == curpcb) {
+ /*
+ * Clear the debug registers on the running CPU,
+ * otherwise they will end up affecting the next
+ * process we switch to.
+ */
+ reset_dbregs();
+ }
+ pcb->pcb_flags &= ~PCB_DBREGS;
+}
+
+/*
* Reset registers to default values on exec.
*/
void
@@ -1174,27 +1202,7 @@ exec_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
/* PS_STRINGS value for BSD/OS binaries. It is 0 for non-BSD/OS. */
regs->tf_ebx = (register_t)imgp->ps_strings;
- /*
- * Reset the hardware debug registers if they were in use.
- * They won't have any meaning for the newly exec'd process.
- */
- if (pcb->pcb_flags & PCB_DBREGS) {
- pcb->pcb_dr0 = 0;
- pcb->pcb_dr1 = 0;
- pcb->pcb_dr2 = 0;
- pcb->pcb_dr3 = 0;
- pcb->pcb_dr6 = 0;
- pcb->pcb_dr7 = 0;
- if (pcb == curpcb) {
- /*
- * Clear the debug registers on the running
- * CPU, otherwise they will end up affecting
- * the next process we switch to.
- */
- reset_dbregs();
- }
- pcb->pcb_flags &= ~PCB_DBREGS;
- }
+ x86_clear_dbregs(pcb);
pcb->pcb_initial_npxcw = __INITIAL_NPXCW__;
diff --git a/sys/x86/include/x86_var.h b/sys/x86/include/x86_var.h
index a802068d6fb4..cc730fcd1bf1 100644
--- a/sys/x86/include/x86_var.h
+++ b/sys/x86/include/x86_var.h
@@ -122,6 +122,7 @@ void cpu_setregs(void);
int dbreg_set_watchpoint(vm_offset_t addr, vm_size_t size, int access);
int dbreg_clr_watchpoint(vm_offset_t addr, vm_size_t size);
void dbreg_list_watchpoints(void);
+void x86_clear_dbregs(struct pcb *pcb);
bool disable_wp(void);
void restore_wp(bool old_wp);
void finishidentcpu(void);