Index: /trunk/kLdr/kLdrModNative.c
===================================================================
--- /trunk/kLdr/kLdrModNative.c	(revision 2972)
+++ /trunk/kLdr/kLdrModNative.c	(revision 2973)
@@ -60,4 +60,8 @@
 #include <winnt.h> */
 
+#elif defined(__DARWIN__)
+# include <dlfcn.h>
+# include <errno.h>
+
 #else
 # error "port me"
@@ -122,4 +126,9 @@
     /** Pointer to the section header array. */
     const IMAGE_SECTION_HEADER *paShdrs;
+
+#elif defined(__DARWIN__)
+    /** The dlopen() handle.*/
+    void                       *pvMod;
+
 #else
 # error "Port me"
@@ -191,4 +200,14 @@
         FreeLibrary(hmod);
 
+#elif defined(__DARWIN__)
+    void *pvMod;
+
+    pvMod = dlopen(pszFilename, 0);
+    if (!pvMod)
+        return ENOENT;
+    rc = kLdrModOpenNativeByHandle((uintptr_t)pvMod, ppMod);
+    if (rc)
+        dlclose(pvMod);
+
 #else
 # error "Port me"
@@ -269,4 +288,8 @@
     cSegments = pNtHdrs->FileHeader.NumberOfSections + 1;
     paShdrs = (const IMAGE_SECTION_HEADER *)(pNtHdrs + 1);
+
+#elif defined(__DARWIN__)
+    char    szFilename[1] = "";
+    cSegments = 0; /** @todo Figure out the Mac OS X dynamic loader. */
 
 #else
@@ -473,4 +496,7 @@
     }
 
+#elif defined(__DARWIN__)
+    /** @todo Figure out the Mac OS X dynamic loader. */
+
 #else
 # error "Port me"
@@ -493,4 +519,5 @@
 #ifdef __OS2__
     rc = DosFreeModule(pModNative->hmod);
+
 #elif defined(__WIN__)
     if (FreeLibrary(pModNative->hmod))
@@ -498,4 +525,8 @@
     else
         rc = GetLastError();
+
+#elif defined(__DARWIN__)
+    dlclose(pModNative->pvMod);
+
 #else
 # error "Port me"
@@ -521,4 +552,6 @@
 #elif defined(__WIN__)
     FARPROC pfn;
+#elif defined(__DARWIN__)
+    void *pfn;
 #else
 # error "Port me"
@@ -577,4 +610,17 @@
                 | KLDRSYMKIND_NO_TYPE;
 
+#elif defined(__DARWIN__)
+    if (!pszSymbol && iSymbol != NIL_KLDRMOD_SYM_ORDINAL)
+        return KLDR_ERR_SYMBOL_NOT_FOUND;
+
+    pfn = dlsym(pModNative->pvMod, pszSymbol);
+    if (!pfn)
+        return KLDR_ERR_SYMBOL_NOT_FOUND;
+    if (puValue)
+        *puValue = (uintptr_t)pfn;
+    if (pfKind)
+        *pfKind = (sizeof(uintptr_t) == 4 ? KLDRSYMKIND_32BIT : KLDRSYMKIND_64BIT)
+                | KLDRSYMKIND_NO_TYPE;
+
 #else
 # error "Port me"
@@ -668,4 +714,9 @@
     return 0;
 
+#elif defined(__DARWIN__)
+    /** @todo implement enumeration on darwin. */
+    (void)pModNative;
+    return KLDR_ERR_TODO;
+
 #else
 # error "Port me"
@@ -681,5 +732,5 @@
 #ifdef __OS2__
 
-    /** @todo implement export enumeration on OS/2. */
+    /** @todo implement import enumeration on OS/2. */
     (void)pModNative;
     return ERROR_NOT_SUPPORTED;
@@ -721,4 +772,9 @@
     return rc;
 
+#elif defined(__DARWIN__)
+    /** @todo Implement import enumeration on darwin. */
+    (void)pModNative;
+    return KLDR_ERR_TODO;
+
 #else
 # error "Port me"
@@ -733,5 +789,5 @@
 #ifdef __OS2__
 
-    /** @todo implement export enumeration on OS/2. */
+    /** @todo implement import counting on OS/2. */
     (void)pModNative;
     return -1;
@@ -761,4 +817,9 @@
     return pModNative->cImportModules;
 
+#elif defined(__DARWIN__)
+    /** @todo Implement import counting on Darwin. */
+    (void)pModNative;
+    return -1;
+
 #else
 # error "Port me"
@@ -773,5 +834,5 @@
 #ifdef __OS2__
 
-    /** @todo implement export enumeration on OS/2. */
+    /** @todo implement stack info on OS/2. */
     (void)pModNative;
     return ERROR_NOT_SUPPORTED;
@@ -784,4 +845,9 @@
     return 0;
 
+#elif defined(__DARWIN__)
+    /** @todo Implement stack info on Darwin. */
+    (void)pModNative;
+    return KLDR_ERR_TODO;
+
 #else
 # error "Port me"
@@ -796,5 +862,5 @@
 #ifdef __OS2__
 
-    /** @todo implement export enumeration on OS/2. */
+    /** @todo implement me on OS/2. */
     (void)pModNative;
     return ERROR_NOT_SUPPORTED;
@@ -809,4 +875,9 @@
     return 0;
 
+#elif defined(__DARWIN__)
+    /** @todo Implement me on Darwin. */
+    (void)pModNative;
+    return KLDR_ERR_TODO;
+
 #else
 # error "Port me"
@@ -821,5 +892,5 @@
 #ifdef __OS2__
 
-    /** @todo implement export enumeration on OS/2. */
+    /** @todo implement me on OS/2. */
     (void)pModNative;
     return ERROR_NOT_SUPPORTED;
@@ -884,4 +955,9 @@
     return rc;
 
+#elif defined(__DARWIN__)
+    /** @todo Implement me on Darwin. */
+    (void)pModNative;
+    return KLDR_ERR_TODO;
+
 #else
 # error "Port me"
@@ -896,5 +972,5 @@
 #ifdef __OS2__
 
-    /** @todo implement export enumeration on OS/2. */
+    /** @todo implement me on OS/2. */
     (void)pModNative;
     return KLDR_ERR_NO_DEBUG_INFO;
@@ -909,4 +985,10 @@
         return KLDR_ERR_NO_DEBUG_INFO;
     return 0;
+
+#elif defined(__DARWIN__)
+    /** @todo Implement me on Darwin. */
+    (void)pModNative;
+    return KLDR_ERR_NO_DEBUG_INFO;
+
 #else
 # error "Port me"
@@ -988,4 +1070,8 @@
     return pModNative->pNtHdrs->OptionalHeader.SizeOfImage;
 
+#elif defined(__DARWIN__)
+    /** @todo Implement me on Darwin. */
+    return 0;
+
 #else
 # error "Port me"
@@ -1002,4 +1088,8 @@
 #elif defined(__WIN__) || defined(__NT__)
     return ERROR_NOT_SUPPORTED; /* don't bother even if we could implement this. */
+
+#elif defined(__DARWIN__)
+    return KLDR_ERR_TODO; /* don't bother. */
+
 #else
 # error "Port me"
@@ -1017,4 +1107,8 @@
 #elif defined(__WIN__) || defined(__NT__)
     return ERROR_NOT_SUPPORTED; /* don't bother even if we could implement this. */
+
+#elif defined(__DARWIN__)
+    return KLDR_ERR_TODO; /* don't bother. */
+
 #else
 # error "Port me"
