X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/3e170ce000f1506b7b5d2c5c7faec85ceabb573d..d9a64523371fa019c4575bb400cbbc3a50ac9903:/iokit/Kernel/IOMultiMemoryDescriptor.cpp diff --git a/iokit/Kernel/IOMultiMemoryDescriptor.cpp b/iokit/Kernel/IOMultiMemoryDescriptor.cpp index fd17233c1..d54824088 100644 --- a/iokit/Kernel/IOMultiMemoryDescriptor.cpp +++ b/iokit/Kernel/IOMultiMemoryDescriptor.cpp @@ -276,26 +276,38 @@ IOReturn IOMultiMemoryDescriptor::doMap(vm_map_t __addressMap, { prot = VM_PROT_READ; if (!(kIOMapReadOnly & options)) prot |= VM_PROT_WRITE; - ref.map = map; - ref.tag = IOMemoryTag(map); - ref.options = options; - ref.size = length; - ref.prot = prot; - if (options & kIOMapAnywhere) - // vm_map looks for addresses above here, even when VM_FLAGS_ANYWHERE - ref.mapped = 0; - else - ref.mapped = mapping->fAddress; - - if ((ref.map == kernel_map) && (kIOMemoryBufferPageable & _flags)) - err = IOIteratePageableMaps(ref.size, &IOMemoryDescriptorMapAlloc, &ref); - else - err = IOMemoryDescriptorMapAlloc(ref.map, &ref); - - if (KERN_SUCCESS != err) break; - - address = ref.mapped; - mapping->fAddress = address; + + if (kIOMapOverwrite & options) + { + if ((map == kernel_map) && (kIOMemoryBufferPageable & _flags)) + { + map = IOPageableMapForAddress(address); + } + err = KERN_SUCCESS; + } + else + { + ref.map = map; + ref.tag = IOMemoryTag(map); + ref.options = options; + ref.size = length; + ref.prot = prot; + if (options & kIOMapAnywhere) + // vm_map looks for addresses above here, even when VM_FLAGS_ANYWHERE + ref.mapped = 0; + else + ref.mapped = mapping->fAddress; + + if ((ref.map == kernel_map) && (kIOMemoryBufferPageable & _flags)) + err = IOIteratePageableMaps(ref.size, &IOMemoryDescriptorMapAlloc, &ref); + else + err = IOMemoryDescriptorMapAlloc(ref.map, &ref); + + if (KERN_SUCCESS != err) break; + + address = ref.mapped; + mapping->fAddress = address; + } mapOffset = offset; bytesRemaining = length; @@ -329,14 +341,9 @@ IOReturn IOMultiMemoryDescriptor::doMap(vm_map_t __addressMap, if (kIOReturnSuccess == err) { #if IOTRACKING - IOTrackingAdd(gIOMapTracking, &mapping->fTracking, length, false); + IOTrackingAddUser(gIOMapTracking, &mapping->fTracking, mapping->fLength); #endif } - else - { - mapping->release(); - mapping = 0; - } return (err); } @@ -348,6 +355,7 @@ IOReturn IOMultiMemoryDescriptor::setPurgeable( IOOptionBits newState, IOOptionBits totalState, state; totalState = kIOMemoryPurgeableNonVolatile; + err = kIOReturnSuccess; for (unsigned index = 0; index < _descriptorsCount; index++) { err = _descriptors[index]->setPurgeable(newState, &state); @@ -386,3 +394,31 @@ IOReturn IOMultiMemoryDescriptor::getPageCounts(IOByteCount * pResidentPageCount return (err); } + +uint64_t IOMultiMemoryDescriptor::getPreparationID( void ) +{ + + if (!super::getKernelReserved()) + { + return (kIOPreparationIDUnsupported); + } + + for (unsigned index = 0; index < _descriptorsCount; index++) + { + uint64_t preparationID = _descriptors[index]->getPreparationID(); + + if ( preparationID == kIOPreparationIDUnsupported ) + { + return (kIOPreparationIDUnsupported); + } + + if ( preparationID == kIOPreparationIDUnprepared ) + { + return (kIOPreparationIDUnprepared); + } + } + + super::setPreparationID(); + + return (super::getPreparationID()); +}