+ if (!contiguous) {
+#if __arm__ || __arm64__
+ if (maxPhys >= (mach_vm_address_t)(gPhysBase + gPhysSize)) {
+ maxPhys = 0;
+ } else
+#endif
+ if (maxPhys <= 0xFFFFFFFF) {
+ maxPhys = 0;
+ options |= KMA_LOMEM;
+ } else if (gIOLastPage && (atop_64(maxPhys) > gIOLastPage)) {
+ maxPhys = 0;
+ }
+ }
+ if (contiguous || maxPhys) {
+ kr = kmem_alloc_contig(kernel_map, &virt, size,
+ alignMask, atop(maxPhys), atop(alignMask), 0, IOMemoryTag(kernel_map));
+ } else {
+ kr = kernel_memory_allocate(kernel_map, &virt,
+ size, alignMask, options, IOMemoryTag(kernel_map));
+ }
+ if (KERN_SUCCESS == kr) {
+ address = virt;
+#if IOTRACKING
+ if (TRACK_ALLOC) {
+ IOTrackingAlloc(gIOMallocTracking, address, size);
+ }
+#endif
+ } else {
+ address = 0;
+ }
+ } else {
+ adjustedSize += alignMask;
+ if (adjustedSize < size) {
+ return 0;
+ }
+ allocationAddress = (mach_vm_address_t) kalloc_tag_bt(adjustedSize, VM_KERN_MEMORY_IOKIT);
+
+ if (allocationAddress) {
+ address = (allocationAddress + alignMask + sizeofIOLibPageMallocHeader)
+ & (~alignMask);