Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/mips/mips Check userland address and address aligne...



details:   https://anonhg.NetBSD.org/src/rev/c4849d94d7ab
branches:  trunk
changeset: 523157:c4849d94d7ab
user:      simonb <simonb%NetBSD.org@localhost>
date:      Tue Mar 05 15:46:51 2002 +0000

description:
Check userland address and address alignent as two separate checks.
Fix for when mips_reg_t is 64-bits.
ANSIfy.

diffstat:

 sys/arch/mips/mips/fpemu.c |  157 ++++++++++++++------------------------------
 1 files changed, 52 insertions(+), 105 deletions(-)

diffs (truncated from 353 to 300 lines):

diff -r d5e4f0e1edc6 -r c4849d94d7ab sys/arch/mips/mips/fpemu.c
--- a/sys/arch/mips/mips/fpemu.c        Tue Mar 05 15:44:40 2002 +0000
+++ b/sys/arch/mips/mips/fpemu.c        Tue Mar 05 15:46:51 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fpemu.c,v 1.9 2002/01/12 01:40:37 enami Exp $ */
+/*     $NetBSD: fpemu.c,v 1.10 2002/03/05 15:46:51 simonb Exp $ */
 
 /*
  * Copyright (c) 1999 Shuichiro URATA.  All rights reserved.
@@ -37,42 +37,37 @@
 #include <machine/cpu.h>
 #include <mips/reg.h>
 #include <mips/regnum.h>                       /* symbolic register indices */
+#include <mips/vmparam.h>                      /* for VM_MAX_ADDRESS */
 #include <mips/trap.h>
 
-static __inline void   send_sigsegv __P((u_int32_t vaddr, u_int32_t exccode,
-                                       struct frame *frame, u_int32_t cause));
-static __inline void   update_pc __P((struct frame *frame, u_int32_t cause));
+static __inline void   send_sigsegv(u_int32_t, u_int32_t, struct frame *,
+                           u_int32_t);
+static __inline void   update_pc(struct frame *, u_int32_t);
 
-void   MachEmulateLWC1 __P((u_int32_t inst, struct frame *frame,
-                               u_int32_t cause));
-void   MachEmulateLDC1 __P((u_int32_t inst, struct frame *frame,
-                               u_int32_t cause));
-void   MachEmulateSWC1 __P((u_int32_t inst, struct frame *frame,
-                               u_int32_t cause));
-void   MachEmulateSDC1 __P((u_int32_t inst, struct frame *frame,
-                               u_int32_t cause));
-void   bcemul_lb __P((u_int32_t inst, struct frame *frame, u_int32_t cause));
-void   bcemul_lbu __P((u_int32_t inst, struct frame *frame, u_int32_t cause));
-void   bcemul_lh __P((u_int32_t inst, struct frame *frame, u_int32_t cause));
-void   bcemul_lhu __P((u_int32_t inst, struct frame *frame, u_int32_t cause));
-void   bcemul_lw __P((u_int32_t inst, struct frame *frame, u_int32_t cause));
-void   bcemul_lwl __P((u_int32_t inst, struct frame *frame, u_int32_t cause));
-void   bcemul_lwr __P((u_int32_t inst, struct frame *frame, u_int32_t cause));
-void   bcemul_sb __P((u_int32_t inst, struct frame *frame, u_int32_t cause));
-void   bcemul_sh __P((u_int32_t inst, struct frame *frame, u_int32_t cause));
-void   bcemul_sw __P((u_int32_t inst, struct frame *frame, u_int32_t cause));
-void   bcemul_swl __P((u_int32_t inst, struct frame *frame, u_int32_t cause));
-void   bcemul_swr __P((u_int32_t inst, struct frame *frame, u_int32_t cause));
+void   MachEmulateLWC1(u_int32_t inst, struct frame *, u_int32_t);
+void   MachEmulateLDC1(u_int32_t inst, struct frame *, u_int32_t);
+void   MachEmulateSWC1(u_int32_t inst, struct frame *, u_int32_t);
+void   MachEmulateSDC1(u_int32_t inst, struct frame *, u_int32_t);
+void   bcemul_lb(u_int32_t inst, struct frame *, u_int32_t);
+void   bcemul_lbu(u_int32_t inst, struct frame *, u_int32_t);
+void   bcemul_lh(u_int32_t inst, struct frame *, u_int32_t);
+void   bcemul_lhu(u_int32_t inst, struct frame *, u_int32_t);
+void   bcemul_lw(u_int32_t inst, struct frame *, u_int32_t);
+void   bcemul_lwl(u_int32_t inst, struct frame *, u_int32_t);
+void   bcemul_lwr(u_int32_t inst, struct frame *, u_int32_t);
+void   bcemul_sb(u_int32_t inst, struct frame *, u_int32_t);
+void   bcemul_sh(u_int32_t inst, struct frame *, u_int32_t);
+void   bcemul_sw(u_int32_t inst, struct frame *, u_int32_t);
+void   bcemul_swl(u_int32_t inst, struct frame *, u_int32_t);
+void   bcemul_swr(u_int32_t inst, struct frame *f, u_int32_t);
 
-vaddr_t MachEmulateBranch __P((struct frame *, vaddr_t, unsigned, int));
+vaddr_t MachEmulateBranch(struct frame *, vaddr_t, unsigned, int);
 
 static __inline void
-send_sigsegv(vaddr, exccode, frame, cause)
-       u_int32_t vaddr;
-       u_int32_t exccode;
-       struct frame *frame;
-       u_int32_t cause;
+send_sigsegv(u_int32_t vaddr, u_int32_t exccode, struct frame *frame,
+    u_int32_t cause)
 {
+
        cause = (cause & 0xFFFFFF00) | (exccode << MIPS_CR_EXC_CODE_SHIFT);
 
        frame->f_regs[CAUSE] = cause;
@@ -81,9 +76,7 @@
 }
 
 static __inline void
-update_pc(frame, cause)
-       struct frame *frame;
-       u_int32_t cause;
+update_pc(struct frame *frame, u_int32_t cause)
 {
 
        if (cause & MIPS_CR_BR_DELAY)
@@ -96,10 +89,7 @@
 #define LWSWC1_MAXLOOP 12
 
 void
-MachEmulateLWC1(inst, frame, cause)
-       u_int32_t inst;
-       struct frame *frame;
-       u_int32_t cause;
+MachEmulateLWC1(u_int32_t inst, struct frame *frame, u_int32_t cause)
 {
        u_int32_t       vaddr;
        int16_t         offset;
@@ -111,7 +101,7 @@
        vaddr = frame->f_regs[(inst>>21)&0x1F] + offset;
 
        /* segment and alignment check */
-       if (vaddr & 0x80000003) {
+       if (vaddr > VM_MAX_ADDRESS || vaddr & 0x3) {
                send_sigsegv(vaddr, T_ADDR_ERR_LD, frame, cause);
                return;
        }
@@ -133,7 +123,8 @@
                if (mips_btop(frame->f_regs[PC]) != mips_btop(pc))
                        return;
 
-               inst = fuiword((u_int32_t *)frame->f_regs[PC]);
+               vaddr = frame->f_regs[PC];      /* XXX truncates to 32 bits */
+               inst = fuiword((u_int32_t *)vaddr);
                if (((InstFmt)inst).FRType.op != OP_LWC1)
                        return;
 
@@ -141,7 +132,7 @@
                vaddr = frame->f_regs[(inst>>21)&0x1F] + offset;
 
                /* segment and alignment check */
-               if (vaddr & 0x80000003) {
+               if (vaddr > VM_MAX_ADDRESS || vaddr & 0x3) {
                        send_sigsegv(vaddr, T_ADDR_ERR_LD, frame, cause);
                        return;
                }
@@ -159,10 +150,7 @@
 }
 
 void
-MachEmulateLDC1(inst, frame, cause)
-       u_int32_t inst;
-       struct frame *frame;
-       u_int32_t cause;
+MachEmulateLDC1(u_int32_t inst, struct frame *frame, u_int32_t cause)
 {
        u_int32_t       vaddr;
        int16_t         offset;
@@ -188,10 +176,7 @@
 }
 
 void
-MachEmulateSWC1(inst, frame, cause)
-       u_int32_t inst;
-       struct frame *frame;
-       u_int32_t cause;
+MachEmulateSWC1(u_int32_t inst, struct frame *frame, u_int32_t cause)
 {
        u_int32_t       vaddr;
        int16_t         offset;
@@ -203,7 +188,7 @@
        vaddr = frame->f_regs[(inst>>21)&0x1F] + offset;
 
        /* segment and alignment check */
-       if (vaddr & 0x80000003) {
+       if (vaddr > VM_MAX_ADDRESS || vaddr & 0x3) {
                send_sigsegv(vaddr, T_ADDR_ERR_ST, frame, cause);
                return;
        }
@@ -225,7 +210,8 @@
                if (mips_btop(frame->f_regs[PC]) != mips_btop(pc))
                        return;
 
-               inst = fuiword((u_int32_t *)frame->f_regs[PC]);
+               vaddr = frame->f_regs[PC];      /* XXX truncates to 32 bits */
+               inst = fuiword((u_int32_t *)vaddr);
                if (((InstFmt)inst).FRType.op != OP_SWC1)
                        return;
 
@@ -233,7 +219,7 @@
                vaddr = frame->f_regs[(inst>>21)&0x1F] + offset;
 
                /* segment and alignment check */
-               if (vaddr & 0x80000003) {
+               if (vaddr > VM_MAX_ADDRESS || vaddr & 0x3) {
                        send_sigsegv(vaddr, T_ADDR_ERR_ST, frame, cause);
                        return;
                }
@@ -251,10 +237,7 @@
 }
 
 void
-MachEmulateSDC1(inst, frame, cause)
-       u_int32_t inst;
-       struct frame *frame;
-       u_int32_t cause;
+MachEmulateSDC1(u_int32_t inst, struct frame *frame, u_int32_t cause)
 {
        u_int32_t       vaddr;
        int16_t         offset;
@@ -280,10 +263,7 @@
 }
 
 void
-bcemul_lb(inst, frame, cause)
-       u_int32_t inst;
-       struct frame *frame;
-       u_int32_t cause;
+bcemul_lb(u_int32_t inst, struct frame *frame, u_int32_t cause)
 {
        u_int32_t       vaddr;
        int16_t         offset;
@@ -309,10 +289,7 @@
 }
 
 void
-bcemul_lbu(inst, frame, cause)
-       u_int32_t inst;
-       struct frame *frame;
-       u_int32_t cause;
+bcemul_lbu(u_int32_t inst, struct frame *frame, u_int32_t cause)
 {
        u_int32_t       vaddr;
        int16_t         offset;
@@ -338,10 +315,7 @@
 }
 
 void
-bcemul_lh(inst, frame, cause)
-       u_int32_t inst;
-       struct frame *frame;
-       u_int32_t cause;
+bcemul_lh(u_int32_t inst, struct frame *frame, u_int32_t cause)
 {
        u_int32_t       vaddr;
        int16_t         offset;
@@ -367,10 +341,7 @@
 }
 
 void
-bcemul_lhu(inst, frame, cause)
-       u_int32_t inst;
-       struct frame *frame;
-       u_int32_t cause;
+bcemul_lhu(u_int32_t inst, struct frame *frame, u_int32_t cause)
 {
        u_int32_t       vaddr;
        int16_t         offset;
@@ -396,10 +367,7 @@
 }
 
 void
-bcemul_lw(inst, frame, cause)
-       u_int32_t inst;
-       struct frame *frame;
-       u_int32_t cause;
+bcemul_lw(u_int32_t inst, struct frame *frame, u_int32_t cause)
 {
        u_int32_t       vaddr;
        int16_t         offset;
@@ -408,7 +376,7 @@
        vaddr = frame->f_regs[(inst>>21)&0x1F] + offset;
 
        /* segment and alignment check */
-       if (vaddr & 0x80000003) {
+       if (vaddr > VM_MAX_ADDRESS || vaddr & 0x3) {
                send_sigsegv(vaddr, T_ADDR_ERR_LD, frame, cause);
                return;
        }
@@ -422,10 +390,7 @@
 }
 
 void
-bcemul_lwl(inst, frame, cause)
-       u_int32_t inst;
-       struct frame *frame;
-       u_int32_t cause;
+bcemul_lwl(u_int32_t inst, struct frame *frame, u_int32_t cause)
 {
        u_int32_t       vaddr, a, x, shift;
        int16_t         offset;
@@ -457,10 +422,7 @@
 }
 
 void
-bcemul_lwr(inst, frame, cause)
-       u_int32_t inst;
-       struct frame *frame;
-       u_int32_t cause;
+bcemul_lwr(u_int32_t inst, struct frame *frame, u_int32_t cause)
 {
        u_int32_t       vaddr, a, x, shift;
        int16_t         offset;
@@ -492,10 +454,7 @@
 }
 
 void
-bcemul_sb(inst, frame, cause)
-       u_int32_t inst;
-       struct frame *frame;
-       u_int32_t cause;
+bcemul_sb(u_int32_t inst, struct frame *frame, u_int32_t cause)
 {
        u_int32_t       vaddr;
        int16_t         offset;
@@ -518,10 +477,7 @@
 }
 
 void



Home | Main Index | Thread Index | Old Index