From 711fbd17ecb5c73100aeb4991e158efcd50b8e7b Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Mon, 7 Dec 2015 21:33:15 +0000 Subject: Add helper functions proc_readmem() and proc_writemem(). These helper functions can be used to read in or write a buffer from or to an arbitrary process' address space. Without them, this can only be done using proc_rwmem(), which requires the caller to fill out a uio. This is onerous and results in code duplication; the new functions provide a simpler interface which is sufficient for most existing callers of proc_rwmem(). This change also adds a manual page for proc_rwmem() and the new functions. Reviewed by: jhb, kib Differential Revision: https://reviews.freebsd.org/D4245 --- .../opensolaris/uts/powerpc/dtrace/fasttrap_isa.c | 40 +++++++--------------- 1 file changed, 13 insertions(+), 27 deletions(-) (limited to 'sys/cddl/contrib/opensolaris/uts/powerpc') diff --git a/sys/cddl/contrib/opensolaris/uts/powerpc/dtrace/fasttrap_isa.c b/sys/cddl/contrib/opensolaris/uts/powerpc/dtrace/fasttrap_isa.c index ea01d5f44616..8e4c647199ce 100644 --- a/sys/cddl/contrib/opensolaris/uts/powerpc/dtrace/fasttrap_isa.c +++ b/sys/cddl/contrib/opensolaris/uts/powerpc/dtrace/fasttrap_isa.c @@ -43,44 +43,30 @@ #define OP_RA(x) (((x) & 0x001F0000) >> 16) #define OP_RB(x) (((x) & 0x0000F100) >> 11) - static int -proc_ops(int op, proc_t *p, void *kaddr, off_t uaddr, size_t len) +uread(proc_t *p, void *kaddr, size_t len, uintptr_t uaddr) { - struct iovec iov; - struct uio uio; - - iov.iov_base = kaddr; - iov.iov_len = len; - uio.uio_offset = uaddr; - uio.uio_iov = &iov; - uio.uio_resid = len; - uio.uio_iovcnt = 1; - uio.uio_segflg = UIO_SYSSPACE; - uio.uio_td = curthread; - uio.uio_rw = op; + ssize_t n; + PHOLD(p); - if (proc_rwmem(p, &uio) != 0) { - PRELE(p); - return (-1); - } + n = proc_readmem(curthread, p, uaddr, kaddr, len); PRELE(p); - + if (n <= 0 || n < len) + return (ENOMEM); return (0); } -static int -uread(proc_t *p, void *kaddr, size_t len, uintptr_t uaddr) -{ - - return (proc_ops(UIO_READ, p, kaddr, uaddr, len)); -} - static int uwrite(proc_t *p, void *kaddr, size_t len, uintptr_t uaddr) { + ssize_t n; - return (proc_ops(UIO_WRITE, p, kaddr, uaddr, len)); + PHOLD(p); + n = proc_writemem(curthread, p, uaddr, kaddr, len); + PRELE(p); + if (n <= 0 || n < len) + return (ENOMEM); + return (0); } int -- cgit v1.2.3