Index: /trunk/src/VBox/Runtime/r0drv/darwin/mach_kernel-r0drv-darwin.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r0drv/darwin/mach_kernel-r0drv-darwin.cpp	(revision 37565)
+++ /trunk/src/VBox/Runtime/r0drv/darwin/mach_kernel-r0drv-darwin.cpp	(revision 37566)
@@ -26,4 +26,5 @@
 
 
+#define RTMEM_WRAP_TO_EF_APIS
 /*******************************************************************************
 *   Header Files                                                               *
@@ -173,4 +174,5 @@
     RTMemFree(pKernel->pachStrTab);
     pKernel->pachStrTab = NULL;
+
     RTMemFree(pKernel->paSyms);
     pKernel->paSyms = NULL;
@@ -192,5 +194,5 @@
     RTMemFree(pKernel->pLoadCmds);
     pKernel->pLoadCmds = NULL;
-    RT_ZERO(pKernel->apSections);
+    memset((void *)&pKernel->apSections[0], 0, sizeof(pKernel->apSections[0]) * MACHO_MAX_SECT);
 }
 
@@ -230,11 +232,23 @@
 
 
+/* Rainy day: Find the right headers for these symbols ... if there are any. */
 extern "C" void ev_try_lock(void);
 extern "C" void OSMalloc(void);
 extern "C" void OSlibkernInit(void);
-extern "C" int osrelease;
-extern "C" int ostype;
+extern "C" int  osrelease;
+extern "C" int  ostype;
 extern "C" void kdp_set_interface(void);
 
+
+/**
+ * Check the symbol table against symbols we known symbols. 
+ *  
+ * This is done to detect whether the on disk image and the in 
+ * memory images matches.  Mismatches could stem from user 
+ * replacing the default kernel image on disk.
+ *  
+ * @returns IPRT status code.
+ * @param   pKernel             The internal scratch data.
+ */
 static int rtR0DarwinMachKernelCheckStandardSymbols(PRTR0DARWINKERNEL pKernel)
 {
@@ -804,6 +818,16 @@
 
 
+/**
+ * Opens symbol table of the mach_kernel. 
+ *  
+ * @returns IPRT status code.
+ * @param   pszMachKernel   The path to the mach_kernel image.
+ * @param   ppHandle        Where to return a handle on success. 
+ *                          Call rtR0DarwinMachKernelClose on it
+ *                          when done.
+ */
 static int rtR0DarwinMachKernelOpen(const char *pszMachKernel, PRTR0DARWINKERNEL *ppHandle)
 {
+    *ppHandle = NULL;
     PRTR0DARWINKERNEL pKernel = (PRTR0DARWINKERNEL)RTMemAllocZ(sizeof(*pKernel));
     if (!pKernel)
@@ -822,5 +846,7 @@
 
     rtR0DarwinMachKernelLoadDone(pKernel);
-    if (RT_FAILURE(rc))
+    if (RT_SUCCESS(rc))
+        *ppHandle = pKernel;
+    else
         rtR0DarwinMachKernelClose(pKernel);
     return rc;
Index: /trunk/src/VBox/Runtime/testcase/tstRTDarwinMachKernel.cpp
===================================================================
--- /trunk/src/VBox/Runtime/testcase/tstRTDarwinMachKernel.cpp	(revision 37565)
+++ /trunk/src/VBox/Runtime/testcase/tstRTDarwinMachKernel.cpp	(revision 37566)
@@ -39,4 +39,19 @@
     PRTR0DARWINKERNEL pKernel;
     RTTESTI_CHECK_RC_RETV(rtR0DarwinMachKernelOpen(pszMachKernel, &pKernel), VINF_SUCCESS);
+    static const char * const s_apszSyms[] =
+    {
+        "ast_pending",
+        "i386_signal_cpu",
+        "i386_cpu_IPI",
+        "dtrace_register",
+        "dtrace_suspend",
+    };
+    for (unsigned i = 0; i < RT_ELEMENTS(s_apszSyms); i++)
+    {
+        uintptr_t uPtr = rtR0DarwinMachKernelLookup(pKernel, s_apszSyms[i]);
+        RTTestIPrintf(RTTESTLVL_ALWAYS, "%p %s\n", uPtr, s_apszSyms[i]);
+        RTTESTI_CHECK(uPtr != 0);
+    }
+    rtR0DarwinMachKernelClose(pKernel);
 }
 
