Source-Changes-HG archive

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

[src/trunk]: src/sys add copyin_pid(), to copyin from a different user addres...



details:   https://anonhg.NetBSD.org/src/rev/a865dc75afe6
branches:  trunk
changeset: 362139:a865dc75afe6
user:      chs <chs%NetBSD.org@localhost>
date:      Mon May 28 21:04:41 2018 +0000

description:
add copyin_pid(), to copyin from a different user address space.

diffstat:

 sys/kern/subr_copy.c |  31 +++++++++++++++++++++++++++++--
 sys/sys/systm.h      |   3 ++-
 2 files changed, 31 insertions(+), 3 deletions(-)

diffs (69 lines):

diff -r 7d6361d64c8b -r a865dc75afe6 sys/kern/subr_copy.c
--- a/sys/kern/subr_copy.c      Mon May 28 21:04:40 2018 +0000
+++ b/sys/kern/subr_copy.c      Mon May 28 21:04:41 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_copy.c,v 1.7 2016/05/25 17:43:58 christos Exp $   */
+/*     $NetBSD: subr_copy.c,v 1.8 2018/05/28 21:04:41 chs Exp $        */
 
 /*-
  * Copyright (c) 1997, 1998, 1999, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -79,7 +79,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_copy.c,v 1.7 2016/05/25 17:43:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_copy.c,v 1.8 2018/05/28 21:04:41 chs Exp $");
 
 #include <sys/param.h>
 #include <sys/fcntl.h>
@@ -300,6 +300,33 @@
 }
 
 /*
+ * Like copyin(), but operates on an arbitrary pid.
+ */
+int
+copyin_pid(pid_t pid, const void *uaddr, void *kaddr, size_t len)
+{
+       struct proc *p;
+       struct vmspace *vm;
+       int error;
+
+       mutex_enter(proc_lock);
+       p = proc_find(pid);
+       if (p == NULL) {
+               mutex_exit(proc_lock);
+               return ESRCH;
+       }
+       mutex_enter(p->p_lock);
+       proc_vmspace_getref(p, &vm);
+       mutex_exit(p->p_lock);
+       mutex_exit(proc_lock);
+
+       error = copyin_vmspace(vm, uaddr, kaddr, len);
+
+       uvmspace_free(vm);
+       return error;
+}
+
+/*
  * Like copyin(), except it operates on kernel addresses when the FKIOCTL
  * flag is passed in `ioctlflags' from the ioctl call.
  */
diff -r 7d6361d64c8b -r a865dc75afe6 sys/sys/systm.h
--- a/sys/sys/systm.h   Mon May 28 21:04:40 2018 +0000
+++ b/sys/sys/systm.h   Mon May 28 21:04:41 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: systm.h,v 1.275 2018/02/04 17:31:51 maxv Exp $ */
+/*     $NetBSD: systm.h,v 1.276 2018/05/28 21:04:41 chs Exp $  */
 
 /*-
  * Copyright (c) 1982, 1988, 1991, 1993
@@ -267,6 +267,7 @@
 
 int    copyin_proc(struct proc *, const void *, void *, size_t);
 int    copyout_proc(struct proc *, const void *, void *, size_t);
+int    copyin_pid(pid_t, const void *, void *, size_t);
 int    copyin_vmspace(struct vmspace *, const void *, void *, size_t);
 int    copyout_vmspace(struct vmspace *, const void *, void *, size_t);
 



Home | Main Index | Thread Index | Old Index