Date: Sun, 13 Jun 2004 09:48:33 GMT From: Juli Mallett <jmallett@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 54806 for review Message-ID: <200406130948.i5D9mXFP090548@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <vm/vm.h> #include <vm/pmap.h> +#include <vm/vm_map.h> #include <machine/cpu.h> #include <machine/frame.h> @@ -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 <sys/cdefs.h> @@ -36,6 +36,7 @@ #include <sys/bus.h> #include <machine/bus.h> +#include <machine/trap.h> #include <platform/models.h> 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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200406130948.i5D9mXFP090548>