X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/d7e50217d7adf6e52786a38bcaa4cd698cb9a79e..5eebf7385fedb1517b66b53c28e5aa6bb0a2be50:/bsd/kern/kern_mman.c diff --git a/bsd/kern/kern_mman.c b/bsd/kern/kern_mman.c index 2d03d5f13..e234d8955 100644 --- a/bsd/kern/kern_mman.c +++ b/bsd/kern/kern_mman.c @@ -1,24 +1,21 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * 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. * - * 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 + * This 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, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -85,6 +82,9 @@ #include #include +#include +#include + #include #include @@ -151,6 +151,7 @@ struct osmmap_args { long pos; }; +int osmmap(curp, uap, retval) struct proc *curp; register struct osmmap_args *uap; @@ -219,6 +220,10 @@ mmap(p, uap, retval) user_addr = (vm_offset_t)uap->addr; user_size = (vm_size_t) uap->len; + AUDIT_ARG(addr, (void *)user_addr); + AUDIT_ARG(len, (int) user_size); + AUDIT_ARG(fd, uap->fd); + prot = (uap->prot & VM_PROT_ALL); flags = uap->flags; @@ -303,7 +308,7 @@ mmap(p, uap, retval) if (err) return(err); if(fp->f_type == DTYPE_PSXSHM) { - uap->addr = user_addr; + uap->addr = (caddr_t)user_addr; uap->len = user_size; uap->prot = prot; uap->flags = flags; @@ -317,12 +322,15 @@ mmap(p, uap, retval) if (vp->v_type != VREG && vp->v_type != VCHR) return (EINVAL); + + AUDIT_ARG(vnpath, vp, ARG_VNODE1); + /* * XXX hack to handle use of /dev/zero to map anon memory (ala * SunOS). */ if (vp->v_type == VCHR || vp->v_type == VSTR) { - return(EOPNOTSUPP); + return(ENODEV); } else { /* * Ensure that file and memory protections are @@ -419,9 +427,16 @@ mmap(p, uap, retval) if (result != KERN_SUCCESS) goto out; + result = vm_protect(user_map, user_addr, user_size, TRUE, maxprot); + if (result != KERN_SUCCESS) + goto out; + result = vm_protect(user_map, user_addr, user_size, FALSE, prot); + if (result != KERN_SUCCESS) + goto out; + } else { UBCINFOCHECK("mmap", vp); - pager = ubc_getpager(vp); + pager = (vm_pager_t)ubc_getpager(vp); if (pager == NULL) return (ENOMEM); @@ -461,7 +476,7 @@ mmap(p, uap, retval) ubc_map(vp); } - if (flags & (MAP_SHARED|MAP_INHERIT)) { + if (flags & MAP_SHARED) { result = vm_inherit(user_map, user_addr, user_size, VM_INHERIT_SHARE); if (result != KERN_SUCCESS) { @@ -518,6 +533,9 @@ msync(p, uap, retval) user_map = current_map(); + if ((flags & (MS_ASYNC|MS_SYNC)) == (MS_ASYNC|MS_SYNC)) + return (EINVAL); + if ((flags & (MS_ASYNC|MS_INVALIDATE)) == (MS_ASYNC|MS_INVALIDATE)) return (EINVAL); @@ -529,7 +547,7 @@ msync(p, uap, retval) * inaccurate results, lets just return error as invalid size * specified */ - return(EINVAL); + return (EINVAL); /* XXX breaks posix apps */ } if (flags & MS_KILLPAGES) @@ -559,10 +577,10 @@ msync(p, uap, retval) } return (0); - } +int mremap() { /* Not yet implemented */ @@ -573,6 +591,7 @@ struct munmap_args { caddr_t addr; int len; }; +int munmap(p, uap, retval) struct proc *p; struct munmap_args *uap; @@ -586,6 +605,9 @@ munmap(p, uap, retval) user_addr = (vm_offset_t) uap->addr; user_size = (vm_size_t) uap->len; + AUDIT_ARG(addr, (void *)user_addr); + AUDIT_ARG(len, (int) user_size); + pageoff = (user_addr & PAGE_MASK); user_addr -= pageoff; @@ -639,6 +661,9 @@ mprotect(p, uap, retval) kern_return_t result; vm_map_t user_map; + AUDIT_ARG(addr, uap->addr); + AUDIT_ARG(len, uap->len); + AUDIT_ARG(value, uap->prot); user_addr = (vm_offset_t) uap->addr; user_size = (vm_size_t) uap->len; prot = (vm_prot_t)(uap->prot & VM_PROT_ALL); @@ -690,6 +715,9 @@ minherit(p, uap, retval) vm_map_t user_map; kern_return_t result; + AUDIT_ARG(addr, uap->addr); + AUDIT_ARG(len, uap->len); + AUDIT_ARG(value, uap->inherit); addr = (vm_offset_t)uap->addr; size = uap->len; inherit = uap->inherit; @@ -907,6 +935,8 @@ mlock(p, uap, retval) int error; kern_return_t result; + AUDIT_ARG(addr, uap->addr); + AUDIT_ARG(len, uap->len); addr = (vm_offset_t) uap->addr; size = uap->len; @@ -956,6 +986,8 @@ munlock(p, uap, retval) vm_map_t user_map; kern_return_t result; + AUDIT_ARG(addr, uap->addr); + AUDIT_ARG(len, uap->len); addr = (vm_offset_t) uap->addr; size = uap->len; @@ -1014,6 +1046,7 @@ munlockall(p, uap) struct obreak_args { char *nsiz; }; +int obreak(p, uap, retval) struct proc *p; struct obreak_args *uap; @@ -1025,6 +1058,7 @@ obreak(p, uap, retval) int both; +int ovadvise() { @@ -1033,12 +1067,11 @@ ovadvise() #endif } /* END DEFUNCT */ -#if 1 -int print_map_addr=0; -#endif /* 1 */ /* CDY need to fix interface to allow user to map above 32 bits */ -kern_return_t map_fd( +/* USV: No! need to obsolete map_fd()! mmap() already supports 64 bits */ +kern_return_t +map_fd( int fd, vm_offset_t offset, vm_offset_t *va, @@ -1048,6 +1081,10 @@ kern_return_t map_fd( kern_return_t ret; boolean_t funnel_state; + AUDIT_MACH_SYSCALL_ENTER(AUE_MAPFD); + AUDIT_ARG(addr, va); + AUDIT_ARG(fd, fd); + funnel_state = thread_funnel_set(kernel_flock, TRUE); ret = map_fd_funneled( fd, (vm_object_offset_t)offset, @@ -1055,10 +1092,12 @@ kern_return_t map_fd( (void) thread_funnel_set(kernel_flock, FALSE); + AUDIT_MACH_SYSCALL_EXIT(ret); return ret; } -kern_return_t map_fd_funneled( +kern_return_t +map_fd_funneled( int fd, vm_object_offset_t offset, vm_offset_t *va, @@ -1075,9 +1114,6 @@ kern_return_t map_fd_funneled( int err=0; vm_map_t my_map; struct proc *p =(struct proc *)current_proc(); -#if 0 - extern int print_map_addr; -#endif /* 0 */ /* * Find the inode; verify that it's a regular file. @@ -1098,6 +1134,8 @@ kern_return_t map_fd_funneled( if (vp->v_type != VREG) return (KERN_INVALID_ARGUMENT); + AUDIT_ARG(vnpath, vp, ARG_VNODE1); + if (offset & PAGE_MASK_64) { printf("map_fd: file offset not page aligned(%d : %s)\n",p->p_pid, p->p_comm); return (KERN_INVALID_ARGUMENT);