Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/powerpc reimplement copy{in, out}str() similarly to ...



details:   https://anonhg.NetBSD.org/src/rev/962fb36853f3
branches:  trunk
changeset: 534391:962fb36853f3
user:      chs <chs%NetBSD.org@localhost>
date:      Wed Jul 24 04:59:32 2002 +0000

description:
reimplement copy{in,out}str() similarly to copy{in,out}()
(instead of the old way of calling [fs]ubyte() in a loop).

diffstat:

 sys/arch/powerpc/conf/files.powerpc   |   4 +-
 sys/arch/powerpc/powerpc/copyinstr.c  |  68 -------------------------
 sys/arch/powerpc/powerpc/copyoutstr.c |  68 -------------------------
 sys/arch/powerpc/powerpc/trap.c       |  93 ++++++++++++++++++++++++++++++++++-
 4 files changed, 93 insertions(+), 140 deletions(-)

diffs (266 lines):

diff -r 0f2efad4f899 -r 962fb36853f3 sys/arch/powerpc/conf/files.powerpc
--- a/sys/arch/powerpc/conf/files.powerpc       Wed Jul 24 04:51:08 2002 +0000
+++ b/sys/arch/powerpc/conf/files.powerpc       Wed Jul 24 04:59:32 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.powerpc,v 1.33 2002/07/17 03:11:07 matt Exp $
+#      $NetBSD: files.powerpc,v 1.34 2002/07/24 04:59:32 chs Exp $
 
 defflag        opt_altivec.h   ALTIVEC K_ALTIVEC
 defflag        opt_openpic.h   OPENPIC OPENPIC_SERIAL_MODE
@@ -48,8 +48,6 @@
 file   arch/powerpc/powerpc/fpu.c                      ppc_mpc6xx
 file   arch/powerpc/powerpc/pmap.c                     ppc_mpc6xx & oldpmap
 file   arch/powerpc/powerpc/trap.c                     ppc_mpc6xx
-file   arch/powerpc/powerpc/copyinstr.c                ppc_mpc6xx
-file   arch/powerpc/powerpc/copyoutstr.c               ppc_mpc6xx
 
 # Binary compatibility with previous NetBSD releases (COMPAT_XX)
 file   arch/powerpc/powerpc/compat_13_machdep.c        compat_13
diff -r 0f2efad4f899 -r 962fb36853f3 sys/arch/powerpc/powerpc/copyinstr.c
--- a/sys/arch/powerpc/powerpc/copyinstr.c      Wed Jul 24 04:51:08 2002 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/*     $NetBSD: copyinstr.c,v 1.3 2000/02/19 23:29:16 chs Exp $        */
-
-/*-
- * Copyright (C) 1995 Wolfgang Solfrank.
- * Copyright (C) 1995 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include <sys/param.h>
-#include <sys/errno.h>
-#include <sys/systm.h>
-
-/*
- * Emulate copyinstr.
- */
-int
-copyinstr(udaddr, kaddr, len, done)
-       const void *udaddr;
-       void *kaddr;
-       size_t len;
-       size_t *done;
-{
-       const u_char *up = udaddr;
-       u_char *kp = kaddr;
-       size_t l;
-       int c, rv;
-
-       rv = ENAMETOOLONG;
-       for (l = 0; len-- > 0; l++) {
-               if ((c = fubyte(up++)) < 0) {
-                       rv = EFAULT;
-                       break;
-               }
-               if (!(*kp++ = c)) {
-                       l++;
-                       rv = 0;
-                       break;
-               }
-       }
-       if (done != NULL) {
-               *done = l;
-       }
-       return rv;
-}
diff -r 0f2efad4f899 -r 962fb36853f3 sys/arch/powerpc/powerpc/copyoutstr.c
--- a/sys/arch/powerpc/powerpc/copyoutstr.c     Wed Jul 24 04:51:08 2002 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/*     $NetBSD: copyoutstr.c,v 1.3 2000/02/19 23:29:17 chs Exp $       */
-
-/*-
- * Copyright (C) 1995 Wolfgang Solfrank.
- * Copyright (C) 1995 TooLs GmbH.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include <sys/param.h>
-#include <sys/errno.h>
-#include <sys/systm.h>
-
-/*
- * Emulate copyoutstr.
- */
-int
-copyoutstr(kaddr, udaddr, len, done)
-       const void *kaddr;
-       void *udaddr;
-       size_t len;
-       size_t *done;
-{
-       const u_char *kp = kaddr;
-       u_char *up = udaddr;
-       size_t l;
-       int rv;
-
-       rv = ENAMETOOLONG;
-       for (l = 0; len-- > 0; l++) {
-               if (subyte(up++, *kp) < 0) {
-                       rv = EFAULT;
-                       break;
-               }
-               if (!*kp++) {
-                       l++;
-                       rv = 0;
-                       break;
-               }
-       }
-       if (done != NULL) {
-               *done = l;
-       }
-       return rv;
-}
diff -r 0f2efad4f899 -r 962fb36853f3 sys/arch/powerpc/powerpc/trap.c
--- a/sys/arch/powerpc/powerpc/trap.c   Wed Jul 24 04:51:08 2002 +0000
+++ b/sys/arch/powerpc/powerpc/trap.c   Wed Jul 24 04:59:32 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.63 2002/07/05 18:45:22 matt Exp $   */
+/*     $NetBSD: trap.c,v 1.64 2002/07/24 04:59:33 chs Exp $    */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -606,3 +606,94 @@
 
        return -1;
 }
+
+int
+copyinstr(udaddr, kaddr, len, done)
+       const void *udaddr;
+       void *kaddr;
+       size_t len;
+       size_t *done;
+{
+       const char *up = udaddr;
+       char *kp = kaddr;
+       char *p;
+       size_t l, ls, d;
+       faultbuf env;
+       int rv;
+
+       if ((rv = setfault(env)) != 0) {
+               curpcb->pcb_onfault = 0;
+               return rv;
+       }
+       d = 0;
+       while (len > 0) {
+               p = (char *)USER_ADDR + ((uintptr_t)up & ~SEGMENT_MASK);
+               l = ((char *)USER_ADDR + SEGMENT_LENGTH) - p;
+               if (l > len)
+                       l = len;
+               setusr(curpcb->pcb_pm->pm_sr[(uintptr_t)up >> ADDR_SR_SHFT]);
+               for (ls = l; ls > 0; ls--) {
+                       if ((*kp++ = *p++) == 0) {
+                               d += l - ls + 1;
+                               rv = 0;
+                               goto out;
+                       }
+               }
+               d += l;
+               len -= l;
+       }
+       rv = ENAMETOOLONG;
+
+ out:
+       curpcb->pcb_onfault = 0;
+       if (done != NULL) {
+               *done = d;
+       }
+       return rv;
+}
+
+
+int
+copyoutstr(kaddr, udaddr, len, done)
+       const void *kaddr;
+       void *udaddr;
+       size_t len;
+       size_t *done;
+{
+       const char *kp = kaddr;
+       char *up = udaddr;
+       char *p;
+       int rv;
+       size_t l, ls, d;
+       faultbuf env;
+
+       if ((rv = setfault(env)) != 0) {
+               curpcb->pcb_onfault = 0;
+               return rv;
+       }
+       d = 0;
+       while (len > 0) {
+               p = (char *)USER_ADDR + ((uintptr_t)up & ~SEGMENT_MASK);
+               l = ((char *)USER_ADDR + SEGMENT_LENGTH) - p;
+               if (l > len)
+                       l = len;
+               setusr(curpcb->pcb_pm->pm_sr[(uintptr_t)up >> ADDR_SR_SHFT]);
+               for (ls = l; ls > 0; ls--) {
+                       if ((*p++ = *kp++) == 0) {
+                               d += l - ls + 1;
+                               rv = 0;
+                               goto out;
+                       }
+               }
+               d += l;
+               len -= l;
+       }
+       rv = ENAMETOOLONG;
+
+ out:
+       curpcb->pcb_onfault = 0;
+       if (done != NULL) {
+               *done = d;
+       }
+       return rv;
+}



Home | Main Index | Thread Index | Old Index