X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/378393581903b274cb7a4d18e0d978071a6b592d..4b17d6b6e417f714551ec129064745ea9919780e:/bsd/dev/i386/mem.c diff --git a/bsd/dev/i386/mem.c b/bsd/dev/i386/mem.c index 892be2473..61f0d6929 100644 --- a/bsd/dev/i386/mem.c +++ b/bsd/dev/i386/mem.c @@ -1,23 +1,29 @@ /* * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ + * @APPLE_OSREFERENCE_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. + * 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. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. * - * This Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * 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@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /*- * Copyright (c) 1988 University of Utah. @@ -71,6 +77,7 @@ #include #include #include +#include #include #include #include @@ -79,8 +86,11 @@ #include #include /* for kernel_map */ -extern vm_offset_t kvtophys(vm_offset_t va); +extern addr64_t kvtophys(vm_offset_t va); extern boolean_t kernacc(off_t, size_t ); +#if !defined(SECURE_KERNEL) +extern int setup_kmem; +#endif static caddr_t devzerobuf; @@ -104,9 +114,21 @@ mmwrite(dev_t dev, struct uio *uio) } int -mmioctl(__unused dev_t dev, u_long cmd, __unused caddr_t data, +mmioctl(dev_t dev, u_long cmd, __unused caddr_t data, __unused int flag, __unused struct proc *p) { + int minnum = minor(dev); + + if (0 == minnum || 1 == minnum) { + /* /dev/mem and /dev/kmem */ +#if defined(SECURE_KERNEL) + return (ENODEV); +#else + if (0 == setup_kmem) + return (EINVAL); +#endif + } + switch (cmd) { case FIONBIO: case FIOASYNC: @@ -128,20 +150,23 @@ mmrw(dev_t dev, struct uio *uio, enum uio_rw rw) vm_offset_t where; vm_size_t size; + while (uio_resid(uio) > 0 && error == 0) { - if (uio_iov_len(uio) == 0) { - uio_next_iov(uio); - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } + uio_update(uio, 0); + switch (minor(dev)) { /* minor device 0 is physical memory */ case 0: +#if defined(SECURE_KERNEL) + return(ENODEV); +#else + if (setup_kmem == 0) + return(ENODEV); +#endif + v = trunc_page(uio->uio_offset); - if (uio->uio_offset >= mem_size) + if (uio->uio_offset >= (off_t)mem_size) goto fault; size= PAGE_SIZE; @@ -150,19 +175,24 @@ mmrw(dev_t dev, struct uio *uio, enum uio_rw rw) goto fault; } o = uio->uio_offset - v; - // LP64todo - fix this! - c = min(PAGE_SIZE - o, (u_int)uio_iov_len(uio)); + c = min(PAGE_SIZE - o, uio_curriovlen(uio)); error = uiomove((caddr_t) (where + o), c, uio); kmem_free(kernel_map, where, PAGE_SIZE); continue; /* minor device 1 is kernel memory */ case 1: +#if defined(SECURE_KERNEL) + return(ENODEV); +#else + if (setup_kmem == 0) + return(ENODEV); +#endif /* Do some sanity checking */ if (((vm_address_t)uio->uio_offset >= VM_MAX_KERNEL_ADDRESS) || - ((vm_address_t)uio->uio_offset <= VM_MIN_KERNEL_ADDRESS)) + ((vm_address_t)uio->uio_offset <= VM_MIN_KERNEL_AND_KEXT_ADDRESS)) goto fault; - c = uio_iov_len(uio); + c = uio_curriovlen(uio); if (!kernacc(uio->uio_offset, c)) goto fault; error = uiomove((caddr_t)(uintptr_t)uio->uio_offset, @@ -173,7 +203,7 @@ mmrw(dev_t dev, struct uio *uio, enum uio_rw rw) case 2: if (rw == UIO_READ) return (0); - c = uio_iov_len(uio); + c = uio_curriovlen(uio); break; case 3: if(devzerobuf == NULL) { @@ -181,11 +211,10 @@ mmrw(dev_t dev, struct uio *uio, enum uio_rw rw) bzero(devzerobuf, PAGE_SIZE); } if(uio->uio_rw == UIO_WRITE) { - c = uio_iov_len(uio); + c = uio_curriovlen(uio); break; } - // LP64todo - fix this! - c = min(uio_iov_len(uio), PAGE_SIZE); + c = min(uio_curriovlen(uio), PAGE_SIZE); error = uiomove(devzerobuf, (int)c, uio); continue; default: @@ -195,10 +224,7 @@ mmrw(dev_t dev, struct uio *uio, enum uio_rw rw) if (error) break; - uio_iov_base_add(uio, c); - uio_iov_len_add(uio, -((int)c)); - uio->uio_offset += c; - uio_setresid(uio, (uio_resid(uio) - c)); + uio_update(uio, c); } return (error); fault: