Index: trunk/kStuff/kHlp/Bare/kHlpBare-gcc.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBare-gcc.c	(revision 3593)
+++ trunk/kStuff/kHlp/Bare/kHlpBare-gcc.c	(revision 3594)
@@ -142,6 +142,9 @@
         KUPTR   u = ch | (ch << 8);
         u |= u << 16;
-#if defined(__AMD64__)
+#if K_ARCH_BITS >= 64
         u |= u << 32;
+#endif
+#if K_ARCH_BITS >= 128
+        u |= u << 64;
 #endif
 
Index: trunk/kStuff/kHlp/Bare/kHlpBareAssert.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBareAssert.c	(revision 3593)
+++ trunk/kStuff/kHlp/Bare/kHlpBareAssert.c	(revision 3594)
@@ -31,5 +31,8 @@
 #include <k/kHlpString.h>
 
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+extern kHlpSys_write(int fd, const void *buf, KSIZE);
+
+#elif K_OS == K_OS_OS2
 # define INCL_BASE
 # define INCL_ERRORS
@@ -51,5 +54,9 @@
 static void kHlpAssertWrite(const char *pszMsg)
 {
-#if K_OS == K_OS_OS2 ||  K_OS == K_OS_WINDOWS
+#if K_OS == K_OS_DARWIN
+    KSIZE cchMsg = kHlpStrLen(pszMsg);
+    kHlpSys_write(2 /* stderr */, pszMsg, cchMsg);
+
+#elif K_OS == K_OS_OS2 ||  K_OS == K_OS_WINDOWS
     /*
      * Line by line.
Index: trunk/kStuff/kHlp/Bare/kHlpBareEnv.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBareEnv.c	(revision 3593)
+++ trunk/kStuff/kHlp/Bare/kHlpBareEnv.c	(revision 3594)
@@ -32,10 +32,14 @@
 #include <k/kErrors.h>
 
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+
+#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"
@@ -45,5 +49,9 @@
 KHLP_DECL(int) kHlpGetEnv(const char *pszVar, char *pszVal, KSIZE cchVal)
 {
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+    /** @todo need to figure out where the stuff is or how it's inherited on darwin ... */
+    return KERR_ENVVAR_NOT_FOUND;
+
+#elif K_OS == K_OS_OS2
     PSZ pszValue = NULL;
     int rc;
Index: trunk/kStuff/kHlp/Bare/kHlpBareHeap.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBareHeap.c	(revision 3593)
+++ trunk/kStuff/kHlp/Bare/kHlpBareHeap.c	(revision 3594)
@@ -38,8 +38,10 @@
 # define INCL_ERRORS
 # include <os2.h>
+
 #elif  K_OS == K_OS_WINDOWS
 # include <Windows.h>
+
 #else
-# error "port me"
+# include <k/kHlpAlloc.h>
 #endif
 
@@ -716,5 +718,16 @@
 
 #else
-# error "Port me"
+    int rc;
+
+    pSeg->cb = (cbMin + 0xffff) & ~(KSIZE)0xffff;
+    pSeg->pvBase = NULL;
+    rc = kHlpPageAlloc(&pSeg->pvBase, pSeg->cb, KPROT_READWRITE, K_FALSE);
+    if (rc)
+    {
+        pSeg->pvBase = NULL;
+        pSeg->cb = 0;
+        return rc;
+    }
+
 #endif
 
@@ -739,5 +752,7 @@
 
 #else
-# error "Port me"
+    int rc = kHlpPageFree(pSeg->pvBase, pSeg->cb);
+    KHLPHEAP_ASSERT(!rc); (void)rc;
+
 #endif
 }
Index: trunk/kStuff/kHlp/Bare/kHlpBareProcess.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBareProcess.c	(revision 3593)
+++ trunk/kStuff/kHlp/Bare/kHlpBareProcess.c	(revision 3594)
@@ -31,5 +31,8 @@
 #include <k/kHlpAssert.h>
 
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+extern void kHlpSys_exit(int rc);
+
+#elif K_OS == K_OS_OS2
 # define INCL_BASE
 # define INCL_ERRORS
@@ -51,5 +54,8 @@
     for (;;)
     {
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+        kHlpSys_exit(rc);
+
+#elif K_OS == K_OS_OS2
         DosExit(EXIT_PROCESS, rc);
 
Index: trunk/kStuff/kHlp/Bare/kHlpBareThread.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBareThread.c	(revision 3593)
+++ trunk/kStuff/kHlp/Bare/kHlpBareThread.c	(revision 3594)
@@ -30,5 +30,7 @@
 #include <k/kHlpThread.h>
 
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+
+#elif K_OS == K_OS_OS2
 # define INCL_BASE
 # define INCL_ERRORS
@@ -48,4 +50,7 @@
 {
 #if K_OS == K_OS_OS2
+    /** @todo mach_wait_until, see gen/nanosleep.c. */
+
+#elif K_OS == K_OS_OS2
     DosSleep(cMillies);
 #elif  K_OS == K_OS_WINDOWS
Index: trunk/kStuff/kHlp/Generic/kHlpPage.c
===================================================================
--- trunk/kStuff/kHlp/Generic/kHlpPage.c	(revision 3593)
+++ trunk/kStuff/kHlp/Generic/kHlpPage.c	(revision 3594)
@@ -31,10 +31,19 @@
 #include <k/kHlpAssert.h>
 
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+# include <sys/syscall.h>
+# include <sys/mman.h>
+extern void *kHlpSys_mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off);
+extern int kHlpSys_mprotect(void *addr, size_t len, int prot);
+extern int kHlpSys_munmap(void *addr, size_t len);
+
+#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"
@@ -45,5 +54,12 @@
 *   Global Variables                                                           *
 *******************************************************************************/
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN \
+ || K_OS == K_OS_FREEBSD \
+ || K_OS == K_OS_LINUX \
+ || K_OS == K_OS_NETBSD \
+ || K_OS == K_OS_OPENBSD \
+ || K_OS == K_OS_SOLARIS
+/* nothing */
+#elif K_OS == K_OS_OS2
 /** The base of the loader stub object. <kLdr Hack>
  * The OS/2 exe stub consists of a single data object. When allocating memory
@@ -62,5 +78,27 @@
 
 
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN \
+ || K_OS == K_OS_FREEBSD \
+ || K_OS == K_OS_LINUX \
+ || K_OS == K_OS_NETBSD \
+ || K_OS == K_OS_OPENBSD \
+ || K_OS == K_OS_SOLARIS
+static int kHlpPageProtToNative(KPROT enmProt)
+{
+    switch (enmProt)
+    {
+        case KPROT_NOACCESS:             return PROT_NONE;
+        case KPROT_READONLY:             return PROT_READ;
+        case KPROT_READWRITE:            return PROT_READ | PROT_WRITE;
+        case KPROT_EXECUTE:              return PROT_EXEC;
+        case KPROT_EXECUTE_READ:         return PROT_EXEC | PROT_READ;
+        case KPROT_EXECUTE_READWRITE:    return PROT_EXEC | PROT_READ | PROT_WRITE;
+        default:
+            kHlpAssert(0);
+            return ~0U;
+    }
+}
+
+#elif K_OS == K_OS_OS2
 static ULONG kHlpPageProtToNative(KPROT enmProt)
 {
@@ -97,4 +135,5 @@
 
 
+
 /**
  * Allocate a chunk of memory with page granularity.
@@ -108,7 +147,20 @@
 KHLP_DECL(int) kHlpPageAlloc(void **ppv, KSIZE cb, KPROT enmProt, KBOOL fFixed)
 {
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+    void *pv;
+
+    pv = kHlpSys_mmap(fFixed ? *ppv : NULL, cb, kHlpPageProtToNative(enmProt),
+                      fFixed ? MAP_FIXED | MAP_ANON: MAP_ANON, -1, 0);
+    if ((KIPTR)pv < 256)
+    {
+        kHlpAssert(0);
+        return (int)(KIPTR)pv; /** @todo convert errno to kErrors */
+    }
+    *ppv = pv;
+    return 0;
+
+#elif K_OS == K_OS_OS2
     APIRET  rc;
-    ULONG   fFlags = kHlpPageProtToNative(enmProt);;
+    ULONG   fFlags = kHlpPageProtToNative(enmProt);
 
     if (!fFixed)
@@ -163,7 +215,17 @@
 KHLP_DECL(int) kHlpPageProtect(void *pv, KSIZE cb, KPROT enmProt)
 {
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+    int rc;
+
+    rc = kHlpSys_mprotect(pv, cb, kHlpPageProtToNative(enmProt));
+    if (!rc)
+        return 0;
+    /** @todo convert errno -> kErrors */
+    kHlpAssert(0);
+    return rc;
+
+#elif K_OS == K_OS_OS2
     APIRET      rc;
-    ULONG       fFlags = kHlpPageProtToNative(enmProt);;
+    ULONG       fFlags = kHlpPageProtToNative(enmProt);
 
     /*
@@ -216,5 +278,14 @@
 KHLP_DECL(int) kHlpPageFree(void *pv, KSIZE cb)
 {
-#if K_OS == K_OS_OS2
+#if K_OS == K_OS_DARWIN
+    int rc;
+
+    rc = kHlpSys_munmap(pv, cb);
+    if (!rc)
+        return 0;
+    /** @todo convert errno -> kErrors */
+    return rc;
+
+#elif K_OS == K_OS_OS2
     APIRET rc;
 
