From 2265d5e30dd81e9fdef4dad9bcb0f47f314bf186 Mon Sep 17 00:00:00 2001 From: "Brian S. Dean" Date: Mon, 28 Feb 2000 19:48:51 +0000 Subject: [PATCH] Reset the hardware debug registers when exec'ing a new image. Reviewed by: bde,jlemon Approved by: jkh --- sys/amd64/amd64/machdep.c | 22 ++++++++++++++++++++++ sys/i386/i386/machdep.c | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 1efc7e48f8e..c204fbeeb72 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -1031,6 +1031,28 @@ setregs(p, entry, stack, ps_strings) else pcb->pcb_gs = _udatasel; + /* + * 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; + } + /* * Initialize the math emulator (if any) for the current process. * Actually, just clear the bit that says that the emulator has diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index 1efc7e48f8e..c204fbeeb72 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -1031,6 +1031,28 @@ setregs(p, entry, stack, ps_strings) else pcb->pcb_gs = _udatasel; + /* + * 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; + } + /* * Initialize the math emulator (if any) for the current process. * Actually, just clear the bit that says that the emulator has