- kr = mach_make_memory_entry( vmmap,
- &size, 0,
- memEntryCacheMode, &sharedMem,
- NULL );
+ // Buffer shouldn't auto prepare they should be prepared explicitly
+ // But it never was enforced so what are you going to do?
+ iomdOptions |= kIOMemoryAutoPrepare;
+
+ /* Allocate a wired-down buffer inside kernel space. */
+ if (options & kIOMemoryPhysicallyContiguous)
+ _buffer = (void *) IOKernelAllocateContiguous(capacity, alignment);
+ else if (alignment > 1)
+ _buffer = IOMallocAligned(capacity, alignment);
+ else
+ _buffer = IOMalloc(capacity);
+ if (!_buffer)
+ return false;
+ }
+ }
+
+ if( (kIOMemoryTypePhysical64 != (kIOMemoryTypeMask & iomdOptions))
+ && (options & (kIOMemoryPageable | kIOMapCacheMask))) {
+ ipc_port_t sharedMem;
+ vm_size_t size = round_page_32(capacity);
+
+ kr = mach_make_memory_entry(vmmap,
+ &size, (vm_offset_t)_buffer,
+ memEntryCacheMode, &sharedMem,
+ NULL );