From owner-p4-projects@FreeBSD.ORG Sun Jun 13 09:49:36 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 20A3F16A4D1; Sun, 13 Jun 2004 09:49:36 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D306316A4CE for ; Sun, 13 Jun 2004 09:49:35 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id B99E443D45 for ; Sun, 13 Jun 2004 09:49:35 +0000 (GMT) (envelope-from jmallett@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.11/8.12.11) with ESMTP id i5D9mXDm090551 for ; Sun, 13 Jun 2004 09:48:33 GMT (envelope-from jmallett@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.11/8.12.11/Submit) id i5D9mXFP090548 for perforce@freebsd.org; Sun, 13 Jun 2004 09:48:33 GMT (envelope-from jmallett@freebsd.org) Date: Sun, 13 Jun 2004 09:48:33 GMT Message-Id: <200406130948.i5D9mXFP090548@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jmallett@freebsd.org using -f From: Juli Mallett To: Perforce Change Reviews Subject: PERFORCE change 54806 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Jun 2004 09:49:36 -0000 http://perforce.freebsd.org/chv.cgi?CH=54806 Change 54806 by jmallett@jmallett_oingo on 2004/06/13 09:47:51 Add check_address(), which is an NIHBSD compatible function to NetBSD's badvaddr(), but it doesn't do alignment. Most things can do that for themselves. At least ISTR badvaddr() checks int alignment. Use check_address() in HPC ala NetBSD. Next year, resolve to ramble less in commit/submit messages. Affected files ... .. //depot/projects/mips/sys/mips/include/trap.h#5 edit .. //depot/projects/mips/sys/mips/mips/trap.c#21 edit .. //depot/projects/mips/sys/mips/sgimips/hpc/hpc.c#3 edit Differences ... ==== //depot/projects/mips/sys/mips/include/trap.h#5 (text+ko) ==== @@ -50,6 +50,10 @@ #define TrVCED 31 #ifndef LOCORE /* XXX */ +struct trapframe; + +void trap(struct trapframe *, u_int, void *); +int check_address(void *); void platform_trap_enter(void); void platform_trap_exit(void); #endif ==== //depot/projects/mips/sys/mips/mips/trap.c#21 (text+ko) ==== @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -86,8 +87,9 @@ }; #define MAXTRAPID 31 -/* XXX belongs in a header some day? */ -void trap(struct trapframe *, u_int, void *); +/* Protected by critical sections, for checking for bad addresses. */ +static char *trap_addr; +static int trap_error; void trap(struct trapframe *tf, u_int cause, void *badvaddr) @@ -99,7 +101,7 @@ code = (cause & MIPS_CR_EXC_CODE) >> MIPS_CR_EXC_CODE_SHIFT; kernelmode = (tf->tf_regs[TF_SR] & MIPS_SR_KSU_USER) == 0; - + if (curthread != NULL) bcopy(tf, curthread->td_frame, sizeof *tf); @@ -115,6 +117,13 @@ /*platform_trap_exit();*/ platform_intr(tf); goto done; + case TrAdEL: + if (trap_error == -1) { + if (trap_addr == badvaddr) + trap_error = EINVAL; + goto done; + } + /* fall through */ default: /* Fatal! */ break; @@ -173,3 +182,25 @@ if (curthread) bcopy(curthread->td_frame, tf, sizeof *tf); } + +int +check_address(void *addr) +{ + vm_paddr_t pa; + char b; + int error; + + critical_enter(); + pa = pmap_kextract((vm_offset_t)addr); + trap_addr = (char *)MIPS_PHYS_TO_KSEG1(pa); + trap_error = -1; + b = *trap_addr; + trap_addr = NULL; + error = trap_error; + trap_error = 0; + critical_exit(); + + if (error == -1) + return (0); + return (error); +} ==== //depot/projects/mips/sys/mips/sgimips/hpc/hpc.c#3 (text+ko) ==== @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $P4: //depot/projects/mips/sys/mips/sgimips/hpc/hpc.c#2 $ + * $P4: //depot/projects/mips/sys/mips/sgimips/hpc/hpc.c#3 $ */ #include @@ -36,6 +36,7 @@ #include #include +#include #include static devclass_t hpc_devclass; @@ -92,6 +93,10 @@ "port", &port); if (error != 0) return (ENODEV); + /* XXX circumvents resource_long_value() */ + error = check_address((void *)MIPS_PHYS_TO_KSEG1(port)); + if (error != 0) + return (error); sc->sc_tag = device_space_tag; sc->sc_handle = port; return (0);