Source-Changes-HG archive

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

[src/trunk]: src * Add copyin_proc() and copyout_proc(), which are like copyi...



details:   https://anonhg.NetBSD.org/src/rev/62d1dd2211ca
branches:  trunk
changeset: 534198:62d1dd2211ca
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Jul 20 03:58:24 2002 +0000

description:
* Add copyin_proc() and copyout_proc(), which are like copyin() and
  copyout(), except they can operate on any process, not just curproc.
* Use this in uiomove() to allow UIO_USERSPACE to non-curproc.

diffstat:

 distrib/sets/lists/comp/mi |   6 ++-
 share/man/man9/Makefile    |   5 +-
 share/man/man9/copy.9      |  33 +++++++++++----
 sys/kern/kern_subr.c       |  95 ++++++++++++++++++++++++++++++++++++++++-----
 sys/sys/systm.h            |   5 +-
 5 files changed, 120 insertions(+), 24 deletions(-)

diffs (truncated from 301 to 300 lines):

diff -r 680099d43486 -r 62d1dd2211ca distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Sat Jul 20 03:09:03 2002 +0000
+++ b/distrib/sets/lists/comp/mi        Sat Jul 20 03:58:24 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.458 2002/07/18 09:35:48 agc Exp $
+#      $NetBSD: mi,v 1.459 2002/07/20 03:58:27 thorpej Exp $
 ./sys                          comp-sysutil-root
 ./usr/bin/addr2line            comp-debug-bin
 ./usr/bin/ar                   comp-util-bin
@@ -3055,8 +3055,10 @@
 ./usr/share/man/cat9/cons.0            comp-sys-catman
 ./usr/share/man/cat9/copy.0            comp-sys-catman
 ./usr/share/man/cat9/copyin.0          comp-sys-catman
+./usr/share/man/cat9/copyin_proc.0             comp-sys-catman
 ./usr/share/man/cat9/copyinstr.0               comp-sys-catman
 ./usr/share/man/cat9/copyout.0         comp-sys-catman
+./usr/share/man/cat9/copyout_proc.0            comp-sys-catman
 ./usr/share/man/cat9/copyoutstr.0              comp-sys-catman
 ./usr/share/man/cat9/copystr.0         comp-sys-catman
 ./usr/share/man/cat9/cpu_configure.0   comp-sys-catman
@@ -5621,8 +5623,10 @@
 ./usr/share/man/man9/cons.9            comp-sys-man
 ./usr/share/man/man9/copy.9            comp-sys-man
 ./usr/share/man/man9/copyin.9          comp-sys-man
+./usr/share/man/man9/copyin_proc.9             comp-sys-man
 ./usr/share/man/man9/copyinstr.9               comp-sys-man
 ./usr/share/man/man9/copyout.9         comp-sys-man
+./usr/share/man/man9/copyout_proc.9            comp-sys-man
 ./usr/share/man/man9/copyoutstr.9              comp-sys-man
 ./usr/share/man/man9/copystr.9         comp-sys-man
 ./usr/share/man/man9/cpu_configure.9   comp-sys-man
diff -r 680099d43486 -r 62d1dd2211ca share/man/man9/Makefile
--- a/share/man/man9/Makefile   Sat Jul 20 03:09:03 2002 +0000
+++ b/share/man/man9/Makefile   Sat Jul 20 03:58:24 2002 +0000
@@ -1,4 +1,4 @@
-#       $NetBSD: Makefile,v 1.116 2002/07/17 15:53:50 hannken Exp $
+#       $NetBSD: Makefile,v 1.117 2002/07/20 03:58:26 thorpej Exp $
 
 #      Makefile for section 9 (kernel function and variable) manual pages.
 
@@ -111,7 +111,8 @@
 MLINKS+=cons.9 cnbell.9 cons.9 cngetc.9 cons.9 cngetsn.9 cons.9 cnpollc.9 \
        cons.9 cnputc.9
 MLINKS+=copy.9 copyin.9 copy.9 copyout.9 copy.9 copystr.9 \
-       copy.9 copyinstr.9 copy.9 copyoutstr.9
+       copy.9 copyinstr.9 copy.9 copyoutstr.9 \
+       copy.9 copyin_proc.9 copy.9 copyout_proc.9
 MLINKS+=cpu_dumpconf.9 cpu_dump.9 cpu_dumpconf.9 cpu_dumpsize.9 \
        cpu_dumpconf.9 dumpsys.9
 MLINKS+=cpu_fork.9 child_return.9 cpu_fork.9 proc_trampoline.9
diff -r 680099d43486 -r 62d1dd2211ca share/man/man9/copy.9
--- a/share/man/man9/copy.9     Sat Jul 20 03:09:03 2002 +0000
+++ b/share/man/man9/copy.9     Sat Jul 20 03:58:24 2002 +0000
@@ -1,6 +1,6 @@
-.\"    $NetBSD: copy.9,v 1.11 2002/02/13 08:18:39 ross Exp $
+.\"    $NetBSD: copy.9,v 1.12 2002/07/20 03:58:26 thorpej Exp $
 .\"
-.\" Copyright (c) 1996 Jason R. Thorpe.
+.\" Copyright (c) 1996, 2002 Jason R. Thorpe.
 .\" All rights reserved.
 .\"
 .\" This code is derived from software contributed by Kenneth Stailey.
@@ -32,7 +32,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd February 22, 1998
+.Dd July 19, 2002
 .Dt COPY 9
 .Os
 .Sh NAME
@@ -56,6 +56,10 @@
 .Fn copyinstr "const void *uaddr" "void *kaddr" "size_t len" "size_t *done"
 .Ft int
 .Fn copyoutstr "const void *kaddr" "void *uaddr" "size_t len" "size_t *done"
+.Ft int
+.Fn copyin_proc "struct proc *p" "const void *uaddr" "void *kaddr" "size_t len"
+.Ft int
+.Fn copyout_proc "struct proc *p" "const void *kaddr" "void *uaddr" "size_t len"
 .Sh DESCRIPTION
 The
 .Nm
@@ -67,13 +71,13 @@
 The
 .Nm
 routines provide the following functionality:
-.Bl -tag -width "copyoutstr()"
+.Bl -tag -width "copyout_proc()"
 .It Fn copyin
 Copies
 .Fa len
 bytes of data from the user-space address
 .Fa uaddr
-to the kernel-space address
+in the current process to the kernel-space address
 .Fa kaddr .
 .It Fn copyout
 Copies
@@ -81,7 +85,8 @@
 bytes of data from the kernel-space address
 .Fa kaddr
 to the user-space address
-.Fa uaddr .
+.Fa uaddr
+in the current process.
 .It Fn copystr
 Copies a NUL-terminated string, at most
 .Fa len
@@ -100,7 +105,7 @@
 .Fa len
 bytes long, from user-space address
 .Fa uaddr
-to kernel-space address
+in the current process to kernel-space address
 .Fa kaddr .
 If the
 .Fa done
@@ -114,13 +119,23 @@
 bytes long, from kernel-space address
 .Fa kaddr
 to user-space address
-.Fa uaddr .
-If the
+.Fa uaddr
+in the current process.  If the
 .Fa done
 argument is non-NULL,
 the number of bytes actually copied, including the terminating
 NUL, is returned in
 .Fa *done .
+.It Fn copyin_proc
+Like
+.Fn copyin ,
+except it operates on the address space of the process
+.Fa p .
+.It Fn copyout_proc
+Like
+.Fn copyout ,
+except it operates on the address space of the process
+.Fa p .
 .El
 .Sh RETURN VALUES
 The
diff -r 680099d43486 -r 62d1dd2211ca sys/kern/kern_subr.c
--- a/sys/kern/kern_subr.c      Sat Jul 20 03:09:03 2002 +0000
+++ b/sys/kern/kern_subr.c      Sat Jul 20 03:58:24 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_subr.c,v 1.81 2002/06/17 16:22:51 christos Exp $  */
+/*     $NetBSD: kern_subr.c,v 1.82 2002/07/20 03:58:24 thorpej Exp $   */
 
 /*-
  * Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.81 2002/06/17 16:22:51 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.82 2002/07/20 03:58:24 thorpej Exp $");
 
 #include "opt_ddb.h"
 #include "opt_md.h"
@@ -111,6 +111,8 @@
 #include <sys/systrace.h>
 #include <sys/ktrace.h>
 
+#include <uvm/uvm_extern.h>
+
 #include <dev/cons.h>
 
 #include <net/if.h>
@@ -152,8 +154,6 @@
 #ifdef DIAGNOSTIC
        if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE)
                panic("uiomove: mode");
-       if (uio->uio_segflg == UIO_USERSPACE && p != curproc)
-               panic("uiomove proc");
 #endif
        while (n > 0 && uio->uio_resid) {
                iov = uio->uio_iov;
@@ -168,15 +168,22 @@
                switch (uio->uio_segflg) {
 
                case UIO_USERSPACE:
-                       KDASSERT(p->p_cpu != NULL);
-                       KDASSERT(p->p_cpu == curcpu());
-                       if (p->p_cpu->ci_schedstate.spc_flags &
+                       if (curproc->p_cpu->ci_schedstate.spc_flags &
                            SPCF_SHOULDYIELD)
                                preempt(NULL);
-                       if (uio->uio_rw == UIO_READ)
-                               error = copyout(cp, iov->iov_base, cnt);
-                       else
-                               error = copyin(iov->iov_base, cp, cnt);
+                       if (__predict_true(p == curproc)) {
+                               if (uio->uio_rw == UIO_READ)
+                                       error = copyout(cp, iov->iov_base, cnt);
+                               else
+                                       error = copyin(iov->iov_base, cp, cnt);
+                       } else {
+                               if (uio->uio_rw == UIO_READ)
+                                       error = copyout_proc(p, cp,
+                                           iov->iov_base, cnt);
+                               else
+                                       error = copyin_proc(p, iov->iov_base,
+                                           cp, cnt);
+                       }
                        if (error)
                                return (error);
                        break;
@@ -240,6 +247,72 @@
 }
 
 /*
+ * Like copyin(), but operates on an arbitrary process.
+ */
+int
+copyin_proc(struct proc *p, const void *uaddr, void *kaddr, size_t len)
+{
+       struct iovec iov;
+       struct uio uio;
+       int error;
+
+       if (len == 0)
+               return (0);
+
+       iov.iov_base = kaddr;
+       iov.iov_len = len;
+       uio.uio_iov = &iov;
+       uio.uio_iovcnt = 1;
+       uio.uio_offset = (off_t)(intptr_t)uaddr;
+       uio.uio_resid = len;
+       uio.uio_segflg = UIO_SYSSPACE;
+       uio.uio_rw = UIO_READ;
+       uio.uio_procp = NULL;
+
+       /* XXXCDC: how should locking work here? */
+       if ((p->p_flag & P_WEXIT) || (p->p_vmspace->vm_refcnt < 1))
+               return (EFAULT);
+       p->p_vmspace->vm_refcnt++;      /* XXX */
+       error = uvm_io(&p->p_vmspace->vm_map, &uio);
+       uvmspace_free(p->p_vmspace);
+
+       return (error);
+}
+
+/*
+ * Like copyout(), but operates on an arbitrary process.
+ */
+int
+copyout_proc(struct proc *p, const void *kaddr, void *uaddr, size_t len)
+{
+       struct iovec iov;
+       struct uio uio;
+       int error;
+
+       if (len == 0)
+               return (0);
+
+       iov.iov_base = (void *) kaddr;  /* XXX cast away const */
+       iov.iov_len = len;
+       uio.uio_iov = &iov;
+       uio.uio_iovcnt = 1;
+       uio.uio_offset = (off_t)(intptr_t)uaddr;
+       uio.uio_resid = len;
+       uio.uio_segflg = UIO_SYSSPACE;
+       uio.uio_rw = UIO_WRITE;
+       uio.uio_procp = NULL;
+
+       /* XXXCDC: how should locking work here? */
+       if ((p->p_flag & P_WEXIT) || (p->p_vmspace->vm_refcnt < 1))
+               return (EFAULT);
+       p->p_vmspace->vm_refcnt++;      /* XXX */
+       error = uvm_io(&p->p_vmspace->vm_map, &uio);
+       uvmspace_free(p->p_vmspace);
+
+       return (error);
+}
+
+/*
  * General routine to allocate a hash table.
  * Allocate enough memory to hold at least `elements' list-head pointers.
  * Return a pointer to the allocated space and set *hashmask to a pattern
diff -r 680099d43486 -r 62d1dd2211ca sys/sys/systm.h
--- a/sys/sys/systm.h   Sat Jul 20 03:09:03 2002 +0000
+++ b/sys/sys/systm.h   Sat Jul 20 03:58:24 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: systm.h,v 1.145 2002/06/17 16:23:58 christos Exp $     */
+/*     $NetBSD: systm.h,v 1.146 2002/07/20 03:58:25 thorpej Exp $      */
 
 /*-
  * Copyright (c) 1982, 1988, 1991, 1993
@@ -224,6 +224,9 @@
 int    copyin __P((const void *, void *, size_t));
 int    copyout __P((const void *, void *, size_t));
 
+int    copyin_proc __P((struct proc *, const void *, void *, size_t));
+int    copyout_proc __P((struct proc *, const void *, void *, size_t));
+
 int    subyte __P((void *, int));
 int    suibyte __P((void *, int));



Home | Main Index | Thread Index | Old Index