]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/kern_mman.c
xnu-344.49.tar.gz
[apple/xnu.git] / bsd / kern / kern_mman.c
index 3fd5b0650c524912f8401f9ef3f45baed68e5389..f42e2d13517a0634d29c9162819d2fcdc8e399c0 100644 (file)
@@ -3,19 +3,22 @@
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
@@ -733,12 +736,12 @@ madvise(p, uap, retval)
         */
        if (VM_MAX_ADDRESS > 0 &&
                ((vm_offset_t) uap->addr + uap->len) > VM_MAX_ADDRESS)
-               return (EINVAL);
+               return (ENOMEM);
        if (VM_MIN_ADDRESS > 0 && uap->addr < VM_MIN_ADDRESS)
-               return (EINVAL);
+               return (ENOMEM);
 
        if (((vm_offset_t) uap->addr + uap->len) < (vm_offset_t) uap->addr)
-               return (EINVAL);
+               return (ENOMEM);
 
        /*
         * Since this routine is only advisory, we default to conservative
@@ -752,14 +755,24 @@ madvise(p, uap, retval)
        switch (uap->behav) {
                case MADV_RANDOM:
                        new_behavior = VM_BEHAVIOR_RANDOM;
+                       break;
                case MADV_SEQUENTIAL: 
                        new_behavior = VM_BEHAVIOR_SEQUENTIAL;
+                       break;
                case MADV_NORMAL:
-               default:
                        new_behavior = VM_BEHAVIOR_DEFAULT;
+                       break;
+               case MADV_WILLNEED:
+                       new_behavior = VM_BEHAVIOR_WILLNEED;
+                       break;
+               case MADV_DONTNEED:
+                       new_behavior = VM_BEHAVIOR_DONTNEED;
+                       break;
+               default:
+                       return(EINVAL);
        }
 
-       result = vm_behavior_set(user_map, start, end, uap->behav);
+       result = vm_behavior_set(user_map, start, end, new_behavior);
        switch (result) {
                case KERN_SUCCESS:
                        return (0);
@@ -923,7 +936,7 @@ mlock(p, uap, retval)
        user_map = current_map();
 
        /* vm_wire */
-       result = vm_wire(host_priv_self(), user_map, addr, size, VM_PROT_ALL);
+       result = vm_map_wire(user_map, addr, (vm_offset_t)(addr+size), VM_PROT_NONE, TRUE);
        return (result == KERN_SUCCESS ? 0 : ENOMEM);
 }
 
@@ -1061,7 +1074,7 @@ kern_return_t map_fd_funneled(
        vm_map_copy_t   tmp;
        int             err=0;
        vm_map_t        my_map;
-       struct proc     *p =(struct proc *)(get_bsdtask_info(current_task()));
+       struct proc     *p =(struct proc *)current_proc();
 #if 0
        extern int print_map_addr;
 #endif /* 0 */
@@ -1076,13 +1089,17 @@ kern_return_t map_fd_funneled(
        
        if (fp->f_type != DTYPE_VNODE)
                return(KERN_INVALID_ARGUMENT);
+
+       if (!(fp->f_flag & FREAD))
+               return (KERN_PROTECTION_FAILURE);
+
        vp = (struct vnode *)fp->f_data;
 
        if (vp->v_type != VREG)
                return (KERN_INVALID_ARGUMENT);
 
        if (offset & PAGE_MASK_64) {
-               printf("map_fd: file offset not page aligned(%d : %s\)n",p->p_pid, p->p_comm);
+               printf("map_fd: file offset not page aligned(%d : %s)\n",p->p_pid, p->p_comm);
                return (KERN_INVALID_ARGUMENT);
        }
        map_size = round_page(size);