- /* Allocate the kext virtual memory */
- rval = mach_vm_allocate(g_kext_map, &addr, size, flags);
+#if CONFIG_KEXT_BASEMENT
+ /* Allocate the kext virtual memory
+ * 10608884 - use mach_vm_map since we want VM_FLAGS_ANYWHERE allocated past
+ * kext_post_boot_base (when possible). mach_vm_allocate will always
+ * start at 0 into the map no matter what you pass in addr. We want non
+ * fixed (post boot) kext allocations to start looking for free space
+ * just past where prelinked kexts have loaded.
+ */
+ rval = mach_vm_map_kernel(g_kext_map,
+ &addr,
+ size,
+ 0,
+ flags,
+ VM_KERN_MEMORY_KEXT,
+ MACH_PORT_NULL,
+ 0,
+ TRUE,
+ VM_PROT_DEFAULT,
+ VM_PROT_ALL,
+ VM_INHERIT_DEFAULT);
+ if (rval != KERN_SUCCESS) {
+ printf("mach_vm_map failed - %d\n", rval);
+ goto finish;
+ }
+#else
+ rval = mach_vm_allocate_kernel(g_kext_map, &addr, size, flags, VM_KERN_MEMORY_KEXT);