Loading...
--- xnu/xnu-10002.1.13/iokit/Kernel/IOBufferMemoryDescriptor.cpp
+++ xnu/xnu-8019.80.24/iokit/Kernel/IOBufferMemoryDescriptor.cpp
@@ -59,7 +59,6 @@
void ipc_port_release_send(ipc_port_t port);
#include <vm/pmap.h>
-KALLOC_HEAP_DEFINE(KHEAP_IOBMD_CONTROL, "IOBMD_control", KHEAP_ID_KT_VAR);
__END_DECLS
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -81,19 +80,14 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-#if defined(__x86_64__)
static uintptr_t
IOBMDPageProc(kalloc_heap_t kheap, iopa_t * a)
{
kern_return_t kr;
vm_address_t vmaddr = 0;
- kma_flags_t kma_flags = KMA_ZERO;
-
- if (kheap == KHEAP_DATA_BUFFERS) {
- kma_flags = (kma_flags_t) (kma_flags | KMA_DATA);
- }
- kr = kmem_alloc(kernel_map, &vmaddr, page_size,
- kma_flags, VM_KERN_MEMORY_IOKIT);
+
+ kr = kernel_memory_allocate(kheap->kh_fallback_map, &vmaddr,
+ page_size, 0, (kma_flags_t) (KMA_NONE | KMA_ZERO), VM_KERN_MEMORY_IOKIT);
if (KERN_SUCCESS != kr) {
vmaddr = 0;
@@ -101,7 +95,6 @@
return (uintptr_t) vmaddr;
}
-#endif /* defined(__x86_64__) */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -189,6 +182,13 @@
bool withCopy = false;
bool mappedOrShared = false;
+ /*
+ * Temporarily use default heap on intel due to rdar://74982985
+ */
+#if __x86_64__
+ kheap = KHEAP_DEFAULT;
+#endif
+
if (!capacity) {
return false;
}
@@ -219,10 +219,10 @@
}
/*
- * Set kalloc_heap to KHEAP_IOBMD_CONTROL if allocation contains pointers
+ * Set kalloc_heap to default if allocation contains pointers
*/
if (kInternalFlagHasPointers & _internalFlags) {
- kheap = KHEAP_IOBMD_CONTROL;
+ kheap = KHEAP_DEFAULT;
}
// make sure super::free doesn't dealloc _ranges before super::init
@@ -329,20 +329,14 @@
vm_offset_t address = 0;
kern_return_t kr;
uintptr_t alignMask;
- kma_flags_t kma_flags = (kma_flags_t) (KMA_GUARD_FIRST |
- KMA_GUARD_LAST | KMA_ZERO);
if (((uint32_t) alignment) != alignment) {
- return false;
+ return NULL;
}
- if (kheap == KHEAP_DATA_BUFFERS) {
- kma_flags = (kma_flags_t) (kma_flags | KMA_DATA);
- }
alignMask = (1UL << log2up((uint32_t) alignment)) - 1;
- kr = kernel_memory_allocate(kernel_map, &address,
- capacity + page_size * 2, alignMask, kma_flags,
- IOMemoryTag(kernel_map));
+ kr = kernel_memory_allocate(kheap->kh_fallback_map, &address,
+ capacity + page_size * 2, alignMask, (kma_flags_t)(KMA_GUARD_FIRST | KMA_GUARD_LAST), IOMemoryTag(kernel_map));
if (kr != KERN_SUCCESS || address == 0) {
return false;
}
@@ -351,33 +345,26 @@
#endif
IOStatisticsAlloc(kIOStatisticsMallocAligned, capacity);
_buffer = (void *)(address + page_size);
-#if defined(__x86_64__)
} else if (mappedOrShared
&& (capacity + alignment) <= (page_size - gIOPageAllocChunkBytes)) {
_internalFlags |= kInternalFlagPageAllocated;
_buffer = (void *) iopa_alloc(&gIOBMDPageAllocator,
&IOBMDPageProc, kheap, capacity, alignment);
if (_buffer) {
- bzero(_buffer, capacity);
IOStatisticsAlloc(kIOStatisticsMallocAligned, capacity);
#if IOALLOCDEBUG
OSAddAtomicLong(capacity, &debug_iomalloc_size);
#endif
}
-#endif /* defined(__x86_64__) */
} else if (alignment > 1) {
- /* BEGIN IGNORE CODESTYLE */
- __typed_allocators_ignore_push
- _buffer = IOMallocAligned_internal(kheap, capacity, alignment,
- Z_ZERO_VM_TAG_BT_BIT);
+ _buffer = IOMallocAligned_internal(kheap, capacity, alignment);
} else {
- _buffer = IOMalloc_internal(kheap, capacity, Z_ZERO_VM_TAG_BT_BIT);
- __typed_allocators_ignore_pop
- /* END IGNORE CODESTYLE */
+ _buffer = IOMalloc_internal(kheap, capacity);
}
if (!_buffer) {
return false;
}
+ bzero(_buffer, capacity);
}
if ((options & (kIOMemoryPageable | kIOMapCacheMask))) {
@@ -411,7 +398,7 @@
}
}
- _ranges.v64->address = (mach_vm_address_t) pgz_decode(_buffer, _capacity);
+ _ranges.v64->address = (mach_vm_address_t) _buffer;
_ranges.v64->length = _capacity;
if (!super::initWithOptions(_ranges.v64, 1, 0,
@@ -642,13 +629,11 @@
bool inContiguous)
{
OSSharedPtr<IOBufferMemoryDescriptor> me = OSMakeShared<IOBufferMemoryDescriptor>();
- mach_vm_address_t alignment;
-
- alignment = (inLength <= page_size) ? inLength : page_size;
+
if (me && !me->initWithPhysicalMask(
kernel_task, inDirection | kIOMemoryUnshared
| (inContiguous ? kIOMemoryPhysicallyContiguous : 0),
- inLength, alignment, 0 )) {
+ inLength, inLength, 0 )) {
me.reset();
}
@@ -682,12 +667,16 @@
IOAddressRange * range = _ranges.v64;
vm_offset_t alignment = _alignment;
kalloc_heap_t kheap = KHEAP_DATA_BUFFERS;
- vm_size_t rsize;
+
+ /*
+ * Temporarily use default heap on intel due to rdar://74982985
+ */
+#if __x86_64__
+ kheap = KHEAP_DEFAULT;
+#endif
if (alignment >= page_size) {
- if (!round_page_overflow(size, &rsize)) {
- size = rsize;
- }
+ size = round_page(size);
}
if (reserved) {
@@ -700,13 +689,11 @@
if ((options & kIOMemoryPageable)
|| (kInternalFlagPageSized & internalFlags)) {
- if (!round_page_overflow(size, &rsize)) {
- size = rsize;
- }
+ size = round_page(size);
}
if (internalFlags & kInternalFlagHasPointers) {
- kheap = KHEAP_IOBMD_CONTROL;
+ kheap = KHEAP_DEFAULT;
}
#if IOTRACKING
@@ -728,35 +715,26 @@
if (kInternalFlagPhysical & internalFlags) {
IOKernelFreePhysical(kheap, (mach_vm_address_t) buffer, size);
} else if (kInternalFlagPageAllocated & internalFlags) {
-#if defined(__x86_64__)
uintptr_t page;
page = iopa_free(&gIOBMDPageAllocator, (uintptr_t) buffer, size);
if (page) {
- kmem_free(kernel_map, page, page_size);
+ kmem_free(kheap->kh_fallback_map, page, page_size);
}
#if IOALLOCDEBUG
OSAddAtomicLong(-size, &debug_iomalloc_size);
#endif
IOStatisticsAlloc(kIOStatisticsFreeAligned, size);
-#else /* !defined(__x86_64__) */
- /* should be unreachable */
- panic("Attempting to free IOBMD with page allocated flag");
-#endif /* defined(__x86_64__) */
} else if (kInternalFlagGuardPages & internalFlags) {
vm_offset_t allocation = (vm_offset_t)buffer - page_size;
- kmem_free(kernel_map, allocation, size + page_size * 2);
+ kmem_free(kheap->kh_fallback_map, allocation, size + page_size * 2);
#if IOALLOCDEBUG
OSAddAtomicLong(-size, &debug_iomalloc_size);
#endif
IOStatisticsAlloc(kIOStatisticsFreeAligned, size);
} else if (alignment > 1) {
- /* BEGIN IGNORE CODESTYLE */
- __typed_allocators_ignore_push
IOFreeAligned_internal(kheap, buffer, size);
} else {
IOFree_internal(kheap, buffer, size);
- __typed_allocators_ignore_pop
- /* END IGNORE CODESTYLE */
}
}
if (range && (kIOMemoryAsReference & flags)) {