diff options
Diffstat (limited to 'sys/uvm/uvm_mmap.c')
-rw-r--r-- | sys/uvm/uvm_mmap.c | 117 |
1 files changed, 22 insertions, 95 deletions
diff --git a/sys/uvm/uvm_mmap.c b/sys/uvm/uvm_mmap.c index a8e6511b2b6..d6d3899102c 100644 --- a/sys/uvm/uvm_mmap.c +++ b/sys/uvm/uvm_mmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_mmap.c,v 1.93 2013/05/30 16:29:46 tedu Exp $ */ +/* $OpenBSD: uvm_mmap.c,v 1.94 2014/04/13 23:14:15 tedu Exp $ */ /* $NetBSD: uvm_mmap.c,v 1.49 2001/02/18 21:19:08 chs Exp $ */ /* @@ -100,7 +100,6 @@ * fd: fd of the file we want to map * off: offset within the file */ - int sys_mquery(struct proc *p, void *v, register_t *retval) { @@ -161,7 +160,6 @@ sys_mquery(struct proc *p, void *v, register_t *retval) /* * sys_mincore: determine if pages are in core or not. */ - /* ARGSUSED */ int sys_mincore(struct proc *p, void *v, register_t *retval) @@ -306,7 +304,6 @@ sys_mincore(struct proc *p, void *v, register_t *retval) * - if address isn't page aligned the mapping starts at trunc_page(addr) * and the return value is adjusted up by the page offset. */ - int sys_mmap(struct proc *p, void *v, register_t *retval) { @@ -332,10 +329,7 @@ sys_mmap(struct proc *p, void *v, register_t *retval) caddr_t handle; int error; - /* - * first, extract syscall args from the uap. - */ - + /* first, extract syscall args from the uap. */ addr = (vaddr_t) SCARG(uap, addr); size = (vsize_t) SCARG(uap, len); prot = SCARG(uap, prot); @@ -360,17 +354,11 @@ sys_mmap(struct proc *p, void *v, register_t *retval) if (size == 0) return (EINVAL); - /* - * align file position and save offset. adjust size. - */ + /* align file position and save offset. adjust size. */ ALIGN_ADDR(pos, size, pageoff); - /* - * now check (MAP_FIXED) or get (!MAP_FIXED) the "addr" - */ - + /* now check (MAP_FIXED) or get (!MAP_FIXED) the "addr" */ if (flags & MAP_FIXED) { - /* adjust address by the same amount as we did the offset */ addr -= pageoff; if (addr & PAGE_MASK) @@ -386,11 +374,8 @@ sys_mmap(struct proc *p, void *v, register_t *retval) } - /* - * check for file mappings (i.e. not anonymous) and verify file. - */ + /* check for file mappings (i.e. not anonymous) and verify file. */ if ((flags & MAP_ANON) == 0) { - if ((fp = fd_getfile(fdp, fd)) == NULL) return (EBADF); @@ -449,10 +434,7 @@ sys_mmap(struct proc *p, void *v, register_t *retval) flags = (flags & ~MAP_PRIVATE) | MAP_SHARED; } - /* - * now check protection - */ - + /* now check protection */ maxprot = VM_PROT_EXECUTE; /* check read access */ @@ -490,12 +472,8 @@ sys_mmap(struct proc *p, void *v, register_t *retval) maxprot |= VM_PROT_WRITE; } - /* - * set handle to vnode - */ - + /* set handle to vnode */ handle = (caddr_t)vp; - } else { /* MAP_ANON case */ /* * XXX What do we do about (MAP_SHARED|MAP_PRIVATE) == 0? @@ -505,7 +483,7 @@ sys_mmap(struct proc *p, void *v, register_t *retval) goto out; } - is_anon: /* label for SunOS style /dev/zero */ +is_anon: /* label for SunOS style /dev/zero */ handle = NULL; maxprot = VM_PROT_ALL; pos = 0; @@ -520,10 +498,7 @@ sys_mmap(struct proc *p, void *v, register_t *retval) } } - /* - * now let kernel internal function uvm_mmap do the work. - */ - + /* now let kernel internal function uvm_mmap do the work. */ error = uvm_mmap(&p->p_vmspace->vm_map, &addr, size, prot, maxprot, flags, handle, pos, p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur, p); @@ -554,10 +529,7 @@ sys_msync(struct proc *p, void *v, register_t *retval) vm_map_t map; int flags, uvmflags; - /* - * extract syscall args from the uap - */ - + /* extract syscall args from the uap */ addr = (vaddr_t)SCARG(uap, addr); size = (vsize_t)SCARG(uap, len); flags = SCARG(uap, flags); @@ -570,22 +542,15 @@ sys_msync(struct proc *p, void *v, register_t *retval) if ((flags & (MS_ASYNC | MS_SYNC)) == 0) flags |= MS_SYNC; - /* - * align the address to a page boundary, and adjust the size accordingly - */ + /* align the address to a page boundary, and adjust the size accordingly */ ALIGN_ADDR(addr, size, pageoff); if (addr > SIZE_MAX - size) return (EINVAL); /* disallow wrap-around. */ - /* - * get map - */ - + /* get map */ map = &p->p_vmspace->vm_map; - /* - * translate MS_ flags into PGO_ flags - */ + /* translate MS_ flags into PGO_ flags */ uvmflags = PGO_CLEANIT; if (flags & MS_INVALIDATE) uvmflags |= PGO_FREE; @@ -600,7 +565,6 @@ sys_msync(struct proc *p, void *v, register_t *retval) /* * sys_munmap: unmap a users memory */ - int sys_munmap(struct proc *p, void *v, register_t *retval) { @@ -614,16 +578,11 @@ sys_munmap(struct proc *p, void *v, register_t *retval) vaddr_t vm_min_address = VM_MIN_ADDRESS; struct uvm_map_deadq dead_entries; - /* - * get syscall args... - */ - + /* get syscall args... */ addr = (vaddr_t) SCARG(uap, addr); size = (vsize_t) SCARG(uap, len); - /* - * align the address to a page boundary, and adjust the size accordingly - */ + /* align address to a page boundary, and adjust size accordingly */ ALIGN_ADDR(addr, size, pageoff); /* @@ -645,15 +604,11 @@ sys_munmap(struct proc *p, void *v, register_t *retval) * interesting system call semantic: make sure entire range is * allocated before allowing an unmap. */ - if (!uvm_map_checkprot(map, addr, addr + size, VM_PROT_NONE)) { vm_map_unlock(map); return (EINVAL); } - /* - * doit! - */ TAILQ_INIT(&dead_entries); uvm_unmap_remove(map, addr, addr + size, &dead_entries, FALSE, TRUE); @@ -667,7 +622,6 @@ sys_munmap(struct proc *p, void *v, register_t *retval) /* * sys_mprotect: the mprotect system call */ - int sys_mprotect(struct proc *p, void *v, register_t *retval) { @@ -705,7 +659,6 @@ sys_mprotect(struct proc *p, void *v, register_t *retval) /* * sys_minherit: the minherit system call */ - int sys_minherit(struct proc *p, void *v, register_t *retval) { @@ -736,7 +689,6 @@ sys_minherit(struct proc *p, void *v, register_t *retval) /* * sys_madvise: give advice about memory usage. */ - /* ARGSUSED */ int sys_madvise(struct proc *p, void *v, register_t *retval) @@ -836,15 +788,11 @@ sys_mlock(struct proc *p, void *v, register_t *retval) vsize_t size, pageoff; int error; - /* - * extract syscall args from uap - */ + /* extract syscall args from uap */ addr = (vaddr_t)SCARG(uap, addr); size = (vsize_t)SCARG(uap, len); - /* - * align the address to a page boundary and adjust the size accordingly - */ + /* align address to a page boundary and adjust size accordingly */ ALIGN_ADDR(addr, size, pageoff); if (addr > SIZE_MAX - size) return (EINVAL); /* disallow wrap-around. */ @@ -881,16 +829,11 @@ sys_munlock(struct proc *p, void *v, register_t *retval) vsize_t size, pageoff; int error; - /* - * extract syscall args from uap - */ - + /* extract syscall args from uap */ addr = (vaddr_t)SCARG(uap, addr); size = (vsize_t)SCARG(uap, len); - /* - * align the address to a page boundary, and adjust the size accordingly - */ + /* align address to a page boundary, and adjust size accordingly */ ALIGN_ADDR(addr, size, pageoff); if (addr > SIZE_MAX - size) return (EINVAL); /* disallow wrap-around. */ @@ -908,7 +851,6 @@ sys_munlock(struct proc *p, void *v, register_t *retval) /* * sys_mlockall: lock all pages mapped into an address space. */ - int sys_mlockall(struct proc *p, void *v, register_t *retval) { @@ -938,7 +880,6 @@ sys_mlockall(struct proc *p, void *v, register_t *retval) /* * sys_munlockall: unlock all pages mapped into an address space. */ - int sys_munlockall(struct proc *p, void *v, register_t *retval) { @@ -955,7 +896,6 @@ sys_munlockall(struct proc *p, void *v, register_t *retval) * sysv shm uses "named anonymous memory") * - caller must page-align the file offset */ - int uvm_mmap(vm_map_t map, vaddr_t *addr, vsize_t size, vm_prot_t prot, vm_prot_t maxprot, int flags, caddr_t handle, voff_t foff, @@ -968,10 +908,7 @@ uvm_mmap(vm_map_t map, vaddr_t *addr, vsize_t size, vm_prot_t prot, uvm_flag_t uvmflag = 0; vsize_t align = 0; /* userland page size */ - /* - * check params - */ - + /* check params */ if (size == 0) return(0); if (foff & PAGE_MASK) @@ -983,7 +920,6 @@ uvm_mmap(vm_map_t map, vaddr_t *addr, vsize_t size, vm_prot_t prot, * for non-fixed mappings, round off the suggested address. * for fixed mappings, check alignment and zap old mappings. */ - if ((flags & MAP_FIXED) == 0) { *addr = round_page(*addr); /* round */ } else { @@ -999,7 +935,6 @@ uvm_mmap(vm_map_t map, vaddr_t *addr, vsize_t size, vm_prot_t prot, * handle anon vs. non-anon mappings. for non-anon mappings attach * to underlying vm object. */ - if (flags & MAP_ANON) { if ((flags & MAP_FIXED) == 0 && size >= __LDPGSZ) align = __LDPGSZ; @@ -1011,9 +946,7 @@ uvm_mmap(vm_map_t map, vaddr_t *addr, vsize_t size, vm_prot_t prot, else /* shared: create amap now */ uvmflag |= UVM_FLAG_OVERLAY; - } else { - vp = (struct vnode *) handle; /* get vnode */ if (vp->v_type != VCHR) { uobj = uvn_attach((void *) vp, (flags & MAP_SHARED) ? @@ -1078,10 +1011,7 @@ uvm_mmap(vm_map_t map, vaddr_t *addr, vsize_t size, vm_prot_t prot, uvmflag |= UVM_FLAG_COPYONW; } - /* - * set up mapping flags - */ - + /* set up mapping flags */ uvmflag = UVM_MAPFLAG(prot, maxprot, (flags & MAP_SHARED) ? UVM_INH_SHARE : UVM_INH_COPY, advice, uvmflag); @@ -1135,10 +1065,7 @@ uvm_mmap(vm_map_t map, vaddr_t *addr, vsize_t size, vm_prot_t prot, return (0); } - /* - * errors: first detach from the uobj, if any. - */ - + /* errors: first detach from the uobj, if any. */ if (uobj) uobj->pgops->pgo_detach(uobj); |