]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/btlog.c
xnu-3248.40.184.tar.gz
[apple/xnu.git] / osfmk / kern / btlog.c
index 50fc5991e01d8fc176fe3a287f52b45ad96f10f2..c39dd166d6037396602c9f26c4ddb52186bc2e18 100644 (file)
@@ -31,6 +31,7 @@
 #include <kern/assert.h>
 #include <vm/vm_kern.h>
 #include <vm/vm_map.h>
+#include <vm/pmap.h>
 #include <mach/vm_param.h>
 
 /*
@@ -73,6 +74,7 @@ struct btlog {
     btlog_recordindex_t freelist;
 };
 
+extern boolean_t vm_kernel_ready;
 extern boolean_t kmem_alloc_ready;
 
 #define lookup_btrecord(btlog, index) \
@@ -92,7 +94,7 @@ btlog_create(size_t numrecords,
        kern_return_t ret;
        size_t btrecord_size;
 
-       if (!kmem_alloc_ready)
+       if (vm_kernel_ready && !kmem_alloc_ready)
                return NULL;
 
        if (numrecords > BTLOG_MAX_RECORDS)
@@ -118,8 +120,13 @@ btlog_create(size_t numrecords,
        /* since rounding to a page size might hold more, recalculate */
        numrecords = MIN(BTLOG_MAX_RECORDS,
                                         (buffersize_needed - sizeof(btlog_t))/btrecord_size);
-       
-       ret = kmem_alloc(kernel_map, &buffer, buffersize_needed);
+
+       if (kmem_alloc_ready) {
+               ret = kmem_alloc(kernel_map, &buffer, buffersize_needed, VM_KERN_MEMORY_DIAG);
+       } else {
+               buffer = (vm_address_t)pmap_steal_memory(buffersize_needed);
+               ret = KERN_SUCCESS;
+       }
        if (ret != KERN_SUCCESS)
                return NULL;