]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/kern_mman.c
xnu-344.12.2.tar.gz
[apple/xnu.git] / bsd / kern / kern_mman.c
index 3fd5b0650c524912f8401f9ef3f45baed68e5389..3febc75bf148f077d4170a500f510a4288151304 100644 (file)
@@ -733,12 +733,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 +752,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 +933,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 +1071,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 +1086,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);