Loading...
--- xnu/xnu-12377.101.15/iokit/Kernel/IOBufferMemoryDescriptor.cpp
+++ xnu/xnu-11417.140.69/iokit/Kernel/IOBufferMemoryDescriptor.cpp
@@ -73,12 +73,6 @@
kInternalFlagInit = 0x00000008,
kInternalFlagHasPointers = 0x00000010,
kInternalFlagGuardPages = 0x00000020,
- /**
- * Should the IOBMD behave as if it has no kernel mapping for the
- * underlying buffer? Note that this does not necessarily imply the
- * existence (or non-existence) of a kernel mapping.
- */
- kInternalFlagAsIfUnmapped = 0x00000040,
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -196,7 +190,6 @@
bool mapped = false;
bool withCopy = false;
bool mappedOrShared = false;
- bool noSoftLimit = false;
if (!capacity) {
return false;
@@ -274,19 +267,8 @@
return false;
}
- if (inTask) {
- if ((inTask != kernel_task) && !(options & kIOMemoryPageable)) {
- // Cannot create non-pageable memory in user tasks
- return false;
- }
- } else {
- // Not passing a task implies the memory should not be mapped (or, at
- // least, should behave as if it were not mapped)
- _internalFlags |= kInternalFlagAsIfUnmapped;
-
- // Disable the soft-limit since the mapping, if any, will not escape the
- // IOBMD.
- noSoftLimit = true;
+ if ((inTask != kernel_task) && !(options & kIOMemoryPageable)) {
+ return false;
}
bzero(&mapSpec, sizeof(mapSpec));
@@ -344,7 +326,7 @@
}
}
_buffer = (void *) IOKernelAllocateWithPhysicalRestrict(kheap,
- capacity, highestMask, alignment, contig, noSoftLimit);
+ capacity, highestMask, alignment, contig);
} else if (_internalFlags & kInternalFlagGuardPages) {
vm_offset_t address = 0;
kern_return_t kr;
@@ -357,10 +339,6 @@
}
if (kheap == KHEAP_DATA_SHARED) {
kma_flags = (kma_flags_t) (kma_flags | KMA_DATA_SHARED);
- }
-
- if (noSoftLimit) {
- kma_flags = (kma_flags_t)(kma_flags | KMA_NOSOFTLIMIT);
}
alignMask = (1UL << log2up((uint32_t) alignment)) - 1;
@@ -389,20 +367,13 @@
#endif
}
#endif /* defined(__x86_64__) */
- } else {
- zalloc_flags_t zflags = Z_ZERO_VM_TAG_BT_BIT;
- if (noSoftLimit) {
- zflags = (zalloc_flags_t)(zflags | Z_NOSOFTLIMIT);
- }
-
+ } else if (alignment > 1) {
/* BEGIN IGNORE CODESTYLE */
__typed_allocators_ignore_push
- if (alignment > 1) {
- _buffer = IOMallocAligned_internal(kheap, capacity, alignment,
- zflags);
- } else {
- _buffer = IOMalloc_internal(kheap, capacity, zflags);
- }
+ _buffer = IOMallocAligned_internal(kheap, capacity, alignment,
+ Z_ZERO_VM_TAG_BT_BIT);
+ } else {
+ _buffer = IOMalloc_internal(kheap, capacity, Z_ZERO_VM_TAG_BT_BIT);
__typed_allocators_ignore_pop
/* END IGNORE CODESTYLE */
}
@@ -426,6 +397,9 @@
if (!withCopy) {
mapTask = inTask;
}
+ if (NULL == inTask) {
+ inTask = kernel_task;
+ }
} else if (options & kIOMapCacheMask) {
// Prefetch each page to put entries into the pmap
volatile UInt8 * startAddr = (UInt8 *)_buffer;
@@ -439,16 +413,11 @@
}
}
- _ranges.v64->address = (mach_vm_address_t) _buffer;
+ _ranges.v64->address = (mach_vm_address_t) pgz_decode(_buffer, _capacity);
_ranges.v64->length = _capacity;
- if (!super::initWithOptions(
- /* buffers */ _ranges.v64, /* count */ 1, /* offset */ 0,
- // Since we handle all "unmapped" behavior internally and our superclass
- // requires a task, default all unbound IOBMDs to the kernel task.
- /* task */ inTask ?: kernel_task,
- /* options */ iomdOptions,
- /* System mapper */ NULL)) {
+ if (!super::initWithOptions(_ranges.v64, 1, 0,
+ inTask, iomdOptions, /* System mapper */ NULL)) {
return false;
}
@@ -857,7 +826,7 @@
bool
IOBufferMemoryDescriptor::appendBytes(const void * bytes, vm_size_t withLength)
{
- vm_size_t actualBytesToCopy = IOMin(withLength, _capacity - _length);
+ vm_size_t actualBytesToCopy = min(withLength, _capacity - _length);
IOByteCount offset;
assert(_length <= _capacity);
@@ -884,10 +853,6 @@
void *
IOBufferMemoryDescriptor::getBytesNoCopy()
{
- if (__improbable(_internalFlags & kInternalFlagAsIfUnmapped)) {
- return NULL;
- }
-
if (kIOMemoryTypePhysical64 == (_flags & kIOMemoryTypeMask)) {
return _buffer;
} else {
@@ -905,10 +870,6 @@
IOBufferMemoryDescriptor::getBytesNoCopy(vm_size_t start, vm_size_t withLength)
{
IOVirtualAddress address;
-
- if (__improbable(_internalFlags & kInternalFlagAsIfUnmapped)) {
- return NULL;
- }
if ((start + withLength) < start) {
return NULL;