BSD 4_4 release
[unix-history] / usr / src / sys / vm / vm_mmap.c
index 90dfc58..060aeb1 100644 (file)
@@ -1,17 +1,43 @@
 /*
  * Copyright (c) 1988 University of Utah.
 /*
  * Copyright (c) 1988 University of Utah.
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1991, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * the Systems Programming Group of the University of Utah Computer
  * Science Department.
  *
  *
  * This code is derived from software contributed to Berkeley by
  * the Systems Programming Group of the University of Utah Computer
  * Science Department.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  *
  * from: Utah $Hdr: vm_mmap.c 1.6 91/10/21$
  *
  *
  * from: Utah $Hdr: vm_mmap.c 1.6 91/10/21$
  *
- *     @(#)vm_mmap.c   7.28 (Berkeley) %G%
+ *     @(#)vm_mmap.c   8.1 (Berkeley) 6/18/93
  */
 
 /*
  */
 
 /*
@@ -71,16 +97,6 @@ sstk(p, uap, retval)
        return (EOPNOTSUPP);
 }
 
        return (EOPNOTSUPP);
 }
 
-struct mmap_args {
-       caddr_t addr;
-       size_t  len;
-       int     prot;
-       int     flags;
-       int     fd;
-       long    pad;
-       off_t   pos;
-};
-
 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
 struct getpagesize_args {
        int     dummy;
 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
 struct getpagesize_args {
        int     dummy;
@@ -98,8 +114,18 @@ ogetpagesize(p, uap, retval)
 }
 #endif /* COMPAT_43 || COMPAT_SUNOS */
 
 }
 #endif /* COMPAT_43 || COMPAT_SUNOS */
 
+struct mmap_args {
+       caddr_t addr;
+       size_t  len;
+       int     prot;
+       int     flags;
+       int     fd;
+       long    pad;
+       off_t   pos;
+};
+
 #ifdef COMPAT_43
 #ifdef COMPAT_43
-struct osmmap_args {
+struct ommap_args {
        caddr_t addr;
        int     len;
        int     prot;
        caddr_t addr;
        int     len;
        int     prot;
@@ -108,9 +134,9 @@ struct osmmap_args {
        long    pos;
 };
 int
        long    pos;
 };
 int
-osmmap(p, uap, retval)
+ommap(p, uap, retval)
        struct proc *p;
        struct proc *p;
-       register struct osmmap_args *uap;
+       register struct ommap_args *uap;
        int *retval;
 {
        struct mmap_args nargs;
        int *retval;
 {
        struct mmap_args nargs;
@@ -148,12 +174,12 @@ osmmap(p, uap, retval)
                nargs.flags |= MAP_INHERIT;
        nargs.fd = uap->fd;
        nargs.pos = uap->pos;
                nargs.flags |= MAP_INHERIT;
        nargs.fd = uap->fd;
        nargs.pos = uap->pos;
-       return (smmap(p, &nargs, retval));
+       return (mmap(p, &nargs, retval));
 }
 #endif
 
 int
 }
 #endif
 
 int
-smmap(p, uap, retval)
+mmap(p, uap, retval)
        struct proc *p;
        register struct mmap_args *uap;
        int *retval;
        struct proc *p;
        register struct mmap_args *uap;
        int *retval;
@@ -458,7 +484,7 @@ mincore(p, uap, retval)
 
 struct mlock_args {
        caddr_t addr;
 
 struct mlock_args {
        caddr_t addr;
-       int     len;
+       size_t  len;
 };
 int
 mlock(p, uap, retval)
 };
 int
 mlock(p, uap, retval)
@@ -477,15 +503,15 @@ mlock(p, uap, retval)
                       p->p_pid, uap->addr, uap->len);
 #endif
        addr = (vm_offset_t)uap->addr;
                       p->p_pid, uap->addr, uap->len);
 #endif
        addr = (vm_offset_t)uap->addr;
-       if ((addr & PAGE_MASK) || uap->len < 0)
+       if ((addr & PAGE_MASK) || uap->addr + uap->len < uap->addr)
                return (EINVAL);
        size = round_page((vm_size_t)uap->len);
        if (atop(size) + cnt.v_wire_count > vm_page_max_wired)
                return (EINVAL);
        size = round_page((vm_size_t)uap->len);
        if (atop(size) + cnt.v_wire_count > vm_page_max_wired)
-               return (ENOMEM);
+               return (EAGAIN);
 #ifdef pmap_wired_count
        if (size + ptoa(pmap_wired_count(vm_map_pmap(&p->p_vmspace->vm_map))) >
            p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur)
 #ifdef pmap_wired_count
        if (size + ptoa(pmap_wired_count(vm_map_pmap(&p->p_vmspace->vm_map))) >
            p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur)
-               return (ENOMEM);
+               return (EAGAIN);
 #else
        if (error = suser(p->p_ucred, &p->p_acflag))
                return (error);
 #else
        if (error = suser(p->p_ucred, &p->p_acflag))
                return (error);
@@ -497,7 +523,7 @@ mlock(p, uap, retval)
 
 struct munlock_args {
        caddr_t addr;
 
 struct munlock_args {
        caddr_t addr;
-       int     len;
+       size_t  len;
 };
 int
 munlock(p, uap, retval)
 };
 int
 munlock(p, uap, retval)
@@ -515,7 +541,7 @@ munlock(p, uap, retval)
                       p->p_pid, uap->addr, uap->len);
 #endif
        addr = (vm_offset_t)uap->addr;
                       p->p_pid, uap->addr, uap->len);
 #endif
        addr = (vm_offset_t)uap->addr;
-       if ((addr & PAGE_MASK) || uap->len < 0)
+       if ((addr & PAGE_MASK) || uap->addr + uap->len < uap->addr)
                return (EINVAL);
 #ifndef pmap_wired_count
        if (error = suser(p->p_ucred, &p->p_acflag))
                return (EINVAL);
 #ifndef pmap_wired_count
        if (error = suser(p->p_ucred, &p->p_acflag))
@@ -545,7 +571,7 @@ vm_mmap(map, addr, size, prot, maxprot, flags, handle, foff)
        register vm_pager_t pager;
        boolean_t fitit;
        vm_object_t object;
        register vm_pager_t pager;
        boolean_t fitit;
        vm_object_t object;
-       struct vnode *vp;
+       struct vnode *vp = NULL;
        int type;
        int rv = KERN_SUCCESS;
 
        int type;
        int rv = KERN_SUCCESS;