From a650e4d7c781bcb8119778619b32e381058aa2b7 Mon Sep 17 00:00:00 2001 From: Dale Rahn Date: Sun, 9 Sep 2001 23:56:41 +0000 Subject: Protect debugger accesses with setfault. Should improve debugger usability, need to verify that kernel exception code deals with this properly. --- sys/arch/macppc/macppc/db_memrw.c | 48 +++++++++++++++++++++++---------------- sys/arch/macppc/macppc/db_trace.c | 6 +++-- 2 files changed, 32 insertions(+), 22 deletions(-) (limited to 'sys/arch') diff --git a/sys/arch/macppc/macppc/db_memrw.c b/sys/arch/macppc/macppc/db_memrw.c index 8c8e400175b..226c2417bfd 100644 --- a/sys/arch/macppc/macppc/db_memrw.c +++ b/sys/arch/macppc/macppc/db_memrw.c @@ -1,5 +1,5 @@ /* $NetBSD: db_memrw.c,v 1.4 2001/05/18 20:38:27 matt Exp $ */ -/* $OpenBSD: db_memrw.c,v 1.1 2001/09/01 15:44:20 drahn Exp $ */ +/* $OpenBSD: db_memrw.c,v 1.2 2001/09/09 23:56:40 drahn Exp $ */ /* * Mach Operating System @@ -45,6 +45,7 @@ #include #include +#include #include @@ -58,21 +59,24 @@ db_read_bytes(addr, size, data) register char *data; { register char *src = (char*)addr; - - if (size == 4) { - *((int*)data) = *((int*)src); + faultbuf env; + faultbuf *old_onfault = curpcb->pcb_onfault; + if (setfault(env)) { + curpcb->pcb_onfault = old_onfault; return; } - if (size == 2) { + if (size == 4) { + *((int*)data) = *((int*)src); + } else if (size == 2) { *((short*)data) = *((short*)src); - return; - } - - while (size > 0) { - --size; - *data++ = *src++; + } else { + while (size > 0) { + --size; + *data++ = *src++; + } } + curpcb->pcb_onfault = old_onfault; } /* @@ -85,21 +89,25 @@ db_write_bytes(addr, size, data) register char *data; { register char *dst = (char *)addr; + faultbuf env; + faultbuf *old_onfault = curpcb->pcb_onfault; - if (size == 4) { - *((int*)dst) = *((int*)data); + if (setfault(env)) { + curpcb->pcb_onfault = old_onfault; return; } - if (size == 2) { + if (size == 4) { + *((int*)dst) = *((int*)data); + } else if (size == 2) { *((short*)dst) = *((short*)data); - return; - } - - while (size > 0) { - --size; - *dst++ = *data++; + } else { + while (size > 0) { + --size; + *dst++ = *data++; + } } syncicache((void *)addr, size); + curpcb->pcb_onfault = old_onfault; } diff --git a/sys/arch/macppc/macppc/db_trace.c b/sys/arch/macppc/macppc/db_trace.c index ef077301df9..8b329da05ef 100644 --- a/sys/arch/macppc/macppc/db_trace.c +++ b/sys/arch/macppc/macppc/db_trace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_trace.c,v 1.3 2001/09/05 20:49:55 drahn Exp $ */ +/* $OpenBSD: db_trace.c,v 1.4 2001/09/09 23:56:40 drahn Exp $ */ /* $NetBSD: db_trace.c,v 1.15 1996/02/22 23:23:41 gwr Exp $ */ /* @@ -100,11 +100,13 @@ int db_read32(u_int32_t paddr, u_int32_t *value) { faultbuf env; + faultbuf *old_onfault = curpcb->pcb_onfault; if (setfault(env)) { - curpcb->pcb_onfault = 0; + curpcb->pcb_onfault = old_onfault; return EFAULT; } *value = *(u_int32_t *)paddr; + curpcb->pcb_onfault = old_onfault; return 0; } -- cgit v1.2.3