diff options
author | Konstantin Belousov <kib@FreeBSD.org> | 2021-04-09 23:19:23 +0000 |
---|---|---|
committer | Konstantin Belousov <kib@FreeBSD.org> | 2021-04-10 01:25:01 +0000 |
commit | a8b75a57c9b2cb3388746f097a55086a0f8c5d38 (patch) | |
tree | ae17e9dd9822d3851d68566a7b8431c95f802d9a /sys/i386/i386/machdep.c | |
parent | 86e352c934e5af49866d13a79ddb7c6fbf090cb9 (diff) | |
download | src-a8b75a57c9b2cb3388746f097a55086a0f8c5d38.tar.gz src-a8b75a57c9b2cb3388746f097a55086a0f8c5d38.zip |
x86: add x86_clear_dbregs() helper
Move the code from exec_setregs() to reset debug registers state on exec,
to the x86_clear_dbregs() helper
Reviewed by: jhb
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D29687
Diffstat (limited to 'sys/i386/i386/machdep.c')
-rw-r--r-- | sys/i386/i386/machdep.c | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index a9749d331f89..5fec2e448c53 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__; |