Index: /trunk/kStuff/Config.kmk
===================================================================
--- /trunk/kStuff/Config.kmk	(revision 3597)
+++ /trunk/kStuff/Config.kmk	(revision 3598)
@@ -63,4 +63,19 @@
 TEMPLATE_kStuff_ASFLAGS.win.amd64= -f win64 -g cv8
 
+TEMPLATE_kStuff_CFLAGS.darwin    = -g -fno-common
+TEMPLATE_kStuff_CFLAGS.freebsd   = -g
+TEMPLATE_kStuff_CFLAGS.linux     = -g
+TEMPLATE_kStuff_CFLAGS.os2       = -g
+TEMPLATE_kStuff_CFLAGS.win       = -Zi -Zl -MD -W3 -GF -GR-
+ifneq ($(BUILD_TYPE),debug)
+TEMPLATE_kStuff_CFLAGS.freebsd  += -O3
+TEMPLATE_kStuff_CFLAGS.linux    += -O3
+TEMPLATE_kStuff_CFLAGS.os2      += -O3
+TEMPLATE_kStuff_CFLAGS.win      += -O2xtg -Oi -Ob2
+else
+TEMPLATE_kStuff_CFLAGS.win      += -Od
+endif
+
+TEMPLATE_kStuff_CXXFLAGS.darwin  = -g -fno-common
 TEMPLATE_kStuff_CXXFLAGS.freebsd = -g
 TEMPLATE_kStuff_CXXFLAGS.linux   = -g
Index: /trunk/kStuff/include/k/kCpu.h
===================================================================
--- /trunk/kStuff/include/k/kCpu.h	(revision 3597)
+++ /trunk/kStuff/include/k/kCpu.h	(revision 3598)
@@ -53,6 +53,6 @@
 #endif
 
-KCPU_DECL(void)     kCpuGetArchAndCpu(PKCPUARCH penmArch, PKCPU penmCpu);
-KCPU_DECL(KBOOL)    kCpuCompare(KCPUARCH enmCodeArch, KCPU enmCodeCpu, KCPUARCH enmArch, KCPU enmCpu);
+KCPU_DECL(void) kCpuGetArchAndCpu(PKCPUARCH penmArch, PKCPU penmCpu);
+KCPU_DECL(int)  kCpuCompare(KCPUARCH enmCodeArch, KCPU enmCodeCpu, KCPUARCH enmArch, KCPU enmCpu);
 
 #ifdef __cplusplus
Index: /trunk/kStuff/include/k/kDefs.h
===================================================================
--- /trunk/kStuff/include/k/kDefs.h	(revision 3597)
+++ /trunk/kStuff/include/k/kDefs.h	(revision 3598)
@@ -75,4 +75,6 @@
 # elif defined(__FreeBSD__) /*??*/
 #  define K_OS      K_OS_FREEBSD
+# elif defined(__gnu_linux__)
+#  define K_OS      K_OS_LINUX
 # elif defined(__NetBSD__) /*??*/
 #  define K_OS      K_OS_NETBSD
Index: /trunk/kStuff/kCpu/kCpuCompare.c
===================================================================
--- /trunk/kStuff/kCpu/kCpuCompare.c	(revision 3597)
+++ /trunk/kStuff/kCpu/kCpuCompare.c	(revision 3598)
@@ -44,5 +44,5 @@
  * @param   enmCpu      The cpu to run it on.
  */
-KCPU_DECL(KBOOL) kCpuCompare(KCPUARCH enmCodeArch, KCPU enmCodeCpu, KCPUARCH enmArch, KCPU enmCpu)
+KCPU_DECL(int) kCpuCompare(KCPUARCH enmCodeArch, KCPU enmCodeCpu, KCPUARCH enmArch, KCPU enmCpu)
 {
     /*
Index: /trunk/kStuff/kDbg/kDbgModWinDbgHelp.cpp
===================================================================
--- /trunk/kStuff/kDbg/kDbgModWinDbgHelp.cpp	(revision 3597)
+++ /trunk/kStuff/kDbg/kDbgModWinDbgHelp.cpp	(revision 3598)
@@ -470,4 +470,5 @@
         DWORD Err = GetLastError();
         int rc = kdbgModDHConvWinError(Err);
+        InterlockedExchange(&s_lLock, 0);
         kDbgAssertMsgFailedReturn(("Failed to load '%s', Err=%d rc=%d\n", szPath, Err, rc), rc);
     }
@@ -521,5 +522,4 @@
             if (!rc)
             {
-                //InterlockedExchange(&g_hDbgHelp, hmod);
                 g_hDbgHelp = hmod;
                 Sleep(1);
Index: /trunk/kStuff/kDbg/kDbgModule.cpp
===================================================================
--- /trunk/kStuff/kDbg/kDbgModule.cpp	(revision 3597)
+++ /trunk/kStuff/kDbg/kDbgModule.cpp	(revision 3598)
@@ -43,8 +43,6 @@
 #if K_OS == K_OS_WINDOWS
     &g_kDbgModWinDbgHelpOpen,
-#else
-#error huh?s
 #endif
-//    &g_kDbgModLdr,
+    &g_kDbgModLdr,
 //    &g_kDbgModCv8,
 //    &g_kDbgModDwarf,
Index: /trunk/kStuff/kLdr/Makefile.kmk
===================================================================
--- /trunk/kStuff/kLdr/Makefile.kmk	(revision 3597)
+++ /trunk/kStuff/kLdr/Makefile.kmk	(revision 3598)
@@ -147,7 +147,7 @@
 kLdrStatic_SDKS.win = WINPSDK W2K3DDK
 kLdrStatic_INCS := $(PATH_SUB_CURRENT) $(PATH_SUB_ROOT)/include
+kLdrStatic_DEFS.darwin = __DARWIN__
+kLdrStatic_DEFS.os2 = __OS2__
 kLdrStatic_DEFS.win = __WIN__
-kLdrStatic_DEFS.os2 = __OS2__
-kLdrStatic_DEFS.darwin = __DARWIN__
 kLdrStatic_SOURCES = $(kLdr_SOURCES)
 
Index: /trunk/kStuff/kLdr/kLdrDyldFind.c
===================================================================
--- /trunk/kStuff/kLdr/kLdrDyldFind.c	(revision 3597)
+++ /trunk/kStuff/kLdr/kLdrDyldFind.c	(revision 3598)
@@ -304,5 +304,10 @@
     if (!kLdrDyldAppDir[0])
     {
-#if defined(__OS2__)
+#if K_OS == K_OS_DARWIN
+        /** @todo implement this! */
+        kLdrDyldWindowsAppDir[0] = kLdrDyldAppDir[0] = '.';
+        kLdrDyldWindowsAppDir[1] = kLdrDyldAppDir[1] = '\0';
+
+#elif K_OS == K_OS_OS2
         PPIB pPib;
         PTIB pTib;
@@ -791,5 +796,8 @@
      */
     if (*penmSearch == KLDRDYLD_SEARCH_HOST)
-#if defined(__OS2__)
+#if K_OS == K_OS_DARWIN
+        /** @todo *penmSearch = KLDRDYLD_SEARCH_DARWIN; */
+        *penmSearch = KLDRDYLD_SEARCH_UNIX_COMMON;
+#elif K_OS == K_OS_OS2
         *penmSearch = KLDRDYLD_SEARCH_OS2;
 #elif K_OS == K_OS_WINDOWS
Index: /trunk/kStuff/kLdr/kLdrDyldOS.c
===================================================================
--- /trunk/kStuff/kLdr/kLdrDyldOS.c	(revision 3597)
+++ /trunk/kStuff/kLdr/kLdrDyldOS.c	(revision 3598)
@@ -43,5 +43,6 @@
 
 #else
-# error "port me"
+# include <k/kHlpAlloc.h>
+
 #endif
 
@@ -76,5 +77,12 @@
 
 #else
-# error "Port me"
+    void *pv;
+
+    if (!cb)
+        cb = 1 * 1024*1024; /* 1MB */
+
+    if (!kHlpPageAlloc(&pv, cb, KPROT_READWRITE, K_FALSE))
+        return pv;
+    return NULL;
 #endif
 }
@@ -92,7 +100,5 @@
 int kldrDyldOSStartExe(KUPTR uMainEPAddress, void *pvStack, KSIZE cbStack)
 {
-#if defined(__OS2__)
-
-#elif K_OS == K_OS_WINDOWS
+#if K_OS == K_OS_WINDOWS
     /*
      * Invoke the entrypoint on the current stack for now.
@@ -109,8 +115,4 @@
     for (;;)
         TerminateProcess(GetCurrentProcess(), rc);
-
-/*#elif defined(__NT__)*/
-#else
-# error "Port me"
 #endif
 
@@ -126,2 +128,3 @@
     kldrDyldDoLoadExe(pExe);
 }
+
Index: /trunk/kStuff/kLdr/kLdrDyldSem.c
===================================================================
--- /trunk/kStuff/kLdr/kLdrDyldSem.c	(revision 3597)
+++ /trunk/kStuff/kLdr/kLdrDyldSem.c	(revision 3598)
@@ -31,11 +31,17 @@
 #include <k/kDefs.h>
 #include <k/kHlpSem.h>
+#include <k/kHlpAssert.h>
 
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+# include <mach/mach.h>
+
+#elif K_OS == K_OS_OS2
 # define INCL_BASE
 # define INCL_ERRORS
 # include <os2.h>
+
 #elif  K_OS == K_OS_WINDOWS
 # include <Windows.h>
+
 #else
 # error "port me"
@@ -47,5 +53,9 @@
 *   Global Variables                                                           *
 *******************************************************************************/
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+/** The loader sempahore. */
+static semaphore_t      g_Semaphore = MACH_PORT_NULL;
+
+#elif K_OS == K_OS_OS2
 /** The loader sempahore. */
 static HMTX             g_hmtx;
@@ -54,4 +64,5 @@
 /** The loader sempahore. */
 static CRITICAL_SECTION g_CritSect;
+
 #else
 # error "port me"
@@ -64,7 +75,14 @@
  * @returns 0 on success, non-zero OS status code on failure.
  */
-int     kLdrDyldSemInit(void)
+int kLdrDyldSemInit(void)
 {
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+    kern_return_t krc;
+
+    krc = semaphore_create(mach_task_self(), &g_Semaphore, SYNC_POLICY_FIFO, 0);
+    if (krc != KERN_SUCCESS)
+        return krc;
+
+#elif K_OS == K_OS_OS2
     APIRET rc;
     g_hmtx = NULLHANDLE;
@@ -86,7 +104,14 @@
  * Terminates the loader semaphore.
  */
-void    kLdrDyldSemTerm(void)
+void kLdrDyldSemTerm(void)
 {
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+    kern_return_t krc;
+    semaphore_t Semaphore = g_Semaphore;
+    g_Semaphore = MACH_PORT_NULL;
+    krc = semaphore_destroy(mach_task_self(), Semaphore);
+    kHlpAssert(krc == KERN_SUCCESS); (void)krc;
+
+#elif K_OS == K_OS_OS2
     HMTX hmtx = g_hmtx;
     g_hmtx = NULLHANDLE;
@@ -108,7 +133,16 @@
  * @returns 0 on success, non-zero OS status code on failure.
  */
-int     kLdrDyldSemRequest(void)
+int kLdrDyldSemRequest(void)
 {
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+    /* not sure about this... */
+    kern_return_t krc;
+    do krc = semaphore_wait(g_Semaphore);
+    while (krc == KERN_ABORTED);
+    if (krc == KERN_SUCCESS)
+        return 0;
+    return krc;
+
+#elif K_OS == K_OS_OS2
     APIRET rc = DosRequestMutexSem(g_hmtx, 5000);
     if (rc == ERROR_TIMEOUT || rc == ERROR_SEM_TIMEOUT || rc == ERROR_INTERRUPT)
@@ -140,7 +174,12 @@
  * The caller is responsible for making sure it's the semaphore owner!
  */
-void    kLdrDyldSemRelease(void)
+void kLdrDyldSemRelease(void)
 {
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+    /* not too sure about this... */
+    kern_return_t krc = semaphore_signal(g_Semaphore);
+    kHlpAssert(krc == KERN_SUCCESS); (void)krc;
+
+#elif K_OS == K_OS_OS2
     APIRET rc = DosReleaseMutexSem(g_hmtx);
     kHlpAssert(!rc); (void)rc;
@@ -152,5 +191,4 @@
 # error "port me"
 #endif
-
 }
 
