Date: Mon, 11 Apr 2011 08:25:26 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r220536 - in stable/8/sys: dev/ksyms kern sys Message-ID: <201104110825.p3B8PQnq078827@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Mon Apr 11 08:25:25 2011 New Revision: 220536 URL: http://svn.freebsd.org/changeset/base/220536 Log: MFC r220100: Promote ksyms_map() and ksyms_unmap() to general facility copyout_map() and copyout_unmap() interfaces. MFC r220101: Handle zero length in copyout_unmap(). MFC r220102: Trim white spaces, adjust style. MFC r220114: Fix the check for vm_map_remove() error. Modified: stable/8/sys/dev/ksyms/ksyms.c stable/8/sys/kern/kern_subr.c stable/8/sys/sys/uio.h Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) Modified: stable/8/sys/dev/ksyms/ksyms.c ============================================================================== --- stable/8/sys/dev/ksyms/ksyms.c Mon Apr 11 08:23:27 2011 (r220535) +++ stable/8/sys/dev/ksyms/ksyms.c Mon Apr 11 08:25:25 2011 (r220536) @@ -360,53 +360,6 @@ ksyms_snapshot(struct tsizes *ts, vm_off return (error); } -/* - * Map some anonymous memory in user space of size sz, rounded up to the page - * boundary. - */ -static int -ksyms_map(struct thread *td, vm_offset_t *addr, size_t sz) -{ - struct vmspace *vms = td->td_proc->p_vmspace; - int error; - vm_size_t size; - - - /* - * Map somewhere after heap in process memory. - */ - PROC_LOCK(td->td_proc); - *addr = round_page((vm_offset_t)vms->vm_daddr + - lim_max(td->td_proc, RLIMIT_DATA)); - PROC_UNLOCK(td->td_proc); - - /* round size up to page boundry */ - size = (vm_size_t) round_page(sz); - - error = vm_mmap(&vms->vm_map, addr, size, PROT_READ | PROT_WRITE, - VM_PROT_ALL, MAP_PRIVATE | MAP_ANON, OBJT_DEFAULT, NULL, 0); - - return (error); -} - -/* - * Unmap memory in user space. - */ -static int -ksyms_unmap(struct thread *td, vm_offset_t addr, size_t sz) -{ - vm_map_t map; - vm_size_t size; - - map = &td->td_proc->p_vmspace->vm_map; - size = (vm_size_t) round_page(sz); - - if (!vm_map_remove(map, addr, addr + size)) - return (EINVAL); - - return (0); -} - static void ksyms_cdevpriv_dtr(void *data) { @@ -475,7 +428,7 @@ ksyms_open(struct cdev *dev, int flags, total_elf_sz = sizeof(struct ksyms_hdr) + ts.ts_symsz + ts.ts_strsz; - error = ksyms_map(td, &(sc->sc_uaddr), + error = copyout_map(td, &(sc->sc_uaddr), (vm_size_t) total_elf_sz); if (error) break; @@ -488,7 +441,7 @@ ksyms_open(struct cdev *dev, int flags, } /* Snapshot failed, unmap the memory and try again */ - (void) ksyms_unmap(td, sc->sc_uaddr, sc->sc_usize); + (void) copyout_unmap(td, sc->sc_uaddr, sc->sc_usize); } failed: @@ -624,7 +577,7 @@ ksyms_close(struct cdev *dev, int flags return (error); /* Unmap the buffer from the process address space. */ - error = ksyms_unmap(td, sc->sc_uaddr, sc->sc_usize); + error = copyout_unmap(td, sc->sc_uaddr, sc->sc_usize); devfs_clear_cdevpriv(); Modified: stable/8/sys/kern/kern_subr.c ============================================================================== --- stable/8/sys/kern/kern_subr.c Mon Apr 11 08:23:27 2011 (r220535) +++ stable/8/sys/kern/kern_subr.c Mon Apr 11 08:25:25 2011 (r220536) @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include <sys/ktr.h> #include <sys/limits.h> #include <sys/lock.h> +#include <sys/mman.h> #include <sys/mutex.h> #include <sys/proc.h> #include <sys/malloc.h> @@ -54,6 +55,7 @@ __FBSDID("$FreeBSD$"); #include <sys/vnode.h> #include <vm/vm.h> +#include <vm/vm_extern.h> #include <vm/vm_page.h> #include <vm/vm_map.h> #ifdef ZERO_COPY_SOCKETS @@ -569,3 +571,54 @@ cloneuio(struct uio *uiop) bcopy(uiop->uio_iov, uio->uio_iov, iovlen); return (uio); } + +/* + * Map some anonymous memory in user space of size sz, rounded up to the page + * boundary. + */ +int +copyout_map(struct thread *td, vm_offset_t *addr, size_t sz) +{ + struct vmspace *vms; + int error; + vm_size_t size; + + vms = td->td_proc->p_vmspace; + + /* + * Map somewhere after heap in process memory. + */ + PROC_LOCK(td->td_proc); + *addr = round_page((vm_offset_t)vms->vm_daddr + + lim_max(td->td_proc, RLIMIT_DATA)); + PROC_UNLOCK(td->td_proc); + + /* round size up to page boundry */ + size = (vm_size_t)round_page(sz); + + error = vm_mmap(&vms->vm_map, addr, size, PROT_READ | PROT_WRITE, + VM_PROT_ALL, MAP_PRIVATE | MAP_ANON, OBJT_DEFAULT, NULL, 0); + + return (error); +} + +/* + * Unmap memory in user space. + */ +int +copyout_unmap(struct thread *td, vm_offset_t addr, size_t sz) +{ + vm_map_t map; + vm_size_t size; + + if (sz == 0) + return (0); + + map = &td->td_proc->p_vmspace->vm_map; + size = (vm_size_t)round_page(sz); + + if (vm_map_remove(map, addr, addr + size) != KERN_SUCCESS) + return (EINVAL); + + return (0); +} Modified: stable/8/sys/sys/uio.h ============================================================================== --- stable/8/sys/sys/uio.h Mon Apr 11 08:23:27 2011 (r220535) +++ stable/8/sys/sys/uio.h Mon Apr 11 08:25:25 2011 (r220536) @@ -94,6 +94,8 @@ int copyiniov(struct iovec *iovp, u_int int copyinstrfrom(const void * __restrict src, void * __restrict dst, size_t len, size_t * __restrict copied, int seg); int copyinuio(struct iovec *iovp, u_int iovcnt, struct uio **uiop); +int copyout_map(struct thread *td, vm_offset_t *addr, size_t sz); +int copyout_unmap(struct thread *td, vm_offset_t addr, size_t sz); void uio_yield(void); int uiomove(void *cp, int n, struct uio *uio); int uiomove_frombuf(void *buf, int buflen, struct uio *uio);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201104110825.p3B8PQnq078827>