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

This commit is contained in:
chs 2018-05-28 21:04:41 +00:00
parent d5abe492a8
commit 5131193704
2 changed files with 31 additions and 3 deletions

View File

@ -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>
@ -299,6 +299,33 @@ copyout_proc(struct proc *p, const void *kaddr, void *uaddr, size_t len)
return error;
}
/*
* 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.

View File

@ -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 @@ typedef int (*copyout_t)(const void *, void *, size_t);
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);