tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[PATCH v3 2/2] compat32: Implement PT_GETDBREGS and PT_SETDBREGS



Uncomment and improve the implementation of compat32 support for
PT_GETDBREGS and PT_SETDBREGS requests.

The new implementation uses x86_dbregs_read() and x86_dbregs_write()
function instead of accessing pcb directly.  While this might be
a little slower, it guarantees that the needed pcb field is allocated
correctly.

Furthermore, the code introduces necessary sanity checks
for PT_SETDBREGS arguments.
---
 sys/arch/amd64/amd64/netbsd32_machdep.c | 52 +++++++++++++------------
 1 file changed, 27 insertions(+), 25 deletions(-)

diff --git a/sys/arch/amd64/amd64/netbsd32_machdep.c b/sys/arch/amd64/amd64/netbsd32_machdep.c
index 1b895e378c1e..d6b07ed6c0e0 100644
--- a/sys/arch/amd64/amd64/netbsd32_machdep.c
+++ b/sys/arch/amd64/amd64/netbsd32_machdep.c
@@ -395,23 +395,19 @@ netbsd32_process_read_fpregs(struct lwp *l, struct fpreg32 *regs, size_t *sz)
 int
 netbsd32_process_read_dbregs(struct lwp *l, struct dbreg32 *regs, size_t *sz)
 {
-#if notyet
-	struct pcb *pcb;
-
-	pcb = lwp_getpcb(l);
+	struct dbreg regs64;
 
-	regs->dr[0] = pcb->pcb_dbregs->dr[0] & 0xffffffff;
-	regs->dr[1] = pcb->pcb_dbregs->dr[1] & 0xffffffff;
-	regs->dr[2] = pcb->pcb_dbregs->dr[2] & 0xffffffff;
-	regs->dr[3] = pcb->pcb_dbregs->dr[3] & 0xffffffff;
+	x86_dbregs_read(l, &regs64);
+	memset(regs, 0, sizeof(*regs));
+	regs->dr[0] = regs64.dr[0] & 0xffffffff;
+	regs->dr[1] = regs64.dr[1] & 0xffffffff;
+	regs->dr[2] = regs64.dr[2] & 0xffffffff;
+	regs->dr[3] = regs64.dr[3] & 0xffffffff;
 
-	regs->dr[6] = pcb->pcb_dbregs->dr[6] & 0xffffffff;
-	regs->dr[7] = pcb->pcb_dbregs->dr[7] & 0xffffffff;
+	regs->dr[6] = regs64.dr[6] & 0xffffffff;
+	regs->dr[7] = regs64.dr[7] & 0xffffffff;
 
 	return 0;
-#else
-	return ENOTSUP;
-#endif
 }
 
 int
@@ -478,23 +474,29 @@ int
 netbsd32_process_write_dbregs(struct lwp *l, const struct dbreg32 *regs,
     size_t sz)
 {
-#if notyet
-	struct pcb *pcb;
+	size_t i;
+	struct dbreg regs64;
 
-	pcb = lwp_getpcb(l);
+	/* Check that DR0-DR3 contain user-space address */
+	for (i = 0; i < X86_DBREGS; i++) {
+		if (regs->dr[i] >= VM_MAXUSER_ADDRESS32)
+			return EINVAL;
+	}
 
-	pcb->pcb_dbregs->dr[0] = regs->dr[0];
-	pcb->pcb_dbregs->dr[1] = regs->dr[1];
-	pcb->pcb_dbregs->dr[2] = regs->dr[2];
-	pcb->pcb_dbregs->dr[3] = regs->dr[3];
+	if (regs->dr[7] & X86_DR7_GENERAL_DETECT_ENABLE) {
+		return EINVAL;
+	}
 
-	pcb->pcb_dbregs->dr[6] = regs->dr[6];
-	pcb->pcb_dbregs->dr[7] = regs->dr[7];
+	regs64.dr[0] = regs->dr[0];
+	regs64.dr[1] = regs->dr[1];
+	regs64.dr[2] = regs->dr[2];
+	regs64.dr[3] = regs->dr[3];
 
+	regs64.dr[6] = regs->dr[6];
+	regs64.dr[7] = regs->dr[7];
+
+	x86_dbregs_write(l, &regs64);
 	return 0;
-#else
-	return ENOTSUP;
-#endif
 }
 
 int
-- 
2.22.0.rc1



Home | Main Index | Thread Index | Old Index