Index: trunk/kStuff/include/k/kErrors.h
===================================================================
--- trunk/kStuff/include/k/kErrors.h	(revision 3572)
+++ trunk/kStuff/include/k/kErrors.h	(revision 3573)
@@ -38,5 +38,5 @@
  */
 /** The base of the general status codes. */
-#define KERR_GENERAL_BASE                               (KERR_BASE )
+#define KERR_GENERAL_BASE                               (KERR_BASE)
 /** Generic error. */
 #define KERR_GENERAL_FAILURE                            (KERR_GENERAL_BASE + 1)
@@ -45,4 +45,8 @@
 /** Hit some unimplemented functionality - feel free to implement it :-) . */
 #define KERR_NOT_IMPLEMENTED                            (KERR_GENERAL_BASE + 3)
+/** An environment variable wasn't found. */
+#define KERR_ENVVAR_NOT_FOUND                           (KERR_GENERAL_BASE + 4)
+/** Buffer overflow. */
+#define KERR_BUFFER_OVERFLOW                            (KERR_GENERAL_BASE + 5)
 /** @}*/
 
@@ -51,5 +55,5 @@
  */
 /** The base of the input validation status codes. */
-#define KERR_INPUT_BASE                                 (KERR_GENERAL_BASE + 4)
+#define KERR_INPUT_BASE                                 (KERR_GENERAL_BASE + 6)
 /** An API was given an invalid parameter. */
 #define KERR_INVALID_PARAMETER                          (KERR_INPUT_BASE + 0)
Index: trunk/kStuff/include/k/kHlp.h
===================================================================
--- trunk/kStuff/include/k/kHlp.h	(revision 3573)
+++ trunk/kStuff/include/k/kHlp.h	(revision 3573)
@@ -0,0 +1,49 @@
+/* $Id$ */
+/** @file
+ * kHlp - Helpers, All Of Them.
+ */
+
+/*
+ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * This file is part of kStuff.
+ *
+ * kStuff is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * kStuff is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with kStuff; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef ___k_kHlp_h___
+#define ___k_kHlp_h___
+
+#include <k/kDefs.h>
+#include <k/kTypes.h>
+#include <k/kErrors.h>
+#include <k/kHlpAlloc.h>
+#include <k/kHlpAssert.h>
+#include <k/kHlpEnv.h>
+#include <k/kHlpPath.h>
+#include <k/kHlpProcess.h>
+#include <k/kHlpSem.h>
+#include <k/kHlpString.h>
+#include <k/kHlpThread.h>
+
+/** @defgroup grp_kHlp  kHlp - Helper Functions
+ * @{ */
+
+/** @} */
+
+#endif
+
+
Index: trunk/kStuff/include/k/kHlpAlloc.h
===================================================================
--- trunk/kStuff/include/k/kHlpAlloc.h	(revision 3572)
+++ trunk/kStuff/include/k/kHlpAlloc.h	(revision 3573)
@@ -61,4 +61,8 @@
 KHLP_DECL(int)      kHlpPageFree(void *pv, KSIZE cb);
 
+KHLP_DECL(int)      kHlpHeapInit(void);
+KHLP_DECL(void)     kHlpHeapTerm(void);
+KHLP_DECL(void)     kHlpHeapDonate(void *pv, KSIZE cb);
+
 #ifdef __cplusplus
 }
Index: trunk/kStuff/include/k/kHlpEnv.h
===================================================================
--- trunk/kStuff/include/k/kHlpEnv.h	(revision 3573)
+++ trunk/kStuff/include/k/kHlpEnv.h	(revision 3573)
@@ -0,0 +1,51 @@
+/* $Id$ */
+/** @file
+ * kHlpEnv - Environment Manipulation.
+ */
+
+/*
+ * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * This file is part of kStuff.
+ *
+ * kStuff is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * kStuff is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with kStuff; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef ___k_kHlpEnv_h___
+#define ___k_kHlpEnv_h___
+
+#include <k/kHlpDefs.h>
+#include <k/kTypes.h>
+
+/** @defgroup grp_kHlpEnv kHlpEnv - Environment Manipulation
+ * @addtogroup grp_kHlp
+ * @{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+KHLP_DECL(int)  kHlpGetEnv(const char *pszVar, char *pszVal, KSIZE cchVal);
+KHLP_DECL(int)  kHlpGetEnvUZ(const char *pszVar, KSIZE *pcb);
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @} */
+
+#endif
+
Index: trunk/kStuff/include/k/kHlpPath.h
===================================================================
--- trunk/kStuff/include/k/kHlpPath.h	(revision 3573)
+++ trunk/kStuff/include/k/kHlpPath.h	(revision 3573)
@@ -0,0 +1,53 @@
+/* $Id$ */
+/** @file
+ * kHlpPath - Path Manipulation.
+ */
+
+/*
+ * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * This file is part of kStuff.
+ *
+ * kStuff is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * kStuff is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with kStuff; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef ___k_kHlpPath_h___
+#define ___k_kHlpPath_h___
+
+#include <k/kHlpDefs.h>
+#include <k/kTypes.h>
+
+/** @defgroup grp_kHlpPath kHlpPath - Path Manipulation
+ * @addtogroup grp_kHlp
+ * @{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+KHLP_DECL(char *)  kHlpGetFilename(const char *pszFilename);
+KHLP_DECL(char *)  kHlpGetSuff(const char *pszFilename);
+KHLP_DECL(char *)  kHlpGetExt(const char *pszFilename);
+KHLP_DECL(int)     kHlpIsFilenameOnly(const char *pszFilename);
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @} */
+
+#endif
+
Index: trunk/kStuff/include/k/kHlpProcess.h
===================================================================
--- trunk/kStuff/include/k/kHlpProcess.h	(revision 3573)
+++ trunk/kStuff/include/k/kHlpProcess.h	(revision 3573)
@@ -0,0 +1,50 @@
+/* $Id$ */
+/** @file
+ * kHlpProcess - Process Management.
+ */
+
+/*
+ * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * This file is part of kStuff.
+ *
+ * kStuff is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * kStuff is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with kStuff; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef ___k_kHlpProcess_h___
+#define ___k_kHlpProcess_h___
+
+#include <k/kHlpDefs.h>
+#include <k/kTypes.h>
+
+/** @defgroup grp_kHlpProcess   kHlpProcess - Process Management
+ * @addtogroup grp_kHlp
+ * @{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+KHLP_DECL(void) kHlpExit(int rc);
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @} */
+
+#endif
+
Index: trunk/kStuff/include/k/kHlpSem.h
===================================================================
--- trunk/kStuff/include/k/kHlpSem.h	(revision 3573)
+++ trunk/kStuff/include/k/kHlpSem.h	(revision 3573)
@@ -0,0 +1,54 @@
+/* $Id$ */
+/** @file
+ * kHlpSem - Semaphores.
+ */
+
+/*
+ * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * This file is part of kStuff.
+ *
+ * kStuff is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * kStuff is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with kStuff; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef ___k_kHlpSem_h___
+#define ___k_kHlpSem_h___
+
+#include <k/kHlpDefs.h>
+#include <k/kTypes.h>
+
+/** @defgroup grp_kHlpSem kHlpSem - Semaphore
+ * @addtogroup grp_kHlp
+ * @{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+KHLP_DECL(int)  kHlpSemInit(void);
+KHLP_DECL(void) kHlpSemTerm(void);
+KHLP_DECL(int)  kHlpSemRequest(void);
+KHLP_DECL(void) kHlpSemRelease(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @} */
+
+#endif
+
+
Index: trunk/kStuff/include/k/kHlpString.h
===================================================================
--- trunk/kStuff/include/k/kHlpString.h	(revision 3572)
+++ trunk/kStuff/include/k/kHlpString.h	(revision 3573)
@@ -28,5 +28,5 @@
 #define ___k_kHlpString_h___
 
-#include <k/kDefs.h>
+#include <k/kHlpDefs.h>
 #include <k/kTypes.h>
 
@@ -118,4 +118,6 @@
 int     kHlpStrIComp(const char *pv1, const char *pv2);
 
+KHLP_DECL(char *)   kHlpInt2Ascii(char *psz, KSIZE cch, long lVal, unsigned iBase);
+
 #ifdef __cplusplus
 }
Index: trunk/kStuff/include/k/kHlpThread.h
===================================================================
--- trunk/kStuff/include/k/kHlpThread.h	(revision 3573)
+++ trunk/kStuff/include/k/kHlpThread.h	(revision 3573)
@@ -0,0 +1,51 @@
+/* $Id$ */
+/** @file
+ * kHlpThread - Thread Manipulation.
+ */
+
+/*
+ * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * This file is part of kStuff.
+ *
+ * kStuff is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * kStuff is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with kStuff; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef ___k_kHlpThread_h___
+#define ___k_kHlpThread_h___
+
+#include <k/kHlpDefs.h>
+#include <k/kTypes.h>
+
+/** @defgroup grp_kHlpThread kHlpThread - Thread Management
+ * @addtogroup grp_kHlp
+ * @{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+KHLP_DECL(void)    kHlpSleep(unsigned cMillies);
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @} */
+
+#endif
+
+
Index: trunk/kStuff/include/k/kLdr.h
===================================================================
--- trunk/kStuff/include/k/kLdr.h	(revision 3572)
+++ trunk/kStuff/include/k/kLdr.h	(revision 3573)
@@ -1019,4 +1019,5 @@
                               const char *pszName, KU32 idLang, PFNKLDRENUMRSRC pfnCallback, void *pvUser);
 
+
 /** @name OS/2 like API
  * @{ */
@@ -1116,5 +1117,6 @@
 typedef const KLDREXEARGS *PCKLDREXEARGS;
 
-void kLdrLoadExe(PCKLDREXEARGS pArgs, void *pvOS);
+void kLdrLoadExe(PCKLDREXEARGS pArgs, void *pvOS); /** @todo fix this mess... */
+void kLdrDyldLoadExe(PCKLDREXEARGS pArgs, void *pvOS);
 
 /** @} */
Index: trunk/kStuff/kHlp/Bare/kHlpBare-gcc.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBare-gcc.c	(revision 3573)
+++ trunk/kStuff/kHlp/Bare/kHlpBare-gcc.c	(revision 3573)
@@ -0,0 +1,216 @@
+/* $Id$ */
+/** @file
+ *
+ * kLdr - The Dynamic Loader, Helper Functions for GCC.
+ *
+ * Copyright (c) 2006 knut st. osmundsen <bird@anduin.net>
+ *
+ *
+ * This file is part of kLdr.
+ *
+ * kLdr is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * kLdr is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with kLdr; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include <k/kLdr.h>
+#include "kHlp.h"
+
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+
+
+void *memchr(const void *pv, int ch, KSIZE cb)
+{
+    const char *pb = pv;
+    while (cb-- > 0)
+    {
+        if (*pb == ch)
+            return (void *)pb;
+        pb++;
+    }
+    return 0;
+}
+
+
+int memcmp(const void *pv1, const void *pv2, KSIZE cb)
+{
+    /*
+     * Pointer size pointer size.
+     */
+    if (    cb > 16
+        &&  !((KUPTR)pv1 & (sizeof(void *) - 1))
+        &&  !((KUPTR)pv2 & (sizeof(void *) - 1)) )
+    {
+        const KUPTR *pu1 = pv1;
+        const KUPTR *pu2 = pv2;
+        while (cb >= sizeof(KUPTR))
+        {
+            const KUPTR u1 = *pu1++;
+            const KUPTR u2 = *pu2++;
+            if (u1 != u2)
+                return u1 > u2 ? 1 : -1;
+            cb -= sizeof(KUPTR);
+        }
+        if (!cb)
+            return 0;
+        pv1 = (const void *)pu1;
+        pv2 = (const void *)pu2;
+    }
+
+    /*
+     * Byte by byte.
+     */
+    if (cb)
+    {
+        const unsigned char *pb1 = pv1;
+        const unsigned char *pb2 = pv2;
+        while (cb-- > 0)
+        {
+            const unsigned char b1 = *pb1++;
+            const unsigned char b2 = *pb2++;
+            if (b1 != b2)
+                return b1 > b2 ? 1 : -1;
+        }
+    }
+    return 0;
+}
+
+
+void *memcpy(void *pv1, const void *pv2, KSIZE cb)
+{
+    void *pv1Start = pv1;
+
+    /*
+     * Pointer size pointer size.
+     */
+    if (    cb > 16
+        &&  !((KUPTR)pv1 & (sizeof(void *) - 1))
+        &&  !((KUPTR)pv2 & (sizeof(void *) - 1)) )
+    {
+        KUPTR       *pu1 = pv1;
+        const KUPTR *pu2 = pv2;
+        while (cb >= sizeof(KUPTR))
+        {
+            cb -= sizeof(KUPTR);
+            *pu1++ = *pu2++;
+        }
+        if (!cb)
+            return 0;
+        pv1 = (void *)pu1;
+        pv2 = (const void *)pu2;
+    }
+
+    /*
+     * byte by byte
+     */
+    if (cb)
+    {
+        unsigned char       *pb1 = pv1;
+        const unsigned char *pb2 = pv2;
+        while (cb-- > 0)
+            *pb1++ = *pb2++;
+    }
+
+    return pv1Start;
+}
+
+void *memset(void *pv, int ch, KSIZE cb)
+{
+    void *pvStart = pv;
+
+    /*
+     * Pointer size pointer size.
+     */
+    if (    cb > 16
+        &&  !((KUPTR)pv & (sizeof(void *) - 1)))
+    {
+        KUPTR  *pu = pv;
+        KUPTR   u = ch | (ch << 8);
+        u |= u << 16;
+#if defined(__AMD64__)
+        u |= u << 32;
+#endif
+
+        while (cb >= sizeof(KUPTR))
+        {
+            cb -= sizeof(KUPTR);
+            *pu++ = u;
+        }
+    }
+
+    /*
+     * Byte by byte
+     */
+    if (cb)
+    {
+        unsigned char *pb = pv;
+        while (cb-- > 0)
+            *pb++ = ch;
+    }
+    return pvStart;
+}
+
+
+int strcmp(const char *psz1, const char *psz2)
+{
+    for (;;)
+    {
+        const char ch1 = *psz1++;
+        const char ch2 = *psz2++;
+        if (ch1 != ch2)
+            return (int)ch1 - (int)ch2;
+        if (!ch1)
+            return 0;
+    }
+}
+
+
+int strncmp(const char *psz1, const char *psz2, KSIZE cch)
+{
+    while (cch-- > 0)
+    {
+        const char ch1 = *psz1++;
+        const char ch2 = *psz2++;
+        if (ch1 != ch2)
+            return (int)ch1 - (int)ch2;
+        if (!ch1)
+            break;
+    }
+    return 0;
+}
+
+char *strchr(const char *psz, int ch)
+{
+    for (;;)
+    {
+        const char chCur = *psz;
+        if (chCur == ch)
+            return (char *)psz;
+        if (!chCur)
+            return 0;
+        psz++;
+    }
+}
+
+KSIZE strlen(const char *psz)
+{
+    const char *pszStart = psz;
+    while (*psz)
+        psz++;
+    return psz - pszStart;
+}
+
Index: trunk/kStuff/kHlp/Bare/kHlpBareAssert.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBareAssert.c	(revision 3573)
+++ trunk/kStuff/kHlp/Bare/kHlpBareAssert.c	(revision 3573)
@@ -0,0 +1,115 @@
+/* $Id$ */
+/** @file
+ * kHlpBare - Assert Backend.
+ */
+
+/*
+ * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * This file is part of kStuff.
+ *
+ * kStuff is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * kStuff is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with kStuff; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <k/kHlpAssert.h>
+#include <k/kHlpString.h>
+
+#if 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"
+#endif
+
+
+/**
+ * Writes a assert string with unix lineendings.
+ *
+ * @param   pszMsg  The string.
+ */
+static void kHlpAssertWrite(const char *pszMsg)
+{
+#if K_OS == K_OS_OS2 ||  K_OS == K_OS_WINDOWS
+    /*
+     * Line by line.
+     */
+    ULONG       cbWritten;
+    const char *pszNl = kHlpStrChr(pszMsg, '\n');
+    while (pszNl)
+    {
+        cbWritten = pszNl - pszMsg;
+
+#if K_OS == K_OS_OS2
+        if (cbWritten)
+            DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
+        DosWrite((HFILE)2, "\r\n", 2, &cbWritten);
+#else /* __WIN32__ */
+        if (cbWritten)
+            WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
+        WriteFile((HANDLE)STD_ERROR_HANDLE, "\r\n", 2, &cbWritten, NULL);
+#endif
+
+        /* next */
+        pszMsg = pszNl + 1;
+        pszNl = kHlpStrChr(pszMsg, '\n');
+    }
+
+    /*
+     * Remaining incomplete line.
+     */
+    if (*pszMsg)
+    {
+        cbWritten = kHlpStrLen(pszMsg);
+#if K_OS == K_OS_OS2
+        DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
+#else /* __WIN32__ */
+        WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
+#endif
+    }
+
+#else
+# error "port me"
+#endif
+}
+
+
+KHLP_DECL(void) kHlpAssertMsg1(const char *pszExpr, const char *pszFile, unsigned iLine, const char *pszFunction)
+{
+    char szLine[16];
+
+    kHlpAssertWrite("\n!!!kLdr Assertion Failed!!!\nExpression: ");
+    kHlpAssertWrite(pszExpr);
+    kHlpAssertWrite("\nAt: ");
+    kHlpAssertWrite(pszFile);
+    kHlpAssertWrite("(");
+    kHlpAssertWrite(kHlpInt2Ascii(szLine, sizeof(szLine), iLine, 10));
+    kHlpAssertWrite(") ");
+    kHlpAssertWrite(pszFunction);
+    kHlpAssertWrite("\n");
+}
+
+
+KHLP_DECL(void) kHlpAssertMsg2(const char *pszFormat, ...)
+{
+    kHlpAssertWrite(pszFormat);
+}
+
Index: trunk/kStuff/kHlp/Bare/kHlpBareEnv.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBareEnv.c	(revision 3573)
+++ trunk/kStuff/kHlp/Bare/kHlpBareEnv.c	(revision 3573)
@@ -0,0 +1,166 @@
+/* $Id$ */
+/** @file
+ * kHlpBare - Environment Manipulation.
+ */
+
+/*
+ * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * This file is part of kStuff.
+ *
+ * kStuff is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * kStuff is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with kStuff; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <k/kHlpEnv.h>
+#include <k/kHlpString.h>
+#include <k/kErrors.h>
+
+#if 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"
+#endif
+
+
+/**
+ * Get an environment variable.
+ *
+ * @returns 0 on success.
+ * @returns KERR_BUFFER_OVERFLOW on if the buffer is too small.
+ * @returns KERR_ENVVAR_NOT_FOUND if not found.
+ * @returns OS specfic status code on other error.
+ * @param   pszVar      The variable name.
+ * @param   pszVal      Where to store the value.
+ * @param   cchVal      The size of the buffer pointed to by pszVal.
+ */
+int     kHlpGetEnv(const char *pszVar, char *pszVal, KSIZE cchVal)
+{
+#if K_OS == K_OS_OS2
+    PSZ pszValue = NULL;
+    int rc;
+
+    *pszVal = '\0';
+    rc = DosScanEnv((PCSZ)pszVar, &pszValue);
+    if (!rc)
+    {
+        KSIZE  cch = kHlpStrLen((const char *)pszValue);
+        if (cchVal > cch)
+            kHlpMemCopy(pszVal, pszValue, cch + 1);
+        else
+            rc = KERR_BUFFER_OVERFLOW;
+    }
+    else
+        rc = KERR_ENV_VAR_NOT_FOUND;
+    return rc;
+
+#elif  K_OS == K_OS_WINDOWS
+    DWORD cch;
+
+    SetLastError(0);
+    cch = GetEnvironmentVariable(pszVar, pszVal, cchVal);
+    if (cch > 0 && cch < cchVal)
+        return 0;
+
+    *pszVal = '\0';
+    if (cch >= cchVal)
+        return KERR_BUFFER_OVERFLOW;
+    if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
+        return KERR_ENVVAR_NOT_FOUND;
+    return GetLastError();
+
+#else
+# error "Port me"
+#endif
+}
+
+
+/**
+ * Gets an environment variable and converts it to a KSIZE.
+ *
+ * @returns 0 and *pcb on success.
+ * @returns On failure see kHlpGetEnv.
+ * @param   pszVar  The name of the variable.
+ * @param   pcb     Where to put the value.
+ */
+int     kHlpGetEnvUZ(const char *pszVar, KSIZE *pcb)
+{
+    KSIZE       cb;
+    unsigned    uBase;
+    char        szVal[64];
+    KSIZE       cchVal = sizeof(szVal);
+    const char *psz;
+    int         rc;
+
+    *pcb = 0;
+    rc = kHlpGetEnv(pszVar, szVal, cchVal);
+    if (rc)
+        return rc;
+
+    /* figure out the base. */
+    uBase = 10;
+    psz = szVal;
+    if (    *psz == '0'
+        &&  (psz[1] == 'x' || psz[1] == 'X'))
+    {
+        uBase = 16;
+        psz += 2;
+    }
+
+    /* convert it up to the first unknown char. */
+    cb = 0;
+    for(;;)
+    {
+        const char ch = *psz;
+        unsigned uDigit;
+        if (!ch)
+            break;
+        else if (ch >= '0' && ch <= '9')
+            uDigit = ch - '0';
+        else if (ch >= 'a' && ch <= 'z')
+            uDigit = ch - 'a' + 10;
+        else if (ch >= 'A' && ch <= 'Z')
+            uDigit = ch - 'A' + 10;
+        else
+            break;
+        if (uDigit >= uBase)
+            break;
+
+        /* add the digit */
+        cb *= uBase;
+        cb += uDigit;
+
+        psz++;
+    }
+
+    /* check for unit */
+    if (*psz == 'm' || *psz == 'M')
+        cb *= 1024*1024;
+    else if (*psz == 'k' ||*psz == 'K')
+        cb *= 1024;
+    else if (*psz == 'g' || *psz == 'G')
+        cb *= 1024*1024*1024;
+
+    *pcb = cb;
+    return 0;
+}
+
Index: trunk/kStuff/kHlp/Bare/kHlpBareHeap.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBareHeap.c	(revision 3573)
+++ trunk/kStuff/kHlp/Bare/kHlpBareHeap.c	(revision 3573)
@@ -0,0 +1,703 @@
+/* $Id$ */
+/** @file
+ * kHlpBare - Heap.
+ */
+
+/*
+ * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * This file is part of kStuff.
+ *
+ * kStuff is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * kStuff is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with kStuff; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#define KLDRHEAP_STRICT
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <k/kHlpAlloc.h>
+
+#if 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"
+#endif
+
+
+/*******************************************************************************
+*   Structures and Typedefs                                                    *
+*******************************************************************************/
+/**
+ * A heap block.
+ */
+typedef struct KLDRHEAPBLOCK
+{
+    /** Next block in the global list. */
+    struct KLDRHEAPBLOCK   *pNext;
+    /** Previous block in the global list. */
+    struct KLDRHEAPBLOCK   *pPrev;
+    /** The size of this block including this header. */
+    KSIZE                   cb;
+    /** The flags. */
+    KSIZE                   fFlags;
+} KLDRHEAPBLOCK, *PKLDRHEAPBLOCK;
+
+/** Indicates whether the block is free (set) or allocated (clear). */
+#define KLDRHEAPBLOCK_FLAG_FREE     ((KSIZE)1)
+/** Valid flag mask. */
+#define KLDRHEAPBLOCK_FLAG_MASK     ((KSIZE)1)
+
+/** Checks if the block is freed. */
+#define KLDRHEAPBLOCK_IS_FREE(pB)       ( (pB)->fFlags & KLDRHEAPBLOCK_FLAG_FREE )
+/** Check if the block is allocated. */
+#define KLDRHEAPBLOCK_IS_ALLOCATED(pB)  !KLDRHEAPBLOCK_IS_FREE(pB)
+/** Checks if the two blocks are adjacent.
+ * Assumes pB1 < pB2. */
+#define KLDRHEAPBLOCK_IS_ADJACENT(pB1, pB2) \
+    ( ((KUPTR)(pB1) + (pB1)->cb) == (KUPTR)(pB2) )
+
+/** The block alignment. */
+#define KLDRHEAPBLOCK_ALIGNMENT     sizeof(KLDRHEAPBLOCK)
+
+/** @def KLDRHEAP_ASSERT
+ * Heap assertion. */
+/** @def KLDRHEAP_ASSERT_BLOCK
+ * Assert that a heap block is valid. */
+/** @def KLDRHEAP_ASSERT_FREE
+ * Assert that a heap free block is valid. */
+#ifdef KLDRHEAP_STRICT
+# define KLDRHEAP_ASSERT(expr)      kHlpAssert(expr)
+
+# define KLDRHEAP_ASSERT_BLOCK(pHeap, pBlock) \
+    do { \
+        KLDRHEAP_ASSERT(!((pBlock)->fFlags & ~KLDRHEAPBLOCK_FLAG_MASK)); \
+        KLDRHEAP_ASSERT(!((pBlock)->cb & (KLDRHEAPBLOCK_ALIGNMENT - 1))); \
+        KLDRHEAP_ASSERT((KUPTR)(pBlock)->pPrev < (KUPTR)(pBlock)); \
+        KLDRHEAP_ASSERT((KUPTR)(pBlock)->pNext > (KUPTR)(pBlock) || !(pBlock)->pNext); \
+    } while (0)
+
+# define KLDRHEAP_ASSERT_FREE(pHeap, pFree) \
+    do { \
+        KLDRHEAP_ASSERT_BLOCK(pHeap, &(pFree)->Core); \
+        KLDRHEAP_ASSERT((KUPTR)(pFree)->pPrev < (KUPTR)(pFree)); \
+        KLDRHEAP_ASSERT((KUPTR)(pFree)->pNext > (KUPTR)(pFree) || !(pFree)->pNext); \
+    } while (0)
+
+#else
+# define KLDRHEAP_ASSERT(expr)          do { } while (0)
+# define KLDRHEAP_ASSERT_BLOCK(pH, pB)  do { } while (0)
+# define KLDRHEAP_ASSERT_FREE(pH, pF)   do { } while (0)
+#endif
+
+
+/**
+ * A free heap block.
+ */
+typedef struct KLDRHEAPFREE
+{
+    /** The core bit which we have in common with used blocks. */
+    KLDRHEAPBLOCK           Core;
+    /** The next free block. */
+    struct KLDRHEAPFREE    *pNext;
+    /** The previous free block. */
+    struct KLDRHEAPFREE    *pPrev;
+} KLDRHEAPFREE, *PKLDRHEAPFREE;
+
+
+/**
+ * A heap segment.
+ */
+typedef struct KLDRHEAPSEG
+{
+    /** The base address of the segment. */
+    void   *pvBase;
+    /** The length of the segment (in bytes). */
+    KSIZE   cb;
+} KLDRHEAPSEG, *PKLDRHEAPSEG;
+
+/**
+ * Bundle of heap segments.
+ */
+typedef struct KLDRHEAPSEGS
+{
+    /** Pointer to the next segment bundle. */
+    struct KLDRHEAPSEGS    *pNext;
+    /** The number of segments used. */
+    KU32                    cSegs;
+    /** Array of chunks. */
+    KLDRHEAPSEG             aSegs[64];
+} KLDRHEAPSEGS, *PKLDRHEAPSEGS;
+
+
+/**
+ * Heap anchor block.
+ */
+typedef struct KLDRHEAPANCHOR
+{
+    /** Head of the block list. */
+    PKLDRHEAPBLOCK      pHead;
+    /** Tail of the block list. */
+    PKLDRHEAPBLOCK      pTail;
+    /** Head of the free list. */
+    PKLDRHEAPFREE       pFreeHead;
+    /** Head segment bundle.
+     * The order of this list is important, but a bit peculiar.
+     * Logically, SegsHead::pNext is the tail pointer. */
+    KLDRHEAPSEGS        SegsHead;
+} KLDRHEAPANCHOR, *PKLDRHEAPANCHOR;
+
+
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+/** The heap anchor block. */
+static KLDRHEAPANCHOR g_Heap;
+
+
+/*******************************************************************************
+*   Internal Functions                                                         *
+*******************************************************************************/
+static int      kLdrHeapInit(PKLDRHEAPANCHOR pHeap);
+static void     kLdrHeapDelete(PKLDRHEAPANCHOR pHeap);
+static void *   kLdrHeapAlloc(PKLDRHEAPANCHOR pHeap, KSIZE cb);
+static void     kLdrHeapFree(PKLDRHEAPANCHOR pHeap, void *pv);
+static void     kLdrHeapDonate(PKLDRHEAPANCHOR pHeap, void *pv, KSIZE cb);
+static int      kLdrHeapSegAlloc(PKLDRHEAPSEG pSeg, KSIZE cb);
+static void     kLdrHeapSegFree(PKLDRHEAPSEG pSeg);
+
+
+/**
+ * Initializes the kLdr heap.
+ *
+ * @returns 0 on success, non-zero OS specific status code on failure.
+ */
+KHLP_DECL(int) kHlpHeapInit(void)
+{
+    return kLdrHeapInit(&g_Heap);
+}
+
+
+/**
+ * Terminates the kLdr heap.
+ */
+KHLP_DECL(void) kHlpHeapTerm(void)
+{
+    kLdrHeapDelete(&g_Heap);
+}
+
+
+/**
+ * Allocates memory from the kLdr heap.
+ *
+ * @returns Pointer to the allocated heap block. NULL if we can't satify the request.
+ * @param   cb      The requested heap block size.
+ */
+KHLP_DECL(void *) kHlpAlloc(KSIZE cb)
+{
+    return kLdrHeapAlloc(&g_Heap, cb);
+}
+
+
+/**
+ * Allocates zero initialized memory from the kLdr heap.
+ *
+ * @returns Pointer to the allocated heap block. NULL if we can't satify the request.
+ * @param   cb      The requested heap block size.
+ */
+KHLP_DECL(void *) kHlpAllocZ(KSIZE cb)
+{
+    void *pv = kLdrHeapAlloc(&g_Heap, cb);
+    if (pv)
+        kHlpMemSet(pv, 0, cb);
+    return pv;
+}
+
+
+/**
+ * Frees memory allocated off the kLdr heap.
+ *
+ * @param   pv      Pointer to the heap block returned by kHlpAlloc().
+ */
+KHLP_DECL(void) kHlpFree(void *pv)
+{
+    kLdrHeapFree(&g_Heap, pv);
+}
+
+
+/**
+ * Donates memory to the heap.
+ *
+ * @param   pv      The address of the memory.
+ * @param   cb      The amount of memory.
+ */
+KHLP_DECL(void) kHlpHeapDonate(void *pv, KSIZE cb)
+{
+    kLdrHeapDonate(&g_Heap, pv, cb);
+}
+
+
+
+/**
+ * Initializes the heap anchor.
+ *
+ * @returns 0 on success, non-zero on failure.
+ * @param   pHeap   The heap anchor to be initialized.
+ */
+static int kLdrHeapInit(PKLDRHEAPANCHOR pHeap)
+{
+    pHeap->pHead = NULL;
+    pHeap->pTail = NULL;
+    pHeap->pFreeHead = NULL;
+    pHeap->SegsHead.pNext = NULL;
+    pHeap->SegsHead.cSegs = 0;
+    return 0;
+}
+
+
+/**
+ * Deletes a heap.
+ * This will free all resources (memory) associated with the heap.
+ *
+ * @param   pHeap   The heap to be deleted.
+ */
+static void kLdrHeapDelete(PKLDRHEAPANCHOR pHeap)
+{
+    /*
+     * Free the segments, LIFO order.
+     * The head element is the last to be free, while the
+     * head.pNext is really the tail pointer - neat or what?
+     */
+    while (     pHeap->SegsHead.cSegs
+           ||   pHeap->SegsHead.pNext)
+    {
+        /* find the tail. */
+        KU32            iSeg;
+        PKLDRHEAPSEGS   pSegs = pHeap->SegsHead.pNext;
+        if (!pSegs)
+            pSegs = &pHeap->SegsHead;
+        else
+        {
+            pHeap->SegsHead.pNext = pSegs->pNext;
+            pSegs->pNext = NULL;
+        }
+
+        /* free the segments */
+        iSeg = pSegs->cSegs;
+        while (iSeg-- > 0)
+            kLdrHeapSegFree(&pSegs->aSegs[iSeg]);
+        pSegs->cSegs = 0;
+    }
+
+    /* Zap the anchor. */
+    pHeap->pHead = NULL;
+    pHeap->pTail = NULL;
+    pHeap->pFreeHead = NULL;
+    pHeap->SegsHead.pNext = NULL;
+    pHeap->SegsHead.cSegs = 0;
+}
+
+
+/**
+ * Internal heap block allocator.
+ */
+static void *   kldrHeapAllocSub(PKLDRHEAPANCHOR pHeap, KSIZE cb)
+{
+    /*
+     * Find a fitting free block.
+     */
+    const KSIZE     cbReq = K_ALIGN_Z(cb + sizeof(KLDRHEAPBLOCK), KLDRHEAPBLOCK_ALIGNMENT);
+    PKLDRHEAPFREE   pCur = pHeap->pFreeHead;
+    while (pCur)
+    {
+        if (pCur->Core.cb >= cbReq)
+        {
+            if (pCur->Core.cb != cbReq)
+            {
+                /* check and see if there is a better match close by. */
+                PKLDRHEAPFREE pCur2 = pCur->pNext;
+                unsigned i = 16;
+                while (i-- > 0 && pCur2)
+                {
+                    if (pCur2->Core.cb >= cbReq)
+                    {
+                        if (pCur2->Core.cb == cbReq)
+                        {
+                            pCur = pCur2;
+                            break;
+                        }
+                        if (pCur2->Core.cb < pCur->Core.cb)
+                            pCur = pCur2;
+                    }
+
+                    /* next */
+                    KLDRHEAP_ASSERT_FREE(pHeap, pCur2);
+                    pCur2 = pCur2->pNext;
+                }
+            }
+            break;
+        }
+
+        /* next */
+        KLDRHEAP_ASSERT_FREE(pHeap, pCur);
+        pCur = pCur->pNext;
+    }
+    if (!pCur)
+        return NULL;
+    KLDRHEAP_ASSERT_FREE(pHeap, pCur);
+
+    /*
+     * Do we need to split out a block?
+     */
+    if (pCur->Core.cb - cbReq >= KLDRHEAPBLOCK_ALIGNMENT * 2)
+    {
+        PKLDRHEAPBLOCK pNew;
+
+        pCur->Core.cb -= cbReq;
+
+        pNew = (PKLDRHEAPBLOCK)((KUPTR)pCur + pCur->Core.cb);
+        pNew->fFlags = 0;
+        pNew->cb = cbReq;
+        pNew->pNext = pCur->Core.pNext;
+        if (pNew->pNext)
+            pNew->pNext->pPrev = pNew;
+        else
+            pHeap->pTail = pNew;
+        pNew->pPrev = &pCur->Core;
+        pCur->Core.pNext = pNew;
+
+        KLDRHEAP_ASSERT_FREE(pHeap, pCur);
+        KLDRHEAP_ASSERT_BLOCK(pHeap, pNew);
+        return pNew + 1;
+    }
+
+    /*
+     * No, just unlink it from the free list and return.
+     */
+    if (pCur->pNext)
+        pCur->pNext->pPrev = pCur->pPrev;
+    if (pCur->pPrev)
+        pCur->pPrev->pNext = pCur->pNext;
+    else
+        pHeap->pFreeHead = pCur->pNext;
+    pCur->Core.fFlags &= ~KLDRHEAPBLOCK_FLAG_FREE;
+
+    KLDRHEAP_ASSERT_BLOCK(pHeap, &pCur->Core);
+    return &pCur->Core + 1;
+}
+
+
+/**
+ * Allocate a heap block.
+ *
+ * @returns Pointer to the allocated heap block on success. On failure NULL is returned.
+ * @param   pHeap   The heap.
+ * @param   cb      The requested heap block size.
+ */
+static void *   kLdrHeapAlloc(PKLDRHEAPANCHOR pHeap, KSIZE cb)
+{
+    void *pv;
+
+    /* adjust the requested block size. */
+    cb = K_ALIGN_Z(cb, KLDRHEAPBLOCK_ALIGNMENT);
+    if (!cb)
+        cb = KLDRHEAPBLOCK_ALIGNMENT;
+
+    /* try allocate the block. */
+    pv = kldrHeapAllocSub(pHeap, cb);
+    if (!pv)
+    {
+        /*
+         * Failed, add another segment and try again.
+         */
+        KLDRHEAPSEG Seg;
+        if (kLdrHeapSegAlloc(&Seg, cb + sizeof(KLDRHEAPSEGS) + sizeof(KLDRHEAPBLOCK) * 16))
+            return NULL;
+
+        /* donate before insterting the segment, this makes sure we got heap to expand the segment list. */
+        kLdrHeapDonate(pHeap, Seg.pvBase, Seg.cb);
+
+        /* insert the segment. */
+        if (pHeap->SegsHead.cSegs < sizeof(pHeap->SegsHead.aSegs) / sizeof(pHeap->SegsHead.aSegs[0]))
+            pHeap->SegsHead.aSegs[pHeap->SegsHead.cSegs++] = Seg;
+        else if (   pHeap->SegsHead.pNext
+                 && pHeap->SegsHead.pNext->cSegs < sizeof(pHeap->SegsHead.aSegs) / sizeof(pHeap->SegsHead.aSegs[0]))
+            pHeap->SegsHead.pNext->aSegs[pHeap->SegsHead.pNext->cSegs++] = Seg;
+        else
+        {
+            PKLDRHEAPSEGS pSegs = (PKLDRHEAPSEGS)kldrHeapAllocSub(pHeap, sizeof(*pSegs));
+            KLDRHEAP_ASSERT(pSegs);
+            pSegs->pNext = pHeap->SegsHead.pNext;
+            pHeap->SegsHead.pNext = pSegs;
+            pSegs->aSegs[0] = Seg;
+            pSegs->cSegs = 1;
+        }
+
+        /* retry (should succeed) */
+        pv = kldrHeapAllocSub(pHeap, cb);
+        KLDRHEAP_ASSERT(pv);
+    }
+
+    return pv;
+}
+
+
+/**
+ * Frees a heap block.
+ *
+ * @param   pHeap   The heap.
+ * @param   pv      The pointer returned by kLdrHeapAlloc().
+ */
+static void     kLdrHeapFree(PKLDRHEAPANCHOR pHeap, void *pv)
+{
+    PKLDRHEAPFREE pFree, pLeft, pRight;
+
+    /* ignore NULL pointers. */
+    if (!pv)
+        return;
+
+    pFree = (PKLDRHEAPFREE)((PKLDRHEAPBLOCK)pv - 1);
+    KLDRHEAP_ASSERT_BLOCK(pHeap, &pFree->Core);
+    KLDRHEAP_ASSERT(KLDRHEAPBLOCK_IS_ALLOCATED(&pFree->Core));
+
+    /*
+     * Merge or link with left node?
+     */
+    pLeft = (PKLDRHEAPFREE)pFree->Core.pPrev;
+    if (    pLeft
+        &&  KLDRHEAPBLOCK_IS_FREE(&pLeft->Core)
+        &&  KLDRHEAPBLOCK_IS_ADJACENT(&pLeft->Core, &pFree->Core)
+       )
+    {
+        /* merge left */
+        pLeft->Core.pNext = pFree->Core.pNext;
+        if (pFree->Core.pNext)
+            pFree->Core.pNext->pPrev = &pLeft->Core;
+        else
+            pHeap->pTail = &pLeft->Core;
+
+        pLeft->Core.cb += pFree->Core.cb;
+        pFree->Core.fFlags = ~0;
+        pFree = pLeft;
+    }
+    else
+    {
+        /* link left */
+        while (pLeft && !KLDRHEAPBLOCK_IS_FREE(&pLeft->Core))
+            pLeft = (PKLDRHEAPFREE)pLeft->Core.pPrev;
+        if (pLeft)
+        {
+            pFree->pPrev = pLeft;
+            pFree->pNext = pLeft->pNext;
+            if (pLeft->pNext)
+                pLeft->pNext->pPrev = pFree;
+            pLeft->pNext  = pFree;
+        }
+        else
+        {
+            pFree->pPrev = NULL;
+            pFree->pNext = pHeap->pFreeHead;
+            if (pHeap->pFreeHead)
+                pHeap->pFreeHead->pPrev = pFree;
+            pHeap->pFreeHead = pFree;
+        }
+        pFree->Core.fFlags |= KLDRHEAPBLOCK_FLAG_FREE;
+    }
+    KLDRHEAP_ASSERT_FREE(pHeap, pFree);
+
+    /*
+     * Merge right?
+     */
+    pRight = (PKLDRHEAPFREE)pFree->Core.pNext;
+    if (    pRight
+        &&  KLDRHEAPBLOCK_IS_FREE(&pRight->Core)
+        &&  KLDRHEAPBLOCK_IS_ADJACENT(&pFree->Core, pRight)
+       )
+    {
+        /* unlink pRight from the global list. */
+        pFree->Core.pNext = pRight->Core.pNext;
+        if (pRight->Core.pNext)
+            pRight->Core.pNext->pPrev = &pFree->Core;
+        else
+            pHeap->pTail = &pFree->Core;
+
+        /* unlink pRight from the free list. */
+        pFree->pNext = pRight->pNext;
+        if (pRight->pNext)
+            pRight->pNext->pPrev = pFree;
+
+        /* update size and invalidate pRight. */
+        pFree->Core.cb += pRight->Core.cb;
+        pRight->Core.fFlags = ~0;
+    }
+}
+
+
+/**
+ * Donates memory to the heap.
+ *
+ * The donated memory is returned to the donator when the heap is deleted.
+ *
+ * @param pHeap The heap
+ * @param pv    The pointer to the donated memory.
+ * @param cb    Size of the donated memory.
+ */
+static void     kLdrHeapDonate(PKLDRHEAPANCHOR pHeap, void *pv, KSIZE cb)
+{
+    PKLDRHEAPBLOCK pBlock;
+
+    /*
+     * Don't bother with small donations.
+     */
+    if (cb < KLDRHEAPBLOCK_ALIGNMENT * 4)
+        return;
+
+    /*
+     * Align the donation on a heap block boundrary.
+     */
+    if ((KUPTR)pv & (KLDRHEAPBLOCK_ALIGNMENT - 1))
+    {
+        cb -= (KUPTR)pv & 31;
+        pv = K_ALIGN_P(pv, KLDRHEAPBLOCK_ALIGNMENT);
+    }
+    cb &= ~(KSIZE)(KLDRHEAPBLOCK_ALIGNMENT - 1);
+
+    /*
+     * Create an allocated block, link it and free it.
+     */
+    pBlock = (PKLDRHEAPBLOCK)pv;
+    pBlock->pNext = NULL;
+    pBlock->pPrev = NULL;
+    pBlock->cb = cb;
+    pBlock->fFlags = 0;
+
+    /* insert */
+    if ((KUPTR)pBlock < (KUPTR)pHeap->pHead)
+    {
+        /* head */
+        pBlock->pNext = pHeap->pHead;
+        pHeap->pHead->pPrev = pBlock;
+        pHeap->pHead = pBlock;
+    }
+    else if ((KUPTR)pBlock > (KUPTR)pHeap->pTail)
+    {
+        if (pHeap->pTail)
+        {
+            /* tail */
+            pBlock->pPrev = pHeap->pTail;
+            pHeap->pTail->pNext = pBlock;
+            pHeap->pTail = pBlock;
+        }
+        else
+        {
+            /* first */
+            pHeap->pHead = pBlock;
+            pHeap->pTail = pBlock;
+        }
+    }
+    else
+    {
+        /* in list (unlikely) */
+        PKLDRHEAPBLOCK pPrev = pHeap->pHead;
+        PKLDRHEAPBLOCK pCur = pPrev->pNext;
+        for (;;)
+        {
+            KLDRHEAP_ASSERT_BLOCK(pHeap, pCur);
+            if ((KUPTR)pCur > (KUPTR)pBlock)
+                break;
+            pPrev = pCur;
+            pCur = pCur->pNext;
+        }
+
+        pBlock->pNext = pCur;
+        pBlock->pPrev = pPrev;
+        pPrev->pNext = pBlock;
+        pCur->pPrev = pBlock;
+    }
+    KLDRHEAP_ASSERT_BLOCK(pHeap, pBlock);
+
+    /* free it */
+    kLdrHeapFree(pHeap, pBlock + 1);
+}
+
+
+
+/**
+ * Allocates a new segment.
+ *
+ * @returns 0 on success, non-zero OS status code on failure.
+ * @param   pSeg    Where to put the info about the allocated segment.
+ * @param   cbMin   The minimum segment size.
+ */
+static int kLdrHeapSegAlloc(PKLDRHEAPSEG pSeg, KSIZE cbMin)
+{
+#if K_OS == K_OS_OS2
+    APIRET rc;
+
+    pSeg->cb = (cbMin + 0xffff) & ~(KSIZE)0xffff;
+    pSeg->pvBase = NULL;
+    rc = DosAllocMem(&pSeg->pvBase, pSeg->cb, PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_ANY);
+    if (rc == ERROR_INVALID_PARAMETER)
+        rc = DosAllocMem(&pSeg->pvBase, pSeg->cb, PAG_COMMIT | PAG_READ | PAG_WRITE);
+    if (rc)
+    {
+        pSeg->pvBase = NULL;
+        pSeg->cb = 0;
+        return rc;
+    }
+
+#elif  K_OS == K_OS_WINDOWS
+    pSeg->cb = (cbMin + 0xffff) & ~(KSIZE)0xffff;
+    pSeg->pvBase = VirtualAlloc(NULL, pSeg->cb, MEM_COMMIT, PAGE_READWRITE);
+    if (!pSeg->pvBase)
+    {
+        pSeg->cb = 0;
+        return GetLastError();
+    }
+
+#else
+# error "Port me"
+#endif
+
+    return 0;
+}
+
+
+/**
+ * Frees a segment.
+ *
+ * @param   pSeg    The segment to be freed.
+ */
+static void kLdrHeapSegFree(PKLDRHEAPSEG pSeg)
+{
+#if K_OS == K_OS_OS2
+    APIRET rc = DosFreeMem(pSeg->pvBase);
+    KLDRHEAP_ASSERT(!rc); (void)rc;
+
+#elif  K_OS == K_OS_WINDOWS
+    BOOL fRc = VirtualFree(pSeg->pvBase, 0 /*pSeg->cb*/, MEM_RELEASE);
+    KLDRHEAP_ASSERT(fRc); (void)fRc;
+
+#else
+# error "Port me"
+#endif
+}
+
Index: trunk/kStuff/kHlp/Bare/kHlpBareMem.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBareMem.c	(revision 3573)
+++ trunk/kStuff/kHlp/Bare/kHlpBareMem.c	(revision 3573)
@@ -0,0 +1,278 @@
+/* $Id$ */
+/** @file
+ * kHlp - Generic Page Memory Functions.
+ */
+
+/*
+ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * This file is part of kStuff.
+ *
+ * kStuff is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * kStuff is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with kStuff; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <k/kHlpAlloc.h>
+
+#if 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"
+#endif
+
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+#if K_OS == K_OS_OS2
+/** The base of the stub object.
+ * The OS/2 exe stub consists of a single data object. When allocating memory
+ * for an executable, we'll have to reuse this.  */
+static void            *g_pvStub = NULL;
+/** The size of the stub object - 0 if no stub. */
+static KSIZE            g_cbStub = 0;
+
+#elif  K_OS == K_OS_WINDOWS
+/** The system info. */
+static SYSTEM_INFO      g_SystemInfo;
+#else
+# error "port me"
+#endif
+
+
+
+#if K_OS == K_OS_OS2
+static ULONG kHlpPageProtToNative(KPROT enmProt)
+{
+    switch (enmProt)
+    {
+        case KPROT_NOACCESS:             return PAG_EXECUTE | PAG_READ | PAG_WRITE;
+        case KPROT_READONLY:             return PAG_COMMIT | PAG_READ;
+        case KPROT_READWRITE:            return PAG_COMMIT | PAG_READ | PAG_WRITE;
+        case KPROT_EXECUTE:              return PAG_COMMIT | PAG_EXECUTE;
+        case KPROT_EXECUTE_READ:         return PAG_COMMIT | PAG_EXECUTE | PAG_READ;
+        case KPROT_EXECUTE_READWRITE:    return PAG_COMMIT | PAG_EXECUTE | PAG_READ | PAG_WRITE;
+        default:
+            kHlpAssert(0);
+            return ~0U;
+    }
+}
+#elif  K_OS == K_OS_WINDOWS
+static DWORD kHlpPageProtToNative(KPROT enmProt)
+{
+    switch (enmProt)
+    {
+        case KPROT_NOACCESS:             return PAGE_NOACCESS;
+        case KPROT_READONLY:             return PAGE_READONLY;
+        case KPROT_READWRITE:            return PAGE_READWRITE;
+        case KPROT_EXECUTE:              return PAGE_EXECUTE;
+        case KPROT_EXECUTE_READ:         return PAGE_EXECUTE_READ;
+        case KPROT_EXECUTE_READWRITE:    return PAGE_EXECUTE_READWRITE;
+        default:
+            kHlpAssert(0);
+            return ~0U;
+    }
+}
+#endif
+
+
+/**
+ * Allocate a chunk of memory with page granularity.
+ *
+ * @returns 0 on success, non-zero OS status code on failure.
+ * @param   ppv         Where to store the address of the allocated memory.
+ *                      If fFixed is set, *ppv will on entry contain the desired address (page aligned).
+ * @param   cb          Number of bytes. Page aligned.
+ * @param   enmProt     The new protection. Copy-on-write is invalid.
+ */
+KHLP_DECL(int) kHlpPageAlloc(void **ppv, KSIZE cb, KPROT enmProt, KBOOL fFixed)
+{
+#if K_OS == K_OS_OS2
+    APIRET  rc;
+    ULONG   fFlags = kHlpPageProtToNative(enmProt);;
+
+    if (!fFixed)
+    {
+        /* simple */
+        rc = DosAllocMem(ppv, cb, fFlags | OBJ_ANY);
+        if (rc == ERROR_INVALID_PARAMETER)
+            rc = DosAllocMem(ppv, cb, fFlags);
+    }
+    else
+    {
+        /* not so simple. */
+        /** @todo I've got code for this in libc somewhere. */
+        rc = -1;
+    }
+    if (!rc)
+        return 0;
+    kHlpAssert(0);
+    return rc;
+
+#elif  K_OS == K_OS_WINDOWS
+    /* (We don't have to care about the stub here, because the stub will be unmapped before we get here.) */
+    int     rc;
+    DWORD   fProt = kHlpPageProtToNative(enmProt);
+
+    if (!g_SystemInfo.dwPageSize)
+        GetSystemInfo(&g_SystemInfo);
+
+    *ppv = VirtualAlloc(fFixed ? *ppv : NULL, cb, MEM_COMMIT, fProt);
+    if (*ppv != NULL)
+        return 0;
+    rc = GetLastError();
+    kHlpAssert(0);
+    return rc;
+
+#else
+# error "port me"
+#endif
+}
+
+
+/**
+ * Change the protection of one or more pages in an allocation.
+ *
+ * (This will of course only work correctly on memory allocated by kHlpPageAlloc().)
+ *
+ * @returns 0 on success, non-zero OS status code on failure.
+ * @param   pv          First page. Page aligned.
+ * @param   cb          Number of bytes. Page aligned.
+ * @param   enmProt     The new protection. Copy-on-write is invalid.
+ */
+KHLP_DECL(int) kHlpPageProtect(void *pv, KSIZE cb, KPROT enmProt)
+{
+#if K_OS == K_OS_OS2
+    APIRET      rc;
+    ULONG       fFlags = kHlpPageProtToNative(enmProt);;
+
+    /*
+     * The non-stub pages.
+     */
+    rc = DosSetMem(pv, cb, fFlags);
+    if (rc && fFlags != PAG_DECOMMIT)
+        rc = DosSetMem(pv, cb, fFlags | PAG_COMMIT);
+    if (rc)
+    {
+        /* Try page by page. */
+        while (cb > 0)
+        {
+            rc = DosSetMem(pv, 0x1000, fFlags);
+            if (rc && fFlags != PAG_DECOMMIT)
+                rc = DosSetMem(pv, 0x1000, fFlags | PAG_COMMIT);
+            if (rc)
+                return rc;
+            pv = (void *)((KUPTR)pv + 0x1000);
+            cb -= 0x1000;
+        }
+    }
+    kHlpAssert(!rc);
+    return rc;
+
+#elif  K_OS == K_OS_WINDOWS
+    DWORD fOldProt = 0;
+    DWORD fProt = kHlpPageProtToNative(enmProt);
+    int rc = 0;
+
+    if (!VirtualProtect(pv, cb, fProt, &fOldProt))
+    {
+        rc = GetLastError();
+        kHlpAssert(0);
+    }
+    return rc;
+#else
+# error "port me"
+#endif
+}
+
+
+/**
+ * Free memory allocated by kHlpPageAlloc().
+ *
+ * @returns 0 on success, non-zero OS status code on failure.
+ * @param   pv          The address returned by kHlpPageAlloc().
+ * @param   cb          The byte count requested from kHlpPageAlloc().
+ */
+KHLP_DECL(int) skHlpPageFree(void *pv, KSIZE cb)
+{
+#if K_OS == K_OS_OS2
+    APIRET rc;
+
+    /*
+     * Deal with any portion overlapping with the stub.
+     */
+    KUPTR offStub = (KUPTR)pv - (KUPTR)g_pvStub;
+    if (offStub < g_cbStub)
+    {
+        /* decommit the pages in the stub. */
+        KSIZE cbStub = K_MIN(g_cbStub - offStub, cb);
+        rc = DosSetMem(pv, cbStub, PAG_DECOMMIT);
+        if (rc)
+        {
+            /* Page by page, ignoring errors after the first success. */
+            while (cbStub > 0)
+            {
+                if (!DosSetMem(pv, 0x1000, PAG_DECOMMIT))
+                    rc = 0;
+                pv = (void *)((KUPTR)pv + 0x1000);
+                cbStub -= 0x1000;
+                cb -= 0x1000;
+            }
+            if (rc)
+            {
+                kHlpAssert(!rc);
+                return rc;
+            }
+        }
+        else
+        {
+            cb -= cbStub;
+            if (!cb)
+                return 0;
+            pv = (void *)((KUPTR)pv + cbStub);
+        }
+    }
+
+    /*
+     * Free the object.
+     */
+    rc = DosFreeMem(pv);
+    kHlpAssert(!rc);
+    return rc;
+
+#elif  K_OS == K_OS_WINDOWS
+    /*
+     * Free the object.
+     */
+    int rc = 0;
+    if (!VirtualFree(pv, 0 /*cb*/, MEM_RELEASE))
+    {
+        rc = GetLastError();
+        kHlpAssert(0);
+    }
+    return rc;
+
+#else
+# error "port me"
+#endif
+}
+
Index: trunk/kStuff/kHlp/Bare/kHlpBarePath.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBarePath.c	(revision 3573)
+++ trunk/kStuff/kHlp/Bare/kHlpBarePath.c	(revision 3573)
@@ -0,0 +1,136 @@
+/* $Id$ */
+/** @file
+ *
+ * kLdr - The Dynamic Loader, Path Helper Functions.
+ *
+ * Copyright (c) 2006-2007 knut st. osmundsen <bird-kbuild-src@anduin.net>
+ *
+ *
+ * This file is part of kLdr.
+ *
+ * kLdr is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * kLdr is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with kLdr; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <k/kHlpPath.h>
+#include <k/kHlpString.h>
+
+
+/**
+ * Get the pointer to the filename part of the name.
+ *
+ * @returns Pointer to where the filename starts within the string pointed to by pszFilename.
+ * @returns Pointer to the terminator char if no filename.
+ * @param   pszFilename     The filename to parse.
+ */
+char   *kHlpGetFilename(const char *pszFilename)
+{
+    const char *pszLast = NULL;
+    for (;;)
+    {
+        char ch = *pszFilename;
+#if defined(__OS2__) || defined(__WIN__)
+        if (ch == '/' || ch == '\\' || ch == ':')
+        {
+            while ((ch = *++pszFilename) == '/' || ch == '\\' || ch == ':')
+                /* nothing */;
+            pszLast = pszFilename;
+        }
+#else
+        if (ch == '/')
+        {
+            while ((ch = *++pszFilename) == '/')
+                /* betsuni */;
+            pszLast = pszFilename;
+        }
+#endif
+        if (!ch)
+            return (char *)(pszLast ? pszLast : pszFilename);
+        pszFilename++;
+    }
+}
+
+
+/**
+ * Gets the filename suffix.
+ *
+ * @returns Pointer to where the suffix starts within the string pointed to by pszFilename.
+ * @returns Pointer to the terminator char if no suffix.
+ * @param   pszFilename     The filename to parse.
+ */
+char   *kHlpGetSuff(const char *pszFilename)
+{
+    const char *pszDot = NULL;
+    pszFilename = kHlpGetFilename(pszFilename);
+    for (;;)
+    {
+        char ch = *pszFilename;
+        if (ch == '.')
+        {
+            while ((ch = *++pszFilename) == '.')
+                /* nothing */;
+            if (ch)
+                pszDot = pszFilename - 1;
+        }
+        if (!ch)
+            return (char *)(pszDot ? pszDot : pszFilename);
+        pszFilename++;
+    }
+}
+
+
+/**
+ * Gets the filename extention.
+ *
+ * @returns Pointer to where the extension starts within the string pointed to by pszFilename.
+ * @returns Pointer to the terminator char if no extension.
+ * @param   pszFilename     The filename to parse.
+ */
+char   *kHlpGetExt(const char *pszFilename)
+{
+    char *psz = kHlpGetSuff(pszFilename);
+    return *psz ? psz + 1 : psz;
+}
+
+
+/**
+ * Checks if this is only a filename or if it contains any kind
+ * of drive, directory, or server specs.
+ *
+ * @returns 1 if this is a filename only.
+ * @returns 0 of it's isn't only a filename.
+ * @param   pszFilename     The filename to parse.
+ */
+int kHlpIsFilenameOnly(const char *pszFilename)
+{
+    for (;;)
+    {
+        const char ch = *pszFilename++;
+#if defined(__OS2__) || defined(__WIN__)
+        if (ch == '/' || ch == '\\' || ch == ':')
+#else
+        if (ch == '/')
+#endif
+            return 0;
+        if (!ch)
+            return 1;
+    }
+}
+
+
Index: trunk/kStuff/kHlp/Bare/kHlpBareProcess.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBareProcess.c	(revision 3573)
+++ trunk/kStuff/kHlp/Bare/kHlpBareProcess.c	(revision 3573)
@@ -0,0 +1,65 @@
+/* $Id$ */
+/** @file
+ * kHlpBare - Process Management
+ */
+
+/*
+ * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * This file is part of kStuff.
+ *
+ * kStuff is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * kStuff is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with kStuff; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <k/kHlpProcess.h>
+#include <k/kHlpAssert.h>
+
+#if 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"
+#endif
+
+
+/**
+ * Terminate the process.
+ *
+ * @param   rc      The exit status.
+ */
+void    kHlpExit(int rc)
+{
+    for (;;)
+    {
+#if K_OS == K_OS_OS2
+        DosExit(EXIT_PROCESS, rc);
+
+#elif  K_OS == K_OS_WINDOWS
+        TerminateProcess(GetCurrentProcess(), rc);
+
+#else
+# error "Port me"
+#endif
+        kHlpAssert(!"Impossible");
+    }
+}
+
Index: trunk/kStuff/kHlp/Bare/kHlpBareSem.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBareSem.c	(revision 3573)
+++ trunk/kStuff/kHlp/Bare/kHlpBareSem.c	(revision 3573)
@@ -0,0 +1,156 @@
+/* $Id$ */
+/** @file
+ *
+ * kLdr - The Dynamic Loader, Semaphore Helper Functions.
+ *
+ * Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net>
+ *
+ *
+ * This file is part of kLdr.
+ *
+ * kLdr is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * kLdr is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with kLdr; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <k/kDefs.h>
+#include <k/kHlpSem.h>
+
+#if 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"
+#endif
+
+
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+#if K_OS == K_OS_OS2
+/** The loader sempahore. */
+static HMTX             g_hmtx;
+
+#elif  K_OS == K_OS_WINDOWS
+/** The loader sempahore. */
+static CRITICAL_SECTION g_CritSect;
+#else
+# error "port me"
+#endif
+
+
+/**
+ * Initializes the loader semaphore.
+ *
+ * @returns 0 on success, non-zero OS status code on failure.
+ */
+int     kHlpSemInit(void)
+{
+#if K_OS == K_OS_OS2
+    APIRET rc;
+    g_hmtx = NULLHANDLE;
+    rc = DosCreateMutexSem(NULL, &g_hmtx, 0, FALSE);
+    if (rc)
+        return rc;
+
+#elif  K_OS == K_OS_WINDOWS
+    InitializeCriticalSection(&g_CritSect);
+
+#else
+# error "port me"
+#endif
+    return 0;
+}
+
+
+/**
+ * Terminates the loader semaphore.
+ */
+void    kHlpSemTerm(void)
+{
+#if K_OS == K_OS_OS2
+    HMTX hmtx = g_hmtx;
+    g_hmtx = NULLHANDLE;
+    DosCloseMutexSem(hmtx);
+
+#elif  K_OS == K_OS_WINDOWS
+    DeleteCriticalSection(&g_CritSect);
+
+#else
+# error "port me"
+#endif
+}
+
+
+/**
+ * Requests the loader sempahore ownership.
+ * This can be done recursivly.
+ *
+ * @returns 0 on success, non-zero OS status code on failure.
+ */
+int     kHlpSemRequest(void)
+{
+#if K_OS == K_OS_OS2
+    APIRET rc = DosRequestMutexSem(g_hmtx, 5000);
+    if (rc == ERROR_TIMEOUT || rc == ERROR_SEM_TIMEOUT || rc == ERROR_INTERRUPT)
+    {
+        unsigned i = 0;
+        do
+        {
+            /** @todo check for deadlocks etc. */
+            rc = DosRequestMutexSem(g_hmtx, 1000);
+        } while (   (   rc == ERROR_TIMEOUT
+                     || rc == ERROR_SEM_TIMEOUT
+                     || rc == ERROR_INTERRUPT)
+                 && i++ < 120);
+    }
+    return rc;
+
+#elif  K_OS == K_OS_WINDOWS
+    EnterCriticalSection(&g_CritSect);
+    return 0;
+
+#else
+# error "port me"
+#endif
+}
+
+
+/**
+ * Releases the loader semaphore ownership.
+ * The caller is responsible for making sure it's the semaphore owner!
+ */
+void    kHlpSemRelease(void)
+{
+#if K_OS == K_OS_OS2
+    APIRET rc = DosReleaseMutexSem(g_hmtx);
+    kHlpAssert(!rc); (void)rc;
+
+#elif  K_OS == K_OS_WINDOWS
+    LeaveCriticalSection(&g_CritSect);
+
+#else
+# error "port me"
+#endif
+
+}
+
Index: trunk/kStuff/kHlp/Bare/kHlpBareStr.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBareStr.c	(revision 3573)
+++ trunk/kStuff/kHlp/Bare/kHlpBareStr.c	(revision 3573)
@@ -0,0 +1,144 @@
+/* $Id$ */
+/** @file
+ * kHlpBare - String Manipulation.
+ */
+
+/*
+ * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * This file is part of kStuff.
+ *
+ * kStuff is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * kStuff is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with kStuff; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+KSIZE  kHlpStrNLen(const char *psz, KSIZE cchMax)
+{
+    const char * const pszStart = psz;
+    while (*psz && cchMax--)
+        psz++;
+    return psz - pszStart;
+}
+
+
+int     kHlpMemIComp(const void *pv1, const void *pv2, KSIZE cb)
+{
+    const KU8 *pb1 = (const KU8 *)pv1;
+    const KU8 *pb2 = (const KU8 *)pv2;
+    while (cb-- > 0)
+    {
+        if (*pb1 != *pb2)
+        {
+            const KU8 u1 = *pb1 >= 'a' && *pb1 <= 'z' ? *pb1 - 'a' : *pb1;
+            const KU8 u2 = *pb2 >= 'a' && *pb2 <= 'z' ? *pb2 - 'a' : *pb2;
+            if (u1 != u2)
+                return (int)*pb1 - (int)*pb2;
+        }
+        pb1++;
+        pb2++;
+    }
+    return 0;
+}
+
+
+int     kHlpStrIComp(const char *pv1, const char *pv2)
+{
+    const KU8 *pb1 = (const KU8 *)pv1;
+    const KU8 *pb2 = (const KU8 *)pv2;
+    for (;;)
+    {
+        if (*pb1 != *pb2)
+        {
+            const KU8 u1 = *pb1 >= 'a' && *pb1 <= 'z' ? *pb1 - 'a' : *pb1;
+            const KU8 u2 = *pb2 >= 'a' && *pb2 <= 'z' ? *pb2 - 'a' : *pb2;
+            if (u1 != u2)
+                return (int)*pb1 - (int)*pb2;
+        }
+        if (!*pb1)
+            break;
+        pb1++;
+        pb2++;
+    }
+    return 0;
+}
+
+
+#ifdef kHlpStrChr_needed
+char   *kHlpStrChr(const char *psz, int ch)
+{
+    while (*psz)
+    {
+        if (*psz == ch)
+            return (char *)psz;
+        psz++;
+    }
+    return NULL;
+}
+#endif
+
+
+#ifdef kHlpMemChr_needed
+void   *kHlpMemChr(const void *pv, int ch, KSIZE cb)
+{
+    const KU8 *pb = (const KU8 *)pv;
+    const KU8  b = (KU8)ch;
+    while (cb-- > 0)
+    {
+        if (*pb == b)
+            return (void *)pb;
+        pb++;
+    }
+    return NULL;
+}
+#endif
+
+
+#ifdef kHlpMemMove_needed
+void   *kHlpMemMove(void *pv1, const void *pv2, KSIZE cb)
+{
+    KU8            *pbDst = (KU8 *)pv1;
+    const KU8      *pbSrc = (const KU8 *)pv2;
+    while (cb-- > 0)
+    {
+        const KU8 b = *pbSrc++;
+        *pbDst++ = b;
+    }
+    return pv1;
+}
+#endif
+
+
+#ifdef kHlpStrNComp_needed
+int     kHlpStrNComp(const char *psz1, const char *psz2, KSIZE cch)
+{
+    while (cch-- > 0)
+    {
+        if (*psz1 != *psz2)
+            return (int)*psz1 - (int)*psz2;
+        if (!*psz1)
+            break;
+        psz1++;
+        psz2++;
+    }
+    return 0;
+}
+#endif
+
Index: trunk/kStuff/kHlp/Bare/kHlpBareThread.c
===================================================================
--- trunk/kStuff/kHlp/Bare/kHlpBareThread.c	(revision 3573)
+++ trunk/kStuff/kHlp/Bare/kHlpBareThread.c	(revision 3573)
@@ -0,0 +1,57 @@
+/* $Id$ */
+/** @file
+ * kHlpBare - Thread Manipulation.
+ */
+
+/*
+ * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * This file is part of kStuff.
+ *
+ * kStuff is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * kStuff is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with kStuff; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <k/kHlpThread.h>
+
+#if 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"
+#endif
+
+
+/**
+ * Sleep for a number of milliseconds.
+ * @param   cMillies    Number of milliseconds to sleep.
+ */
+void kHlpSleep(unsigned cMillies)
+{
+#if K_OS == K_OS_OS2
+    DosSleep(cMillies);
+#elif  K_OS == K_OS_WINDOWS
+    Sleep(cMillies);
+#else
+    usleep(cMillies * 1000);
+#endif
+}
+
Index: trunk/kStuff/kHlp/CRT/Makefile.kmk
===================================================================
--- trunk/kStuff/kHlp/CRT/Makefile.kmk	(revision 3572)
+++ 	(revision )
@@ -1,41 +1,0 @@
-# $Id$
-## @file
-# kHlpCRT - The CRT Based Helper API.
-#
-
-#
-# Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
-#
-# This file is part of kStuff.
-#
-# kStuff is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# kStuff is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with kStuff; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-#
-#
-
-DEPTH = ../../..
-include $(PATH_KBUILD)/header.kmk
-
-#
-# kCrtStatic
-#
-LIBRARIES += kHlpCRTStatic
-kHlpCRTStatic_TEMPLATE = kStuffLIB
-kHlpCRTStatic_SOURCES = \
-	kHlpCRTAlloc.cpp \
-	kHlpCRTString.cpp \
-
-# Generate the rules
-include $(PATH_KBUILD)/footer.kmk
-
Index: trunk/kStuff/kHlp/Generic/kHlpInt2Ascii.c
===================================================================
--- trunk/kStuff/kHlp/Generic/kHlpInt2Ascii.c	(revision 3573)
+++ trunk/kStuff/kHlp/Generic/kHlpInt2Ascii.c	(revision 3573)
@@ -0,0 +1,79 @@
+/* $Id$ */
+/** @file
+ * kHlpString - kHlpInt2Ascii.
+ */
+
+/*
+ * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * This file is part of kStuff.
+ *
+ * kStuff is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * kStuff is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with kStuff; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <k/kHlpString.h>
+
+
+/**
+ * Converts an signed integer to an ascii string.
+ *
+ * @returns psz.
+ * @param   psz         Pointer to the output buffer.
+ * @param   cch         The size of the output buffer.
+ * @param   lVal        The value.
+ * @param   iBase       The base to format it. (2,8,10 or 16)
+ */
+KHLP_DECL(char *) kHlpInt2Ascii(char *psz, KSIZE cch, long lVal, unsigned iBase)
+{
+    static const char s_szDigits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
+    char *pszRet = psz;
+
+    if (cch >= (lVal < 0 ? 3U : 2U) && psz)
+    {
+        /* prefix */
+        if (lVal < 0)
+        {
+            *psz++ = '-';
+            cch--;
+            lVal = -lVal;
+        }
+
+        /* the digits */
+        do
+        {
+            *psz++ = s_szDigits[lVal % iBase];
+            cch--;
+            lVal /= iBase;
+        } while (lVal && cch > 1);
+
+        /* overflow indicator */
+        if (lVal)
+            psz[-1] = '+';
+    }
+    else if (!pszRet)
+        return pszRet;
+    else if (cch < 1 || !pszRet)
+        return pszRet;
+    else
+        *psz++ = '+';
+    *psz = '\0';
+
+    return pszRet;
+}
+
Index: trunk/kStuff/kHlp/Makefile.kmk
===================================================================
--- trunk/kStuff/kHlp/Makefile.kmk	(revision 3573)
+++ trunk/kStuff/kHlp/Makefile.kmk	(revision 3573)
@@ -0,0 +1,60 @@
+# $Id$
+## @file
+# kHlp - The Helper API.
+#
+
+#
+# Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
+#
+# This file is part of kStuff.
+#
+# kStuff is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# kStuff is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with kStuff; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+#
+#
+
+DEPTH = ../..
+include $(PATH_KBUILD)/header.kmk
+
+#
+# kHlpBaseStatic
+#
+LIBRARIES += kHlpBaseStatic
+kHlpBaseStatic_TEMPLATE = kStuffLIB
+kHlpBaseStatic_SOURCES = \
+	Generic/kHlpInt2Ascii.c \
+	\
+	Bare/kHlpBareAssert.c \
+	Bare/kHlpBareHeap.c \
+	Bare/kHlpBareEnv.c \
+	Bare/kHlpBareMem.c \
+	Bare/kHlpBarePath.c \
+	Bare/kHlpBareProcess.c \
+	Bare/kHlpBareSem.c \
+	Bare/kHlpBareStr.c \
+	Bare/kHlpBareThread.c \
+
+#
+# kCrtStatic
+#
+LIBRARIES += kHlpCRTStatic
+kHlpCRTStatic_TEMPLATE = kStuffLIB
+kHlpCRTStatic_SOURCES = \
+	\
+	CRT/kHlpCRTAlloc.cpp \
+	CRT/kHlpCRTString.cpp \
+
+# Generate the rules
+include $(PATH_KBUILD)/footer.kmk
+
Index: trunk/kStuff/kLdr/Makefile.kmk
===================================================================
--- trunk/kStuff/kLdr/Makefile.kmk	(revision 3572)
+++ trunk/kStuff/kLdr/Makefile.kmk	(revision 3573)
@@ -120,10 +120,4 @@
 	kLdrDyldOS.c \
 	kLdrErr.c \
-	kLdrHlp.c \
-	kLdrHlpHeap.c \
-	kLdrHlpMem.c \
-	kLdrHlpPath.c \
-	kLdrHlpSem.c \
-	kLdrHlpStr.c \
 	kLdrMisc.c \
 	kLdrRdr.c \
@@ -137,9 +131,10 @@
 	kLdr-os2.def \
 	kLdr-os2.c \
-	kLdrHlp-gcc.c \
 	kLdrA-os2.asm
 kLdr_SOURCES.win = \
 	kLdr-win.def \
 	kLdr-win.c
+kLdr_LIBS += \
+	$(PATH_LIB)/kHlpBaseStatic$(SUFF_LIB)
 
 kLdrErr.c_DEPS = $(PATH_TARGET)/kldrErrConsts.h
@@ -197,14 +192,14 @@
 # Heap testcase.
 #
-PROGRAMS += tstkLdrHeap
+#PROGRAMS += tstkLdrHeap
 tstkLdrHeap_TEMPLATE = TST
 tstkLdrHeap_SOURCES = \
 	tstkLdrHeap.c \
-	kLdrHlp.c \
-	kLdrHlpHeap.c \
-	kLdrHlpMem.c \
-	kLdrHlpPath.c \
-	kLdrHlpSem.c \
-	kLdrHlpStr.c \
+	kHlp.c \
+	kHlpHeap.c \
+	kHlpMem.c \
+	kHlpPath.c \
+	kHlpSem.c \
+	kHlpStr.c \
 
 #
Index: trunk/kStuff/kLdr/kLdr-os2.c
===================================================================
--- trunk/kStuff/kLdr/kLdr-os2.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdr-os2.c	(revision 3573)
@@ -35,5 +35,4 @@
 #include <k/kLdr.h>
 #include "kLdrInternal.h"
-#include "kLdrHlp.h"
 
 
Index: trunk/kStuff/kLdr/kLdr-win.c
===================================================================
--- trunk/kStuff/kLdr/kLdr-win.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdr-win.c	(revision 3573)
@@ -34,5 +34,4 @@
 #include <k/kLdr.h>
 #include "kLdrInternal.h"
-#include "kLdrHlp.h"
 
 
Index: trunk/kStuff/kLdr/kLdr.c
===================================================================
--- trunk/kStuff/kLdr/kLdr.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdr.c	(revision 3573)
@@ -52,5 +52,4 @@
 *******************************************************************************/
 #include <k/kLdr.h>
-#include "kLdrHlp.h"
 #include "kLdrInternal.h"
 
@@ -95,5 +94,5 @@
             break;
         }
-        kldrHlpSleep(1);
+        kHlpSleep(1);
     }
 
@@ -101,8 +100,8 @@
      * Do the initialization.
      */
-    rc = kldrHlpHeapInit();
+    rc = kHlpHeapInit();
     if (!rc)
     {
-        rc = kldrHlpSemInit();
+        rc = kHlpSemInit();
         if (!rc)
         {
@@ -113,7 +112,7 @@
                 return 0;
             }
-            kldrHlpSemTerm();
+            kHlpSemTerm();
         }
-        kldrHlpHeapTerm();
+        kHlpHeapTerm();
     }
     g_fInitialized = -2;
@@ -135,6 +134,6 @@
      * Do the termination.
      */
-    kldrHlpSemTerm();
-    kldrHlpHeapTerm();
+    kHlpSemTerm();
+    kHlpHeapTerm();
 
     /* done */
Index: trunk/kStuff/kLdr/kLdrDyld.c
===================================================================
--- trunk/kStuff/kLdr/kLdrDyld.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdrDyld.c	(revision 3573)
@@ -30,5 +30,4 @@
 *******************************************************************************/
 #include <k/kLdr.h>
-#include "kLdrHlp.h"
 #include "kLdrInternal.h"
 
@@ -45,5 +44,5 @@
  */
 #ifdef KLDRDYLD_STRICT
-# define KLDRDYLD_ASSERT(expr)  kldrHlpAssert(expr)
+# define KLDRDYLD_ASSERT(expr)  kHlpAssert(expr)
 #else
 # define KLDRDYLD_ASSERT(expr)  do {} while (0)
@@ -267,13 +266,13 @@
     /** @todo make sense of this default prefix/suffix stuff. */
     if (pArgs->szDefPrefix[0] != '\0')
-        kLdrHlpMemCopy(kLdrDyldDefPrefix, pArgs->szDefPrefix, K_MIN(sizeof(pArgs->szDefPrefix), sizeof(kLdrDyldDefPrefix)));
+        kHlpMemCopy(kLdrDyldDefPrefix, pArgs->szDefPrefix, K_MIN(sizeof(pArgs->szDefPrefix), sizeof(kLdrDyldDefPrefix)));
     if (pArgs->szDefSuffix[0] != '\0')
-        kLdrHlpMemCopy(kLdrDyldDefSuffix, pArgs->szDefSuffix, K_MIN(sizeof(pArgs->szDefSuffix), sizeof(kLdrDyldDefSuffix)));
+        kHlpMemCopy(kLdrDyldDefSuffix, pArgs->szDefSuffix, K_MIN(sizeof(pArgs->szDefSuffix), sizeof(kLdrDyldDefSuffix)));
 
     /** @todo append that path to the one for the specified search method. */
     /** @todo create a function for doing this, an exposed api preferably. */
     /* append path */
-    cbStack = sizeof(kLdrDyldLibraryPath) - kLdrHlpStrLen(kLdrDyldLibraryPath); /* borrow cbStack for a itty bit. */
-    kLdrHlpMemCopy(kLdrDyldLibraryPath, pArgs->szLibPath, K_MIN(sizeof(pArgs->szLibPath), cbStack));
+    cbStack = sizeof(kLdrDyldLibraryPath) - kHlpStrLen(kLdrDyldLibraryPath); /* borrow cbStack for a itty bit. */
+    kHlpMemCopy(kLdrDyldLibraryPath, pArgs->szLibPath, K_MIN(sizeof(pArgs->szLibPath), cbStack));
     kLdrDyldLibraryPath[sizeof(kLdrDyldLibraryPath) - 1] = '\0';
 
@@ -281,5 +280,5 @@
      * Make sure we own the loader semaphore (necessary for init).
      */
-    rc = kldrHlpSemRequest();
+    rc = kHlpSemRequest();
     if (rc)
         kldrDyldFailure(rc, "Sem req. failure, rc=%d", rc);
@@ -333,12 +332,12 @@
         *pszErr = '\0';
     *phMod = NIL_HKLDRMOD;
-    KLDRHLP_VALIDATE_STRING(pszDll);
-    KLDRHLP_VALIDATE_OPTIONAL_STRING(pszPrefix);
-    KLDRHLP_VALIDATE_OPTIONAL_STRING(pszSuffix);
-    KLDRHLP_VALIDATE_ENUM(enmSearch, KLDRDYLD_SEARCH);
-    KLDRHLP_VALIDATE_OPTIONAL_BUFFER(pszErr, cchErr);
+    K_VALIDATE_STRING(pszDll);
+    K_VALIDATE_OPTIONAL_STRING(pszPrefix);
+    K_VALIDATE_OPTIONAL_STRING(pszSuffix);
+    K_VALIDATE_ENUM(enmSearch, KLDRDYLD_SEARCH);
+    K_VALIDATE_OPTIONAL_BUFFER(pszErr, cchErr);
 
     /* get the semaphore and do the job. */
-    rc = kldrHlpSemRequest();
+    rc = kHlpSemRequest();
     if (!rc)
     {
@@ -349,5 +348,5 @@
         g_cActiveLoadCalls--;
         kldrDyldDoModuleTerminationAndGarabageCollection();
-        kldrHlpSemRelease();
+        kHlpSemRelease();
         *phMod = pMod ? pMod->hMod : NIL_HKLDRMOD;
     }
@@ -370,5 +369,5 @@
 
     /* get sem & do work */
-    rc = kldrHlpSemRequest();
+    rc = kHlpSemRequest();
     if (!rc)
     {
@@ -378,5 +377,5 @@
         g_cActiveUnloadCalls--;
         kldrDyldDoModuleTerminationAndGarabageCollection();
-        kldrHlpSemRelease();
+        kHlpSemRelease();
     }
     return rc;
@@ -406,13 +405,13 @@
     /* validate & initialize */
     *phMod = NIL_HKLDRMOD;
-    KLDRHLP_VALIDATE_STRING(pszDll);
+    K_VALIDATE_STRING(pszDll);
 
     /* get sem & do work */
-    rc = kldrHlpSemRequest();
+    rc = kHlpSemRequest();
     if (!rc)
     {
         PKLDRDYLDMOD pMod = NULL;
         rc = kldrDyldDoFindByName(pszDll, pszPrefix, pszSuffix, enmSearch, fFlags, &pMod);
-        kldrHlpSemRelease();
+        kHlpSemRelease();
         *phMod = pMod ? pMod->hMod : NIL_HKLDRMOD;
     }
@@ -446,10 +445,10 @@
 
     /* get sem & do work */
-    rc = kldrHlpSemRequest();
+    rc = kHlpSemRequest();
     if (!rc)
     {
         PKLDRDYLDMOD pMod = NULL;
         rc = kldrDyldDoFindByAddress(Address, &pMod, piSegment, poffSegment);
-        kldrHlpSemRelease();
+        kHlpSemRelease();
         *phMod = pMod ? pMod->hMod : NIL_HKLDRMOD;
     }
@@ -476,12 +475,12 @@
         *pszName = '\0';
     KLDRDYLD_VALIDATE_HKLDRMOD(hMod);
-    KLDRHLP_VALIDATE_BUFFER(pszName, cchName);
+    K_VALIDATE_BUFFER(pszName, cchName);
 
     /* get sem & do work */
-    rc = kldrHlpSemRequest();
+    rc = kHlpSemRequest();
     if (!rc)
     {
         rc = kldrDyldDoGetName(hMod, pszName, cchName);
-        kldrHlpSemRelease();
+        kHlpSemRelease();
     }
     return rc;
@@ -507,12 +506,12 @@
         *pszFilename = '\0';
     KLDRDYLD_VALIDATE_HKLDRMOD(hMod);
-    KLDRHLP_VALIDATE_BUFFER(pszFilename, cchFilename);
+    K_VALIDATE_BUFFER(pszFilename, cchFilename);
 
     /* get sem & do work */
-    rc = kldrHlpSemRequest();
+    rc = kHlpSemRequest();
     if (!rc)
     {
         rc = kldrDyldDoGetFilename(hMod, pszFilename, cchFilename);
-        kldrHlpSemRelease();
+        kHlpSemRelease();
     }
     return rc;
@@ -545,12 +544,12 @@
         return KLDR_ERR_INVALID_PARAMETER;
     KLDRDYLD_VALIDATE_HKLDRMOD(hMod);
-    KLDRHLP_VALIDATE_OPTIONAL_STRING(pszSymbolName);
+    K_VALIDATE_OPTIONAL_STRING(pszSymbolName);
 
     /* get sem & do work */
-    rc = kldrHlpSemRequest();
+    rc = kHlpSemRequest();
     if (!rc)
     {
         rc = kldrDyldDoQuerySymbol(hMod, uSymbolOrdinal, pszSymbolName, pValue, pfKind);
-        kldrHlpSemRelease();
+        kHlpSemRelease();
     }
     return rc;
@@ -1086,10 +1085,10 @@
         KU32 cNew = g_cStackModsAllocated ? g_cStackModsAllocated * 2 : 128;
         void *pvOld = g_papStackMods;
-        void *pvNew = kldrHlpAlloc(cNew * sizeof(g_papStackMods[0]));
+        void *pvNew = kHlpAlloc(cNew * sizeof(g_papStackMods[0]));
         if (!pvNew)
             return KLDR_ERR_NO_MEMORY;
-        kLdrHlpMemCopy(pvNew, pvOld, g_cStackMods * sizeof(g_papStackMods[0]));
+        kHlpMemCopy(pvNew, pvOld, g_cStackMods * sizeof(g_papStackMods[0]));
         g_papStackMods = (PPKLDRDYLDMOD)pvNew;
-        kldrHlpFree(pvOld);
+        kHlpFree(pvOld);
     }
 
@@ -1472,5 +1471,5 @@
     /** @todo print it. */
     if (g_fBootstrapping);
-        kldrHlpExit(1);
+        kHlpExit(1);
     return rc;
 }
@@ -1491,13 +1490,13 @@
     /* if no error string, format the rc into a string. */
     if (!g_szkLdrDyldError[0] && rc)
-        kldrHlpInt2Ascii(g_szkLdrDyldError, sizeof(g_szkLdrDyldError), rc, 10);
+        kHlpInt2Ascii(g_szkLdrDyldError, sizeof(g_szkLdrDyldError), rc, 10);
 
     /* copy it if we got something. */
     if (cchErr && pszErr && g_szkLdrDyldError[0])
     {
-        cchToCopy = kLdrHlpStrLen(g_szkLdrDyldError);
+        cchToCopy = kHlpStrLen(g_szkLdrDyldError);
         if (cchToCopy >= cchErr)
             cchToCopy = cchErr - 1;
-        kLdrHlpMemCopy(pszErr, g_szkLdrDyldError, cchToCopy);
+        kHlpMemCopy(pszErr, g_szkLdrDyldError, cchToCopy);
         pszErr[cchToCopy] = '\0';
     }
Index: trunk/kStuff/kLdr/kLdrDyldFind.c
===================================================================
--- trunk/kStuff/kLdr/kLdrDyldFind.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdrDyldFind.c	(revision 3573)
@@ -52,6 +52,6 @@
 
 #include <k/kLdr.h>
-#include "kLdrHlp.h"
 #include "kLdrInternal.h"
+
 
 /*******************************************************************************
@@ -66,5 +66,5 @@
  */
 #ifdef KLDRDYLDFIND_STRICT
-# define KLDRDYLDFIND_ASSERT(expr)  kldrHlpAssert(expr)
+# define KLDRDYLDFIND_ASSERT(expr)  kHlpAssert(expr)
 #else
 # define KLDRDYLDFIND_ASSERT(expr)  do {} while (0)
@@ -225,11 +225,11 @@
      * The kLdr search parameters.
      */
-    rc = kldrHlpGetEnv("KLDR_LIBRARY_PATH", kLdrDyldLibraryPath, sizeof(kLdrDyldLibraryPath));
-    rc = kldrHlpGetEnv("KLDR_DEF_PREFIX", szTmp, sizeof(szTmp));
+    rc = kHlpGetEnv("KLDR_LIBRARY_PATH", kLdrDyldLibraryPath, sizeof(kLdrDyldLibraryPath));
+    rc = kHlpGetEnv("KLDR_DEF_PREFIX", szTmp, sizeof(szTmp));
     if (!rc)
-        kLdrHlpMemCopy(kLdrDyldDefPrefix, szTmp, sizeof(szTmp));
-    rc = kldrHlpGetEnv("KLDR_DEF_SUFFIX", szTmp, sizeof(szTmp));
+        kHlpMemCopy(kLdrDyldDefPrefix, szTmp, sizeof(szTmp));
+    rc = kHlpGetEnv("KLDR_DEF_SUFFIX", szTmp, sizeof(szTmp));
     if (!rc)
-        kLdrHlpMemCopy(kLdrDyldDefSuffix, szTmp, sizeof(szTmp));
+        kHlpMemCopy(kLdrDyldDefSuffix, szTmp, sizeof(szTmp));
 
     /*
@@ -251,6 +251,6 @@
 
 #else
-    kldrHlpGetEnv("KLDR_OS2_LIBPATH", kLdrDyldOS2Libpath, sizeof(kLdrDyldOS2Libpath));
-    kldrHlpGetEnv("KLDR_OS2_LIBPATHSTRICT", kLdrDyldOS2LibpathStrict, sizeof(kLdrDyldOS2LibpathStrict));
+    kHlpGetEnv("KLDR_OS2_LIBPATH", kLdrDyldOS2Libpath, sizeof(kLdrDyldOS2Libpath));
+    kHlpGetEnv("KLDR_OS2_LIBPATHSTRICT", kLdrDyldOS2LibpathStrict, sizeof(kLdrDyldOS2LibpathStrict));
     if (    kLdrDyldOS2LibpathStrict[0] == 'T'
         ||  kLdrDyldOS2LibpathStrict[0] == 't')
@@ -259,6 +259,6 @@
         kLdrDyldOS2LibpathStrict[0] = '\0';
     kLdrDyldOS2LibpathStrict[1] = '\0';
-    kldrHlpGetEnv("KLDR_OS2_BEGINLIBPATH", kLdrDyldOS2BeginLibpath, sizeof(kLdrDyldOS2BeginLibpath));
-    kldrHlpGetEnv("KLDR_OS2_ENDLIBPATH", kLdrDyldOS2EndLibpath, sizeof(kLdrDyldOS2EndLibpath));
+    kHlpGetEnv("KLDR_OS2_BEGINLIBPATH", kLdrDyldOS2BeginLibpath, sizeof(kLdrDyldOS2BeginLibpath));
+    kHlpGetEnv("KLDR_OS2_ENDLIBPATH", kLdrDyldOS2EndLibpath, sizeof(kLdrDyldOS2EndLibpath));
 #endif
 
@@ -273,11 +273,11 @@
     if (cch >= sizeof(kLdrDyldWindowsDir))
         return (rc = GetLastError()) ? rc : -1;
-    kldrHlpGetEnv("PATH", kLdrDyldWindowsPath, sizeof(kLdrDyldWindowsPath));
+    kHlpGetEnv("PATH", kLdrDyldWindowsPath, sizeof(kLdrDyldWindowsPath));
 #else
-    kldrHlpGetEnv("KLDR_WINDOWS_SYSTEM_DIR", kLdrDyldWindowsSystemDir, sizeof(kLdrDyldWindowsSystemDir));
-    kldrHlpGetEnv("KLDR_WINDOWS_DIR", kLdrDyldWindowsDir, sizeof(kLdrDyldWindowsDir));
-    rc = kldrHlpGetEnv("KLDR_WINDOWS_PATH", kLdrDyldWindowsPath, sizeof(kLdrDyldWindowsPath));
+    kHlpGetEnv("KLDR_WINDOWS_SYSTEM_DIR", kLdrDyldWindowsSystemDir, sizeof(kLdrDyldWindowsSystemDir));
+    kHlpGetEnv("KLDR_WINDOWS_DIR", kLdrDyldWindowsDir, sizeof(kLdrDyldWindowsDir));
+    rc = kHlpGetEnv("KLDR_WINDOWS_PATH", kLdrDyldWindowsPath, sizeof(kLdrDyldWindowsPath));
     if (rc)
-        kldrHlpGetEnv("PATH", kLdrDyldWindowsPath, sizeof(kLdrDyldWindowsPath));
+        kHlpGetEnv("PATH", kLdrDyldWindowsPath, sizeof(kLdrDyldWindowsPath));
 #endif
 
@@ -285,7 +285,7 @@
      * The Unix search parameters.
      */
-    rc = kldrHlpGetEnv("KLDR_UNIX_LIBRARY_PATH", kLdrDyldUnixLibraryPath, sizeof(kLdrDyldUnixLibraryPath));
+    rc = kHlpGetEnv("KLDR_UNIX_LIBRARY_PATH", kLdrDyldUnixLibraryPath, sizeof(kLdrDyldUnixLibraryPath));
     if (rc)
-        kldrHlpGetEnv("LD_LIBRARY_PATH", kLdrDyldUnixLibraryPath, sizeof(kLdrDyldUnixLibraryPath));
+        kHlpGetEnv("LD_LIBRARY_PATH", kLdrDyldUnixLibraryPath, sizeof(kLdrDyldUnixLibraryPath));
 
     (void)cch;
@@ -310,6 +310,6 @@
         if (!rc)
         {
-            *kldrHlpGetFilename(kLdrDyldAppDir) = '\0';
-             kLdrHlpMemCopy(kLdrDyldWindowsAppDir, kLdrDyldAppDir, sizeof(kLdrDyldAppDir));
+            *kHlpGetFilename(kLdrDyldAppDir) = '\0';
+             kHlpMemCopy(kLdrDyldWindowsAppDir, kLdrDyldAppDir, sizeof(kLdrDyldAppDir));
         }
         else
@@ -324,6 +324,6 @@
         if (dwSize > 0)
         {
-            *kldrHlpGetFilename(kLdrDyldAppDir) = '\0';
-            kLdrHlpMemCopy(kLdrDyldWindowsAppDir, kLdrDyldAppDir, sizeof(kLdrDyldAppDir));
+            *kHlpGetFilename(kLdrDyldAppDir) = '\0';
+            kHlpMemCopy(kLdrDyldWindowsAppDir, kLdrDyldAppDir, sizeof(kLdrDyldAppDir));
         }
         else
@@ -364,5 +364,5 @@
      * that should be opened directly and not a module name to be searched for.
      */
-    if (!kldrHlpIsFilenameOnly(pszName))
+    if (!kHlpIsFilenameOnly(pszName))
         rc = kldrDyldFindTryOpen(pszName, &pRdr);
     else if (!(fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE))
@@ -377,9 +377,9 @@
         {
             const char     *pszFilename = kLdrRdrName(pRdr);
-            const KSIZE     cchFilename = kLdrHlpStrLen(pszFilename);
+            const KSIZE     cchFilename = kHlpStrLen(pszFilename);
             PKLDRDYLDMOD    pCur;
             for (pCur = kLdrDyldHead; pCur; pCur = pCur->Load.pNext)
                 KLDRDYLDFIND_ASSERT(    pCur->pMod->cchFilename != cchFilename
-                                    ||  kLdrHlpMemComp(pCur->pMod->pszFilename, pszFilename, cchFilename));
+                                    ||  kHlpMemComp(pCur->pMod->pszFilename, pszFilename, cchFilename));
         }
 #endif
@@ -391,5 +391,5 @@
         {
             const char     *pszFilename = kLdrRdrName(pRdr);
-            const KSIZE     cchFilename = kLdrHlpStrLen(pszFilename);
+            const KSIZE     cchFilename = kHlpStrLen(pszFilename);
             PKLDRDYLDMOD    pCur;
             for (pCur = kLdrDyldHead; pCur; pCur = pCur->Load.pNext)
@@ -397,5 +397,5 @@
                 if (    !pCur->fGlobalOrSpecific
                     &&  pCur->pMod->cchFilename == cchFilename
-                    &&  !kLdrHlpMemComp(pCur->pMod->pszFilename, pszFilename, cchFilename))
+                    &&  !kHlpMemComp(pCur->pMod->pszFilename, pszFilename, cchFilename))
                 {
                     kLdrRdrClose(pRdr);
@@ -405,5 +405,5 @@
                 }
                 KLDRDYLDFIND_ASSERT(    pCur->pMod->cchFilename != cchFilename
-                                    ||  kLdrHlpMemComp(pCur->pMod->pszFilename, pszFilename, cchFilename));
+                                    ||  kHlpMemComp(pCur->pMod->pszFilename, pszFilename, cchFilename));
             }
         }
@@ -449,7 +449,7 @@
         return rc;
     Args.pszName = pszName;
-    Args.cchName = kLdrHlpStrLen(pszName);
-    Args.cchPrefix = Args.pszPrefix ? kLdrHlpStrLen(Args.pszPrefix) : 0;
-    Args.cchSuffix = Args.pszSuffix ? kLdrHlpStrLen(Args.pszSuffix) : 0;
+    Args.cchName = kHlpStrLen(pszName);
+    Args.cchPrefix = Args.pszPrefix ? kHlpStrLen(Args.pszPrefix) : 0;
+    Args.cchSuffix = Args.pszSuffix ? kHlpStrLen(Args.pszSuffix) : 0;
     Args.cchMaxLength = Args.cchName + Args.cchSuffix + Args.cchPrefix;
     Args.fFlags = fFlags;
@@ -467,5 +467,5 @@
             if (kLdrDyldAppDir[0] != '\0')
             {
-                rc = kldrDyldFindTryOpenPath(kLdrDyldAppDir, kLdrHlpStrLen(kLdrDyldAppDir), &Args);
+                rc = kldrDyldFindTryOpenPath(kLdrDyldAppDir, kHlpStrLen(kLdrDyldAppDir), &Args);
                 if (rc != KLDR_ERR_MODULE_NOT_FOUND)
                     break;
@@ -494,5 +494,5 @@
         {
             kldrDyldFindLazyInitAppDir();
-            rc = kldrDyldFindTryOpenPath(kLdrDyldWindowsAppDir, kLdrHlpStrLen(kLdrDyldWindowsAppDir), &Args);
+            rc = kldrDyldFindTryOpenPath(kLdrDyldWindowsAppDir, kHlpStrLen(kLdrDyldWindowsAppDir), &Args);
             if (rc != KLDR_ERR_MODULE_NOT_FOUND)
                 break;
@@ -503,8 +503,8 @@
                     break;
             }
-            rc = kldrDyldFindTryOpenPath(kLdrDyldWindowsSystemDir, kLdrHlpStrLen(kLdrDyldWindowsSystemDir), &Args);
+            rc = kldrDyldFindTryOpenPath(kLdrDyldWindowsSystemDir, kHlpStrLen(kLdrDyldWindowsSystemDir), &Args);
             if (rc != KLDR_ERR_MODULE_NOT_FOUND)
                 break;
-            rc = kldrDyldFindTryOpenPath(kLdrDyldWindowsDir, kLdrHlpStrLen(kLdrDyldWindowsDir), &Args);
+            rc = kldrDyldFindTryOpenPath(kLdrDyldWindowsDir, kHlpStrLen(kLdrDyldWindowsDir), &Args);
             if (rc != KLDR_ERR_MODULE_NOT_FOUND)
                 break;
@@ -528,5 +528,5 @@
         }
 
-        default: kldrHlpAssert(!"internal error"); return -1;
+        default: kHlpAssert(!"internal error"); return -1;
     }
     return rc;
@@ -563,7 +563,7 @@
         return rc;
     Args.pszName = pszName;
-    Args.cchName = kLdrHlpStrLen(pszName);
-    Args.cchPrefix = Args.pszPrefix ? kLdrHlpStrLen(Args.pszPrefix) : 0;
-    Args.cchSuffix = Args.pszSuffix ? kLdrHlpStrLen(Args.pszSuffix) : 0;
+    Args.cchName = kHlpStrLen(pszName);
+    Args.cchPrefix = Args.pszPrefix ? kHlpStrLen(Args.pszPrefix) : 0;
+    Args.cchSuffix = Args.pszSuffix ? kHlpStrLen(Args.pszSuffix) : 0;
     Args.cchMaxLength = Args.cchName + Args.cchSuffix + Args.cchPrefix;
     Args.fFlags = fFlags;
@@ -579,5 +579,5 @@
         if (kLdrDyldAppDir[0] != '\0')
         {
-            rc = kldrDyldFindTryOpenPath(kLdrDyldAppDir, kLdrHlpStrLen(kLdrDyldAppDir), &Args);
+            rc = kldrDyldFindTryOpenPath(kLdrDyldAppDir, kHlpStrLen(kLdrDyldAppDir), &Args);
             if (rc != KLDR_ERR_MODULE_NOT_FOUND)
                 return rc;
@@ -591,8 +591,8 @@
     {
         KSIZE cch;
-        kldrHlpGetEnv("KLDR_EXE_PATH", kLdrDyldExePath, sizeof(kLdrDyldExePath) - 10);
-        cch = kLdrHlpStrLen(kLdrDyldExePath);
+        kHlpGetEnv("KLDR_EXE_PATH", kLdrDyldExePath, sizeof(kLdrDyldExePath) - 10);
+        cch = kHlpStrLen(kLdrDyldExePath);
         kLdrDyldExePath[cch++] = ';';
-        kldrHlpGetEnv("PATH", &kLdrDyldExePath[cch], sizeof(kLdrDyldExePath) - cch);
+        kHlpGetEnv("PATH", &kLdrDyldExePath[cch], sizeof(kLdrDyldExePath) - cch);
     }
     return kldrDyldFindEnumeratePath(kLdrDyldExePath, &Args);
@@ -662,5 +662,5 @@
      * The directory path.
      */
-    kLdrHlpMemCopy(s_szFilename, pchPath, cchPath);
+    kHlpMemCopy(s_szFilename, pchPath, cchPath);
     psz = &s_szFilename[cchPath];
     if (psz[-1] != '/'
@@ -677,12 +677,12 @@
     if (pArgs->cchPrefix)
     {
-        kLdrHlpMemCopy(psz, pArgs->pszPrefix, pArgs->cchPrefix);
+        kHlpMemCopy(psz, pArgs->pszPrefix, pArgs->cchPrefix);
         psz += pArgs->cchPrefix;
     }
-    kLdrHlpMemCopy(psz, pArgs->pszName, pArgs->cchName);
+    kHlpMemCopy(psz, pArgs->pszName, pArgs->cchName);
     psz += pArgs->cchName;
     if (pArgs->cchSuffix)
     {
-        kLdrHlpMemCopy(psz, pArgs->pszSuffix, pArgs->cchSuffix);
+        kHlpMemCopy(psz, pArgs->pszSuffix, pArgs->cchSuffix);
         psz += pArgs->cchSuffix;
     }
@@ -836,10 +836,10 @@
     if (*ppszSuffix)
     {
-        const KSIZE cchName = kLdrHlpStrLen(pszName);
-        const KSIZE cchSuffix = kLdrHlpStrLen(*ppszSuffix);
+        const KSIZE cchName = kHlpStrLen(pszName);
+        const KSIZE cchSuffix = kHlpStrLen(*ppszSuffix);
         if (    cchName > cchSuffix
             &&  (   fCaseSensitive
-                 ?  !kLdrHlpMemComp(pszName + cchName - cchSuffix, *ppszSuffix, cchSuffix)
-                 :  !kLdrHlpMemIComp(pszName + cchName - cchSuffix, *ppszSuffix, cchSuffix))
+                 ?  !kHlpMemComp(pszName + cchName - cchSuffix, *ppszSuffix, cchSuffix)
+                 :  !kHlpMemIComp(pszName + cchName - cchSuffix, *ppszSuffix, cchSuffix))
            )
             *ppszSuffix = NULL;
@@ -893,5 +893,5 @@
      */
     fOS2LibpathStrict = 0;
-    if (    !kldrHlpIsFilenameOnly(pszName)
+    if (    !kHlpIsFilenameOnly(pszName)
         ||  (fOS2LibpathStrict = (   enmSearch == KLDRDYLD_SEARCH_OS2
                                   && kLdrDyldOS2LibpathStrict[0] == 'T')
@@ -908,5 +908,5 @@
             /* do a filename based search. */
             const char     *pszFilename = kLdrRdrName(pRdr);
-            const KSIZE     cchFilename = kLdrHlpStrLen(pszFilename);
+            const KSIZE     cchFilename = kHlpStrLen(pszFilename);
             PKLDRDYLDMOD    pCur;
             rc = KLDR_ERR_MODULE_NOT_FOUND;
@@ -914,5 +914,5 @@
             {
                 if (    pCur->pMod->cchFilename == cchFilename
-                    &&  !kLdrHlpMemComp(pCur->pMod->pszFilename, pszFilename, cchFilename))
+                    &&  !kHlpMemComp(pCur->pMod->pszFilename, pszFilename, cchFilename))
                 {
                     *ppMod = pCur;
@@ -926,8 +926,8 @@
     else
     {
-        const KSIZE     cchName = kLdrHlpStrLen(pszName);
-        const KSIZE     cchPrefix = pszPrefix ? kLdrHlpStrLen(pszPrefix) : 0;
-        const KSIZE     cchSuffix = pszSuffix ? kLdrHlpStrLen(pszSuffix) : 0;
-        const char     *pszNameSuffix = kldrHlpGetSuff(pszName);
+        const KSIZE     cchName = kHlpStrLen(pszName);
+        const KSIZE     cchPrefix = pszPrefix ? kHlpStrLen(pszPrefix) : 0;
+        const KSIZE     cchSuffix = pszSuffix ? kHlpStrLen(pszSuffix) : 0;
+        const char     *pszNameSuffix = kHlpGetSuff(pszName);
         PKLDRDYLDMOD    pCur = kLdrDyldHead;
 
@@ -942,6 +942,6 @@
         {
             const unsigned fNameHasSuffix = pszNameSuffix
-                                         && kLdrHlpStrLen(pszNameSuffix) == cchSuffix
-                                         && !kLdrHlpMemIComp(pszNameSuffix, pszName + cchName - cchSuffix, cchSuffix);
+                                         && kHlpStrLen(pszNameSuffix) == cchSuffix
+                                         && !kHlpMemIComp(pszNameSuffix, pszName + cchName - cchSuffix, cchSuffix);
             for (; pCur; pCur = pCur->Load.pNext)
             {
@@ -953,11 +953,11 @@
                 /* match name */
                 if (    pCur->pMod->cchName == cchName
-                    &&  !kLdrHlpMemIComp(pCur->pMod->pszName, pszName, cchName))
+                    &&  !kHlpMemIComp(pCur->pMod->pszName, pszName, cchName))
                     break;
                 if (cchPrefix)
                 {
                     if (    pCur->pMod->cchName == cchName + cchPrefix
-                        &&  !kLdrHlpMemIComp(pCur->pMod->pszName, pszPrefix, cchPrefix)
-                        &&  !kLdrHlpMemIComp(pCur->pMod->pszName + cchPrefix, pszName, cchName))
+                        &&  !kHlpMemIComp(pCur->pMod->pszName, pszPrefix, cchPrefix)
+                        &&  !kHlpMemIComp(pCur->pMod->pszName + cchPrefix, pszName, cchName))
                     break;
                 }
@@ -965,22 +965,22 @@
                 {
                     if (    pCur->pMod->cchName == cchName + cchSuffix
-                        &&  !kLdrHlpMemIComp(pCur->pMod->pszName + cchName, pszSuffix, cchSuffix)
-                        &&  !kLdrHlpMemIComp(pCur->pMod->pszName, pszName, cchName))
+                        &&  !kHlpMemIComp(pCur->pMod->pszName + cchName, pszSuffix, cchSuffix)
+                        &&  !kHlpMemIComp(pCur->pMod->pszName, pszName, cchName))
                     break;
                     if (    fNameHasSuffix
                         &&  pCur->pMod->cchName == cchName - cchSuffix
-                        &&  !kLdrHlpMemIComp(pCur->pMod->pszName, pszName, cchName - cchSuffix))
+                        &&  !kHlpMemIComp(pCur->pMod->pszName, pszName, cchName - cchSuffix))
                     break;
                     if (cchPrefix)
                     {
                         if (    pCur->pMod->cchName == cchName + cchPrefix + cchSuffix
-                            &&  !kLdrHlpMemIComp(pCur->pMod->pszName, pszPrefix, cchPrefix)
-                            &&  !kLdrHlpMemIComp(pCur->pMod->pszName + cchPrefix, pszName, cchName)
-                            &&  !kLdrHlpMemIComp(pCur->pMod->pszName + cchPrefix + cchName, pszSuffix, cchSuffix))
+                            &&  !kHlpMemIComp(pCur->pMod->pszName, pszPrefix, cchPrefix)
+                            &&  !kHlpMemIComp(pCur->pMod->pszName + cchPrefix, pszName, cchName)
+                            &&  !kHlpMemIComp(pCur->pMod->pszName + cchPrefix + cchName, pszSuffix, cchSuffix))
                         break;
                         if (    fNameHasSuffix
                             &&  pCur->pMod->cchName == cchName + cchPrefix - cchSuffix
-                            &&  !kLdrHlpMemIComp(pCur->pMod->pszName, pszPrefix, cchPrefix)
-                            &&  !kLdrHlpMemIComp(pCur->pMod->pszName + cchPrefix, pszName, cchName - cchSuffix))
+                            &&  !kHlpMemIComp(pCur->pMod->pszName, pszPrefix, cchPrefix)
+                            &&  !kHlpMemIComp(pCur->pMod->pszName + cchPrefix, pszName, cchName - cchSuffix))
                         break;
                     }
@@ -991,6 +991,6 @@
         {
             const unsigned fNameHasSuffix = pszNameSuffix
-                                         && kLdrHlpStrLen(pszNameSuffix) == cchSuffix
-                                         && kLdrHlpMemComp(pszNameSuffix, pszName + cchName - cchSuffix, cchSuffix);
+                                         && kHlpStrLen(pszNameSuffix) == cchSuffix
+                                         && kHlpMemComp(pszNameSuffix, pszName + cchName - cchSuffix, cchSuffix);
             for (; pCur; pCur = pCur->Load.pNext)
             {
@@ -1002,11 +1002,11 @@
                 /* match name */
                 if (    pCur->pMod->cchName == cchName
-                    &&  !kLdrHlpMemComp(pCur->pMod->pszName, pszName, cchName))
+                    &&  !kHlpMemComp(pCur->pMod->pszName, pszName, cchName))
                     break;
                 if (cchPrefix)
                 {
                     if (    pCur->pMod->cchName == cchName + cchPrefix
-                        &&  !kLdrHlpMemComp(pCur->pMod->pszName, pszPrefix, cchPrefix)
-                        &&  !kLdrHlpMemComp(pCur->pMod->pszName + cchPrefix, pszName, cchName))
+                        &&  !kHlpMemComp(pCur->pMod->pszName, pszPrefix, cchPrefix)
+                        &&  !kHlpMemComp(pCur->pMod->pszName + cchPrefix, pszName, cchName))
                     break;
                 }
@@ -1014,21 +1014,21 @@
                 {
                     if (    pCur->pMod->cchName == cchName + cchSuffix
-                        &&  !kLdrHlpMemComp(pCur->pMod->pszName + cchName, pszSuffix, cchSuffix)
-                        &&  !kLdrHlpMemComp(pCur->pMod->pszName, pszName, cchName))
+                        &&  !kHlpMemComp(pCur->pMod->pszName + cchName, pszSuffix, cchSuffix)
+                        &&  !kHlpMemComp(pCur->pMod->pszName, pszName, cchName))
                     break;
                     if (    fNameHasSuffix
                         &&  pCur->pMod->cchName == cchName - cchSuffix
-                        &&  !kLdrHlpMemComp(pCur->pMod->pszName, pszName, cchName - cchSuffix))
+                        &&  !kHlpMemComp(pCur->pMod->pszName, pszName, cchName - cchSuffix))
                     break;
                     if (cchPrefix)
                     {
                         if (    pCur->pMod->cchName == cchName + cchPrefix + cchSuffix
-                            &&  !kLdrHlpMemComp(pCur->pMod->pszName, pszPrefix, cchPrefix)
-                            &&  !kLdrHlpMemComp(pCur->pMod->pszName + cchPrefix, pszName, cchName)
-                            &&  !kLdrHlpMemComp(pCur->pMod->pszName + cchPrefix + cchName, pszSuffix, cchSuffix))
+                            &&  !kHlpMemComp(pCur->pMod->pszName, pszPrefix, cchPrefix)
+                            &&  !kHlpMemComp(pCur->pMod->pszName + cchPrefix, pszName, cchName)
+                            &&  !kHlpMemComp(pCur->pMod->pszName + cchPrefix + cchName, pszSuffix, cchSuffix))
                         break;
                         if (    pCur->pMod->cchName == cchName + cchPrefix - cchSuffix
-                            &&  !kLdrHlpMemComp(pCur->pMod->pszName, pszPrefix, cchPrefix)
-                            &&  !kLdrHlpMemComp(pCur->pMod->pszName + cchPrefix, pszName, cchName - cchSuffix))
+                            &&  !kHlpMemComp(pCur->pMod->pszName, pszPrefix, cchPrefix)
+                            &&  !kHlpMemComp(pCur->pMod->pszName + cchPrefix, pszName, cchName - cchSuffix))
                         break;
                     }
Index: trunk/kStuff/kLdr/kLdrDyldMod.c
===================================================================
--- trunk/kStuff/kLdr/kLdrDyldMod.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdrDyldMod.c	(revision 3573)
@@ -32,5 +32,4 @@
 #include <k/kLdr.h>
 #include "kLdrInternal.h"
-#include "kLdrHlp.h"
 
 
@@ -46,5 +45,5 @@
  */
 #ifdef KLDRDYLDMOD_STRICT
-# define KLDRDYLDMOD_ASSERT(expr)  kldrHlpAssert(expr)
+# define KLDRDYLDMOD_ASSERT(expr)  kHlpAssert(expr)
 #else
 # define KLDRDYLDMOD_ASSERT(expr)  do {} while (0)
@@ -120,5 +119,5 @@
      * Allocate a new dyld module.
      */
-    pMod = (PKLDRDYLDMOD)kldrHlpAlloc(sizeof(*pMod));
+    pMod = (PKLDRDYLDMOD)kHlpAlloc(sizeof(*pMod));
     if (pMod)
     {
@@ -282,5 +281,5 @@
         }
 
-        kldrHlpFree(pMod->papPrereqs);
+        kHlpFree(pMod->papPrereqs);
         pMod->papPrereqs = NULL;
         pMod->cPrereqs = 0;
@@ -305,5 +304,5 @@
         pMod->u32MagicHead = 1;
         pMod->u32MagicTail = 2;
-        kldrHlpFree(pMod);
+        kHlpFree(pMod);
     }
 }
@@ -490,5 +489,5 @@
         pMod->u32MagicHead = 1;
         pMod->u32MagicTail = 2;
-        kldrHlpFree(pMod);
+        kHlpFree(pMod);
     }
 }
@@ -757,9 +756,9 @@
      */
     cPrereqs = kLdrModNumberOfImports(pMod->pMod, NULL);
-    kldrHlpAssert(cPrereqs >= 0);
+    kHlpAssert(cPrereqs >= 0);
     if (pMod->cPrereqs != cPrereqs)
     {
         KLDRDYLDMOD_ASSERT(!pMod->papPrereqs);
-        pMod->papPrereqs = (PPKLDRDYLDMOD)kldrHlpAllocZ(sizeof(pMod->papPrereqs[0]) * cPrereqs);
+        pMod->papPrereqs = (PPKLDRDYLDMOD)kHlpAllocZ(sizeof(pMod->papPrereqs[0]) * cPrereqs);
         if (!pMod->papPrereqs)
             return KLDR_ERR_NO_MEMORY;
@@ -1149,5 +1148,5 @@
             /* check if there is a stack size override/default. */
             KSIZE cbDefOverride;
-            if (kldrHlpGetEnvUZ("KLDR_MAIN_STACK_SIZE", &cbDefOverride))
+            if (kHlpGetEnvUZ("KLDR_MAIN_STACK_SIZE", &cbDefOverride))
                 cbDefOverride = 0;
 
@@ -1235,5 +1234,5 @@
     if (cch)
     {
-        kLdrHlpMemCopy(pszName, pMod->pMod->pszName, cch - 1);
+        kHlpMemCopy(pszName, pMod->pMod->pszName, cch - 1);
         pszName[cch - 1] = '\0';
     }
@@ -1255,5 +1254,5 @@
     if (cch)
     {
-        kLdrHlpMemCopy(pszFilename, pMod->pMod->pszFilename, cch - 1);
+        kHlpMemCopy(pszFilename, pMod->pMod->pszFilename, cch - 1);
         pszFilename[cch - 1] = '\0';
     }
@@ -1280,5 +1279,5 @@
 
     rc = kLdrModQuerySymbol(pMod->pMod, NULL, KLDRMOD_BASEADDRESS_MAP,
-                            uSymbolOrdinal, pszSymbolName, kLdrHlpStrLen(pszSymbolName), NULL,
+                            uSymbolOrdinal, pszSymbolName, kHlpStrLen(pszSymbolName), NULL,
                             kldrDyldModFixupGetImportCallback, pMod,
                             &uValue, &fKind);
Index: trunk/kStuff/kLdr/kLdrDyldOS.c
===================================================================
--- trunk/kStuff/kLdr/kLdrDyldOS.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdrDyldOS.c	(revision 3573)
@@ -40,5 +40,4 @@
 
 #include <k/kLdr.h>
-#include "kLdrHlp.h"
 #include "kLdrInternal.h"
 
@@ -103,5 +102,5 @@
 
     TerminateProcess(GetCurrentProcess(), rc);
-    kldrHlpAssert(!"TerminateProcess failed");
+    kHlpAssert(!"TerminateProcess failed");
     for (;;)
         TerminateProcess(GetCurrentProcess(), rc);
@@ -118,5 +117,5 @@
 void kldrDyldDoLoadExeStackSwitch(PKLDRDYLDMOD pExe, void *pvStack, KSIZE cbStack)
 {
-    /*kldrHlpAssert(!"not implemented");*/
+    /*kHlpAssert(!"not implemented");*/
 
     /** @todo implement this properly! */
Index: trunk/kStuff/kLdr/kLdrExeStub-win.c
===================================================================
--- trunk/kStuff/kLdr/kLdrExeStub-win.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdrExeStub-win.c	(revision 3573)
@@ -31,4 +31,5 @@
 #include <k/kLdr.h>
 #include <Windows.h>
+#include "kLdrInternal.h"
 
 
@@ -52,5 +53,7 @@
 int WindowsMain(void)
 {
-    return kLdrDyldLoadExe(&g_Args, NULL);
+    kLdrDyldLoadExe(&g_Args, NULL);
+    /* won't happen */
+    return 0;
 }
 
Index: trunk/kStuff/kLdr/kLdrHlp-gcc.c
===================================================================
--- trunk/kStuff/kLdr/kLdrHlp-gcc.c	(revision 3572)
+++ 	(revision )
@@ -1,216 +1,0 @@
-/* $Id$ */
-/** @file
- *
- * kLdr - The Dynamic Loader, Helper Functions for GCC.
- *
- * Copyright (c) 2006 knut st. osmundsen <bird@anduin.net>
- *
- *
- * This file is part of kLdr.
- *
- * kLdr is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * kLdr is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with kLdr; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-#include <k/kLdr.h>
-#include "kLdrHlp.h"
-
-
-/*******************************************************************************
-*   Global Variables                                                           *
-*******************************************************************************/
-
-
-void *memchr(const void *pv, int ch, KSIZE cb)
-{
-    const char *pb = pv;
-    while (cb-- > 0)
-    {
-        if (*pb == ch)
-            return (void *)pb;
-        pb++;
-    }
-    return 0;
-}
-
-
-int memcmp(const void *pv1, const void *pv2, KSIZE cb)
-{
-    /*
-     * Pointer size pointer size.
-     */
-    if (    cb > 16
-        &&  !((KUPTR)pv1 & (sizeof(void *) - 1))
-        &&  !((KUPTR)pv2 & (sizeof(void *) - 1)) )
-    {
-        const KUPTR *pu1 = pv1;
-        const KUPTR *pu2 = pv2;
-        while (cb >= sizeof(KUPTR))
-        {
-            const KUPTR u1 = *pu1++;
-            const KUPTR u2 = *pu2++;
-            if (u1 != u2)
-                return u1 > u2 ? 1 : -1;
-            cb -= sizeof(KUPTR);
-        }
-        if (!cb)
-            return 0;
-        pv1 = (const void *)pu1;
-        pv2 = (const void *)pu2;
-    }
-
-    /*
-     * Byte by byte.
-     */
-    if (cb)
-    {
-        const unsigned char *pb1 = pv1;
-        const unsigned char *pb2 = pv2;
-        while (cb-- > 0)
-        {
-            const unsigned char b1 = *pb1++;
-            const unsigned char b2 = *pb2++;
-            if (b1 != b2)
-                return b1 > b2 ? 1 : -1;
-        }
-    }
-    return 0;
-}
-
-
-void *memcpy(void *pv1, const void *pv2, KSIZE cb)
-{
-    void *pv1Start = pv1;
-
-    /*
-     * Pointer size pointer size.
-     */
-    if (    cb > 16
-        &&  !((KUPTR)pv1 & (sizeof(void *) - 1))
-        &&  !((KUPTR)pv2 & (sizeof(void *) - 1)) )
-    {
-        KUPTR       *pu1 = pv1;
-        const KUPTR *pu2 = pv2;
-        while (cb >= sizeof(KUPTR))
-        {
-            cb -= sizeof(KUPTR);
-            *pu1++ = *pu2++;
-        }
-        if (!cb)
-            return 0;
-        pv1 = (void *)pu1;
-        pv2 = (const void *)pu2;
-    }
-
-    /*
-     * byte by byte
-     */
-    if (cb)
-    {
-        unsigned char       *pb1 = pv1;
-        const unsigned char *pb2 = pv2;
-        while (cb-- > 0)
-            *pb1++ = *pb2++;
-    }
-
-    return pv1Start;
-}
-
-void *memset(void *pv, int ch, KSIZE cb)
-{
-    void *pvStart = pv;
-
-    /*
-     * Pointer size pointer size.
-     */
-    if (    cb > 16
-        &&  !((KUPTR)pv & (sizeof(void *) - 1)))
-    {
-        KUPTR  *pu = pv;
-        KUPTR   u = ch | (ch << 8);
-        u |= u << 16;
-#if defined(__AMD64__)
-        u |= u << 32;
-#endif
-
-        while (cb >= sizeof(KUPTR))
-        {
-            cb -= sizeof(KUPTR);
-            *pu++ = u;
-        }
-    }
-
-    /*
-     * Byte by byte
-     */
-    if (cb)
-    {
-        unsigned char *pb = pv;
-        while (cb-- > 0)
-            *pb++ = ch;
-    }
-    return pvStart;
-}
-
-
-int strcmp(const char *psz1, const char *psz2)
-{
-    for (;;)
-    {
-        const char ch1 = *psz1++;
-        const char ch2 = *psz2++;
-        if (ch1 != ch2)
-            return (int)ch1 - (int)ch2;
-        if (!ch1)
-            return 0;
-    }
-}
-
-
-int strncmp(const char *psz1, const char *psz2, KSIZE cch)
-{
-    while (cch-- > 0)
-    {
-        const char ch1 = *psz1++;
-        const char ch2 = *psz2++;
-        if (ch1 != ch2)
-            return (int)ch1 - (int)ch2;
-        if (!ch1)
-            break;
-    }
-    return 0;
-}
-
-char *strchr(const char *psz, int ch)
-{
-    for (;;)
-    {
-        const char chCur = *psz;
-        if (chCur == ch)
-            return (char *)psz;
-        if (!chCur)
-            return 0;
-        psz++;
-    }
-}
-
-KSIZE strlen(const char *psz)
-{
-    const char *pszStart = psz;
-    while (*psz)
-        psz++;
-    return psz - pszStart;
-}
-
Index: trunk/kStuff/kLdr/kLdrHlp-os2.c
===================================================================
--- trunk/kStuff/kLdr/kLdrHlp-os2.c	(revision 3572)
+++ 	(revision )
@@ -1,35 +1,0 @@
-/* $Id$ */
-/** @file
- *
- * kLdr - The Dynamic Loader, Helper Functions for OS/2.
- *
- * Copyright (c) 2006 knut st. osmundsen <bird@anduin.net>
- *
- *
- * This file is part of kLdr.
- *
- * kLdr is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * kLdr is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with kLdr; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-#include "kLdrHlp.h"
-#include <os2emx.h>
-
-
-/*******************************************************************************
-*   Global Variables                                                           *
-*******************************************************************************/
-
-
Index: trunk/kStuff/kLdr/kLdrHlp.c
===================================================================
--- trunk/kStuff/kLdr/kLdrHlp.c	(revision 3572)
+++ 	(revision )
@@ -1,280 +1,0 @@
-/* $Id$ */
-/** @file
- *
- * kLdr - The Dynamic Loader, Misc Helper Functions.
- *
- * Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net>
- *
- *
- * This file is part of kLdr.
- *
- * kLdr is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * kLdr is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with kLdr; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-
-/*******************************************************************************
-*   Header Files                                                               *
-*******************************************************************************/
-#ifdef __OS2__
-# define INCL_BASE
-# define INCL_ERRORS
-# include <os2.h>
-#elif defined(__WIN__)
-# include <Windows.h>
-#else
-# error "port me"
-#endif
-
-#include <k/kLdr.h>
-#include "kLdrHlp.h"
-
-
-/**
- * Get an environment variable.
- *
- * @returns 0 on success.
- * @returns KLDR_ERR_BUFFER_OVERFLOW on if the buffer is too small.
- * @returns KLDR_ERR_SYMBOL_NOT_FOUND if not found. (Yeah, abusing the status code, but it's only internally...)
- * @returns OS specfic status code on other error.
- * @param   pszVar      The variable name.
- * @param   pszVal      Where to store the value.
- * @param   cchVal      The size of the buffer pointed to by pszVal.
- */
-int     kldrHlpGetEnv(const char *pszVar, char *pszVal, KSIZE cchVal)
-{
-#ifdef __OS2__
-    PSZ pszValue = NULL;
-    int rc;
-
-    *pszVal = '\0';
-    rc = DosScanEnv((PCSZ)pszVar, &pszValue);
-    if (!rc)
-    {
-        KSIZE  cch = kLdrHlpStrLen((const char *)pszValue);
-        if (cchVal > cch)
-            kLdrHlpMemCopy(pszVal, pszValue, cch + 1);
-        else
-            rc = KLDR_ERR_BUFFER_OVERFLOW;
-    }
-    else
-        rc = KLDR_ERR_SYMBOL_NOT_FOUND;
-    return rc;
-
-#elif defined(__WIN__)
-    DWORD cch;
-
-    SetLastError(0);
-    cch = GetEnvironmentVariable(pszVar, pszVal, cchVal);
-    if (cch > 0 && cch < cchVal)
-        return 0;
-
-    *pszVal = '\0';
-    if (cch >= cchVal)
-        return KLDR_ERR_BUFFER_OVERFLOW;
-    if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
-        return KLDR_ERR_SYMBOL_NOT_FOUND;
-    return GetLastError();
-
-#else
-# error "Port me"
-#endif
-}
-
-
-/**
- * Gets an environment variable and converts it to a KSIZE.
- *
- * @returns 0 and *pcb on success.
- * @returns On failure see kldrHlpGetEnv.
- * @param   pszVar  The name of the variable.
- * @param   pcb     Where to put the value.
- */
-int     kldrHlpGetEnvUZ(const char *pszVar, KSIZE *pcb)
-{
-    KSIZE       cb;
-    unsigned    uBase;
-    char        szVal[64];
-    KSIZE       cchVal = sizeof(szVal);
-    const char *psz;
-    int         rc;
-
-    *pcb = 0;
-    rc = kldrHlpGetEnv(pszVar, szVal, cchVal);
-    if (rc)
-        return rc;
-
-    /* figure out the base. */
-    uBase = 10;
-    psz = szVal;
-    if (    *psz == '0'
-        &&  (psz[1] == 'x' || psz[1] == 'X'))
-    {
-        uBase = 16;
-        psz += 2;
-    }
-
-    /* convert it up to the first unknown char. */
-    cb = 0;
-    for(;;)
-    {
-        const char ch = *psz;
-        unsigned uDigit;
-        if (!ch)
-            break;
-        else if (ch >= '0' && ch <= '9')
-            uDigit = ch - '0';
-        else if (ch >= 'a' && ch <= 'z')
-            uDigit = ch - 'a' + 10;
-        else if (ch >= 'A' && ch <= 'Z')
-            uDigit = ch - 'A' + 10;
-        else
-            break;
-        if (uDigit >= uBase)
-            break;
-
-        /* add the digit */
-        cb *= uBase;
-        cb += uDigit;
-
-        psz++;
-    }
-
-    /* check for unit */
-    if (*psz == 'm' || *psz == 'M')
-        cb *= 1024*1024;
-    else if (*psz == 'k' ||*psz == 'K')
-        cb *= 1024;
-    else if (*psz == 'g' || *psz == 'G')
-        cb *= 1024*1024*1024;
-
-    *pcb = cb;
-    return 0;
-}
-
-
-/**
- * Terminate the process.
- *
- * @param   rc      The exit status.
- */
-void    kldrHlpExit(int rc)
-{
-    for (;;)
-    {
-#ifdef __OS2__
-        DosExit(EXIT_PROCESS, rc);
-
-#elif defined(__WIN__)
-        TerminateProcess(GetCurrentProcess(), rc);
-
-#else
-# error "Port me"
-#endif
-        kldrHlpAssert(!"Impossible");
-    }
-}
-
-
-/**
- * Sleep for a number of milliseconds.
- * @param   cMillies    Number of milliseconds to sleep.
- */
-void kldrHlpSleep(unsigned cMillies)
-{
-#ifdef __OS2__
-    DosSleep(cMillies);
-#elif defined(__WIN__)
-    Sleep(cMillies);
-#else
-    usleep(cMillies * 1000);
-#endif
-}
-
-
-/**
- * Writes a assert string with unix lineendings.
- *
- * @param   pszMsg  The string.
- */
-static void kldrHlpAssertWrite(const char *pszMsg)
-{
-#if defined(__OS2__) || defined(__WIN__)
-    /*
-     * Line by line.
-     */
-    ULONG       cbWritten;
-    const char *pszNl = kLdrHlpStrChr(pszMsg, '\n');
-    while (pszNl)
-    {
-        cbWritten = pszNl - pszMsg;
-
-#ifdef __OS2__
-        if (cbWritten)
-            DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
-        DosWrite((HFILE)2, "\r\n", 2, &cbWritten);
-#else /* __WIN32__ */
-        if (cbWritten)
-            WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
-        WriteFile((HANDLE)STD_ERROR_HANDLE, "\r\n", 2, &cbWritten, NULL);
-#endif
-
-        /* next */
-        pszMsg = pszNl + 1;
-        pszNl = kLdrHlpStrChr(pszMsg, '\n');
-    }
-
-    /*
-     * Remaining incomplete line.
-     */
-    if (*pszMsg)
-    {
-        cbWritten = kLdrHlpStrLen(pszMsg);
-#ifdef __OS2__
-        DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
-#else /* __WIN32__ */
-        WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
-#endif
-    }
-
-#else
-# error "port me"
-#endif
-}
-
-
-/**
- * Internal worker for the kLdrHlpAssert() macro.
- *
- * @param   pszExpr         The assert expression.
- * @param   pszFile         The filename.
- * @param   iLine           The line number.
- * @param   pszFunction     The function name.
- */
-void    kldrHlpAssertMsg(const char *pszExpr, const char *pszFile, unsigned iLine, const char *pszFunction)
-{
-    char szLine[16];
-
-    kldrHlpAssertWrite("\n!!!kLdr Assertion Failed!!!\nExpression: ");
-    kldrHlpAssertWrite(pszExpr);
-    kldrHlpAssertWrite("\nAt: ");
-    kldrHlpAssertWrite(pszFile);
-    kldrHlpAssertWrite("(");
-    kldrHlpAssertWrite(kldrHlpInt2Ascii(szLine, sizeof(szLine), iLine, 10));
-    kldrHlpAssertWrite(") ");
-    kldrHlpAssertWrite(pszFunction);
-    kldrHlpAssertWrite("\n");
-}
-
Index: trunk/kStuff/kLdr/kLdrHlp.h
===================================================================
--- trunk/kStuff/kLdr/kLdrHlp.h	(revision 3572)
+++ trunk/kStuff/kLdr/kLdrHlp.h	(revision 3573)
@@ -1,290 +1,9 @@
-/* $Id$ */
-/** @file
- *
- * kLdr - The Dynamic Loader, Helper Functions.
- *
- * Copyright (c) 2006 knut st. osmundsen <bird@anduin.net>
- *
- *
- * This file is part of kLdr.
- *
- * kLdr is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * kLdr is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with kLdr; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-
-#ifndef __kLdrHlp_h__
-#define __kLdrHlp_h__
-
-/** @defgroup grp_kLdrHlp  kLdrHlp - Helper Functions
- * @internal
- * @{ */
-
-/*
- * Compiler specific helpers / CRT.
- * (I.e. operations that tend to have compiler intrinsic implementations).
- */
-#ifndef KLDR_USE_CRT
-
-# ifdef __GNUC__
-/** memchr */
-#  define kLdrHlpMemChr(a,b,c)  __builtin_memchr(a,b,c)
-/** memcmp */
-#  define kLdrHlpMemComp(a,b,c) __builtin_memcmp(a,b,c)
-/** memcpy */
-#  define kLdrHlpMemCopy(a,b,c) __builtin_memcpy(a,b,c)
-/** memmove */
-/*# define kLdrHlpMemMove(a,b,c) __builtin_memmove(a,b,c)*/
-#  define kLdrHlpMemMove_needed
-/** memset */
-#  define kLdrHlpMemSet(a,b,c)  __builtin_memset(a,b,c)
-/** strchr */
-#  define kLdrHlpStrChr(a, b)   __builtin_strchr(a, b)
-/** strcmp */
-#  define kLdrHlpStrComp(a, b)  __builtin_strcmp(a, b)
-/** strncmp */
-#  define kLdrHlpStrNComp(a,b,c) __builtin_strncmp(a, b, c)
-/** strlen */
-#  define kLdrHlpStrLen(a)      __builtin_strlen(a)
-/** alloca */
-#  define kLdrHlpAllocA(a)      __builtin_alloca(a)
-/** int3 */
-#  define kldrHlpBreakpoint() do { __asm__ __volatile__ ("int3\n\tnop"); } while (0)
-/** NULL */
-#  ifndef NULL
-#   define NULL 0
-#  endif
-# endif
-
-# ifdef _MSC_VER
-#  include <string.h>
-#  include <malloc.h>
-#  pragma intrinsic(memcmp, memcpy, memset, strcmp, strlen, __debugbreak)
-/** memchr */
-#  define kLdrHlpMemChr_needed
-/** memcmp */
-#  define kLdrHlpMemComp(a,b,c) memcmp(a,b,c)
-/** memcpy */
-#  define kLdrHlpMemCopy(a,b,c) memcpy(a,b,c)
-/** memmove */
-#  define kLdrHlpMemMove_needed
-/** memset */
-#  define kLdrHlpMemSet(a,b,c)  memset(a,b,c)
-/** strcmp */
-#  define kLdrHlpStrComp(a, b)  strcmp(a, b)
-/** strncmp */
-#  define kLdrHlpStrNComp_needed
-/** strlen */
-#  define kLdrHlpStrLen(a)      strlen(a)
-/** strchr */
-#  define kLdrHlpStrChr_needed
-/** alloca */
-#  define kLdrHlpAllocA(a)      alloca(a)
-/** int3 */
-#  define kldrHlpBreakpoint() __debugbreak()
-/** NULL */
-#  ifndef NULL
-#   define NULL 0
-#  endif
-# endif
-
-# ifdef kLdrHlpStrChr_needed
-char   *kLdrHlpStrChr(const char *psz, int ch);
-# endif
-# ifdef kLdrHlpStrChr_needed
-int     kLdrHlpStrNComp(const char *psz1, const char *psz2, KSIZE cch);
-# endif
-# ifdef kLdrHlpMemChr_needed
-void   *kLdrHlpMemChr(const void *pv, int ch, KSIZE cb);
-# endif
-# ifdef kLdrHlpMemMove_needed
-void   *kLdrHlpMemMove(void *pv1, const void *pv2, KSIZE cb);
-# endif
-
-
-#else /* KLDR_USE_CRT */
-
-#  include <string.h>
-#  include <stdlib.h>
-#  ifdef _MSC_VER
-#   include <malloc.h>
-#  endif
-
-#  define kLdrHlpMemChr(a,b,c)  memchr(a,b,c)
-/** memcmp */
-#  define kLdrHlpMemComp(a,b,c) memcmp(a,b,c)
-/** memcpy */
-#  define kLdrHlpMemCopy(a,b,c) memcpy(a,b,c)
-/** memmove */
-#  define kLdrHlpMemMove(a,b,c) memmove(a,b,c)
-/** memset */
-#  define kLdrHlpMemSet(a,b,c)  memset(a,b,c)
-/** strchr */
-#  define kLdrHlpStrChr(a, b)   strchr(a, b)
-/** strcmp */
-#  define kLdrHlpStrComp(a, b)  strcmp(a, b)
-/** strncmp */
-#  define kLdrHlpStrNComp(a,b,c) strncmp(a, b, c)
-/** strlen */
-#  define kLdrHlpStrLen(a)      strlen(a)
-/** alloca */
-#  define kLdrHlpAllocA(a)      alloca(a)
-/** int3 */
-#  ifdef __GNUC__
-#   define kldrHlpBreakpoint() do { __asm__ __volatile__ ("int3\n\tnop"); } while (0)
-#  endif
-#  ifdef _MSC_VER
-#   define kldrHlpBreakpoint() __debugbreak()
-#  endif
-
-#endif
-
-#if (!defined(kLdrHlpMemChr) && !defined(kLdrHlpStrChr_needed))\
- || !defined(kLdrHlpMemComp) \
- || !defined(kLdrHlpMemCopy) \
- || !defined(kLdrHlpMemSet) \
- || (!defined(kLdrHlpStrChr) && !defined(kLdrHlpStrChr_needed)) \
- || !defined(kLdrHlpStrComp) \
- || (!defined(kLdrHlpStrNComp) && !defined(kLdrHlpStrNComp_needed)) \
- || !defined(kLdrHlpStrLen) \
- || !defined(kLdrHlpAllocA) \
- || !defined(kldrHlpBreakpoint)
-# error "Needs porting to your compiler."
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-KSIZE   kLdrHlpStrNLen(const char *psz, KSIZE cchMax);
-int     kLdrHlpMemIComp(const void *pv1, const void *pv2, KSIZE cb);
-int     kLdrHlpStrIComp(const char *pv1, const char *pv2);
-
-int     kldrHlpSemInit(void);
-void    kldrHlpSemTerm(void);
-int     kldrHlpSemRequest(void);
-void    kldrHlpSemRelease(void);
-
-int     kldrHlpPageAlloc(void **ppv, KSIZE cb, KPROT enmProt, unsigned fFixed);
-int     kldrHlpPageProtect(void *pv, KSIZE cb, KPROT enmProt);
-int     kldrHlpPageFree(void *pv, KSIZE cb);
-
-int     kldrHlpHeapInit(void);
-void    kldrHlpHeapTerm(void);
-void    kldrHlpHeapDonate(void *pv, KSIZE cb);
-void *  kldrHlpAlloc(KSIZE cb);
-void *  kldrHlpAllocZ(KSIZE cb);
-void    kldrHlpFree(void *pv);
 
 int     kldrHlpGetEnv(const char *pszVar, char *pszVal, KSIZE cchVal);
 int     kldrHlpGetEnvUZ(const char *pszVar, KSIZE *pcb);
-char   *kldrHlpGetFilename(const char *pszFilename);
-char   *kldrHlpGetSuff(const char *pszFilename);
-char   *kldrHlpGetExt(const char *pszFilename);
-int     kldrHlpIsFilenameOnly(const char *pszFilename);
+
 void    kldrHlpExit(int rc);
 void    kldrHlpSleep(unsigned cMillies);
+
 char   *kldrHlpInt2Ascii(char *psz, KSIZE cch, long lVal, unsigned iBase);
-void    kldrHlpAssertMsg(const char *pszExpr, const char *pszFile, unsigned iLine, const char *pszFunction);
 
-#ifdef __cplusplus
-}
-#endif
-
-
-/** Assertion macro.
- * Users should wrap it since this is ALWAYS compiled in. */
-#define kldrHlpAssert(expr) \
-    do { \
-        if (!(expr)) \
-        { \
-            kldrHlpAssertMsg(#expr, __FILE__, __LINE__, __FUNCTION__); \
-            kldrHlpBreakpoint(); \
-        } \
-    } while (0)
-
-
-/** @name Parameter validation macros
- * @{ */
-
-/** Crash validation of a string argument. */
-#define KLDRHLP_VALIDATE_STRING(str) \
-    do { kLdrHlpStrLen(str); } while (0)
-
-/** Crash validation of an optional string argument. */
-#define KLDRHLP_VALIDATE_OPTIONAL_STRING(str) \
-    do { if (str) { KLDRHLP_VALIDATE_STRING(str); } } while (0)
-
-/** Return/Crash validation of an output buffer. */
-#define KLDRHLP_VALIDATE_BUFFER(buf, cb) \
-    do { \
-        if ((cb)) \
-        { \
-            KU8             __b; \
-            KU8 volatile *  __pb = (KU8 volatile *)(buf); \
-            KSIZE           __cbPage1 = 0x1000 - ((KUPTR)(__pb) & 0xfff); /* ASSUMES page size! */ \
-            __b = *__pb; *__pb = 0xff; *__pb = __b; \
-            if ((cb) > __cbPage1) \
-            { \
-                KSIZE   __cb = (cb) - __cbPage1; \
-                __pb -= __cbPage1; \
-                for (;;) \
-                { \
-                    __b = *__pb; *__pb = 0xff; *__pb = __b; \
-                    if (__cb < 0x1000) \
-                        break; \
-                    __pb += 0x1000; \
-                    __cb -= 0x1000; \
-                } \
-            } \
-        } \
-        else \
-            return KLDR_ERR_INVALID_PARAMETER; \
-    } while (0)
-
-/** Crash validation of an optional output buffer. */
-#define KLDRHLP_VALIDATE_OPTIONAL_BUFFER(buf, cb) \
-    do { \
-        if ((buf) != NULL && (cb) != 0) \
-        { \
-            KLDRHLP_VALIDATE_BUFFER(buf, cb); \
-        } \
-    } while (0)
-
-/** Return validation of an enum argument. */
-#define KLDRHLP_VALIDATE_ENUM(arg, enumname) \
-    do { \
-        if ((arg) <= enumname##_INVALID || (arg) >= enumname##_END) \
-        {  \
-            return KLDR_ERR_INVALID_PARAMETER; \
-        } \
-    } while (0)
-
-/** Return validation of a flags argument. */
-#define KLDRHLP_VALIDATE_FLAGS(arg, AllowedMask) \
-    do { \
-        if ((arg) & ~(AllowedMask)) \
-        {  \
-            return KLDR_ERR_INVALID_PARAMETER; \
-        } \
-    } while (0)
-
-/** @} */
-
-
-/** @} */
-
-#endif /* __kLdrHlp_h__ */
-
Index: trunk/kStuff/kLdr/kLdrHlpHeap.c
===================================================================
--- trunk/kStuff/kLdr/kLdrHlpHeap.c	(revision 3572)
+++ 	(revision )
@@ -1,705 +1,0 @@
-/* $Id$ */
-/** @file
- *
- * kLdr - The Dynamic Loader, Helper Functions, Heap.
- *
- * Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net>
- *
- *
- * This file is part of kLdr.
- *
- * kLdr is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * kLdr is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with kLdr; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-#define KLDRHEAP_STRICT
-
-/*******************************************************************************
-*   Header Files                                                               *
-*******************************************************************************/
-#ifdef __OS2__
-# define INCL_BASE
-# define INCL_ERRORS
-# include <os2.h>
-#elif defined(__WIN__)
-# include <Windows.h>
-#else
-# error "port me"
-#endif
-
-#include <k/kLdr.h>
-#include "kLdrHlp.h"
-
-
-
-/*******************************************************************************
-*   Structures and Typedefs                                                    *
-*******************************************************************************/
-/**
- * A heap block.
- */
-typedef struct KLDRHEAPBLOCK
-{
-    /** Next block in the global list. */
-    struct KLDRHEAPBLOCK   *pNext;
-    /** Previous block in the global list. */
-    struct KLDRHEAPBLOCK   *pPrev;
-    /** The size of this block including this header. */
-    KSIZE                   cb;
-    /** The flags. */
-    KSIZE                   fFlags;
-} KLDRHEAPBLOCK, *PKLDRHEAPBLOCK;
-
-/** Indicates whether the block is free (set) or allocated (clear). */
-#define KLDRHEAPBLOCK_FLAG_FREE     ((KSIZE)1)
-/** Valid flag mask. */
-#define KLDRHEAPBLOCK_FLAG_MASK     ((KSIZE)1)
-
-/** Checks if the block is freed. */
-#define KLDRHEAPBLOCK_IS_FREE(pB)       ( (pB)->fFlags & KLDRHEAPBLOCK_FLAG_FREE )
-/** Check if the block is allocated. */
-#define KLDRHEAPBLOCK_IS_ALLOCATED(pB)  !KLDRHEAPBLOCK_IS_FREE(pB)
-/** Checks if the two blocks are adjacent.
- * Assumes pB1 < pB2. */
-#define KLDRHEAPBLOCK_IS_ADJACENT(pB1, pB2) \
-    ( ((KUPTR)(pB1) + (pB1)->cb) == (KUPTR)(pB2) )
-
-/** The block alignment. */
-#define KLDRHEAPBLOCK_ALIGNMENT     sizeof(KLDRHEAPBLOCK)
-
-/** @def KLDRHEAP_ASSERT
- * Heap assertion. */
-/** @def KLDRHEAP_ASSERT_BLOCK
- * Assert that a heap block is valid. */
-/** @def KLDRHEAP_ASSERT_FREE
- * Assert that a heap free block is valid. */
-#ifdef KLDRHEAP_STRICT
-# define KLDRHEAP_ASSERT(expr)      kldrHlpAssert(expr)
-
-# define KLDRHEAP_ASSERT_BLOCK(pHeap, pBlock) \
-    do { \
-        KLDRHEAP_ASSERT(!((pBlock)->fFlags & ~KLDRHEAPBLOCK_FLAG_MASK)); \
-        KLDRHEAP_ASSERT(!((pBlock)->cb & (KLDRHEAPBLOCK_ALIGNMENT - 1))); \
-        KLDRHEAP_ASSERT((KUPTR)(pBlock)->pPrev < (KUPTR)(pBlock)); \
-        KLDRHEAP_ASSERT((KUPTR)(pBlock)->pNext > (KUPTR)(pBlock) || !(pBlock)->pNext); \
-    } while (0)
-
-# define KLDRHEAP_ASSERT_FREE(pHeap, pFree) \
-    do { \
-        KLDRHEAP_ASSERT_BLOCK(pHeap, &(pFree)->Core); \
-        KLDRHEAP_ASSERT((KUPTR)(pFree)->pPrev < (KUPTR)(pFree)); \
-        KLDRHEAP_ASSERT((KUPTR)(pFree)->pNext > (KUPTR)(pFree) || !(pFree)->pNext); \
-    } while (0)
-
-#else
-# define KLDRHEAP_ASSERT(expr)          do { } while (0)
-# define KLDRHEAP_ASSERT_BLOCK(pH, pB)  do { } while (0)
-# define KLDRHEAP_ASSERT_FREE(pH, pF)   do { } while (0)
-#endif
-
-
-/**
- * A free heap block.
- */
-typedef struct KLDRHEAPFREE
-{
-    /** The core bit which we have in common with used blocks. */
-    KLDRHEAPBLOCK           Core;
-    /** The next free block. */
-    struct KLDRHEAPFREE    *pNext;
-    /** The previous free block. */
-    struct KLDRHEAPFREE    *pPrev;
-} KLDRHEAPFREE, *PKLDRHEAPFREE;
-
-
-/**
- * A heap segment.
- */
-typedef struct KLDRHEAPSEG
-{
-    /** The base address of the segment. */
-    void   *pvBase;
-    /** The length of the segment (in bytes). */
-    KSIZE   cb;
-} KLDRHEAPSEG, *PKLDRHEAPSEG;
-
-/**
- * Bundle of heap segments.
- */
-typedef struct KLDRHEAPSEGS
-{
-    /** Pointer to the next segment bundle. */
-    struct KLDRHEAPSEGS    *pNext;
-    /** The number of segments used. */
-    KU32                    cSegs;
-    /** Array of chunks. */
-    KLDRHEAPSEG             aSegs[64];
-} KLDRHEAPSEGS, *PKLDRHEAPSEGS;
-
-
-/**
- * Heap anchor block.
- */
-typedef struct KLDRHEAPANCHOR
-{
-    /** Head of the block list. */
-    PKLDRHEAPBLOCK      pHead;
-    /** Tail of the block list. */
-    PKLDRHEAPBLOCK      pTail;
-    /** Head of the free list. */
-    PKLDRHEAPFREE       pFreeHead;
-    /** Head segment bundle.
-     * The order of this list is important, but a bit peculiar.
-     * Logically, SegsHead::pNext is the tail pointer. */
-    KLDRHEAPSEGS        SegsHead;
-} KLDRHEAPANCHOR, *PKLDRHEAPANCHOR;
-
-
-
-/*******************************************************************************
-*   Global Variables                                                           *
-*******************************************************************************/
-/** The heap anchor block. */
-static KLDRHEAPANCHOR g_Heap;
-
-
-/*******************************************************************************
-*   Internal Functions                                                         *
-*******************************************************************************/
-static int      kLdrHeapInit(PKLDRHEAPANCHOR pHeap);
-static void     kLdrHeapDelete(PKLDRHEAPANCHOR pHeap);
-static void *   kLdrHeapAlloc(PKLDRHEAPANCHOR pHeap, KSIZE cb);
-static void     kLdrHeapFree(PKLDRHEAPANCHOR pHeap, void *pv);
-static void     kLdrHeapDonate(PKLDRHEAPANCHOR pHeap, void *pv, KSIZE cb);
-static int      kLdrHeapSegAlloc(PKLDRHEAPSEG pSeg, KSIZE cb);
-static void     kLdrHeapSegFree(PKLDRHEAPSEG pSeg);
-
-
-/**
- * Initializes the kLdr heap.
- *
- * @returns 0 on success, non-zero OS specific status code on failure.
- */
-int kldrHlpHeapInit(void)
-{
-    return kLdrHeapInit(&g_Heap);
-}
-
-
-/**
- * Terminates the kLdr heap.
- */
-void kldrHlpHeapTerm(void)
-{
-    kLdrHeapDelete(&g_Heap);
-}
-
-
-/**
- * Allocates memory from the kLdr heap.
- *
- * @returns Pointer to the allocated heap block. NULL if we can't satify the request.
- * @param   cb      The requested heap block size.
- */
-void *kldrHlpAlloc(KSIZE cb)
-{
-    return kLdrHeapAlloc(&g_Heap, cb);
-}
-
-
-/**
- * Allocates zero initialized memory from the kLdr heap.
- *
- * @returns Pointer to the allocated heap block. NULL if we can't satify the request.
- * @param   cb      The requested heap block size.
- */
-void *kldrHlpAllocZ(KSIZE cb)
-{
-    void *pv = kLdrHeapAlloc(&g_Heap, cb);
-    if (pv)
-        kLdrHlpMemSet(pv, 0, cb);
-    return pv;
-}
-
-
-/**
- * Frees memory allocated off the kLdr heap.
- *
- * @param   pv      Pointer to the heap block returned by kldrHlpAlloc().
- */
-void kldrHlpFree(void *pv)
-{
-    kLdrHeapFree(&g_Heap, pv);
-}
-
-
-/**
- * Donates memory to the heap.
- *
- * @param   pv      The address of the memory.
- * @param   cb      The amount of memory.
- */
-void kldrHlpHeapDonate(void *pv, KSIZE cb)
-{
-    kLdrHeapDonate(&g_Heap, pv, cb);
-}
-
-
-
-/**
- * Initializes the heap anchor.
- *
- * @returns 0 on success, non-zero on failure.
- * @param   pHeap   The heap anchor to be initialized.
- */
-static int kLdrHeapInit(PKLDRHEAPANCHOR pHeap)
-{
-    pHeap->pHead = NULL;
-    pHeap->pTail = NULL;
-    pHeap->pFreeHead = NULL;
-    pHeap->SegsHead.pNext = NULL;
-    pHeap->SegsHead.cSegs = 0;
-    return 0;
-}
-
-
-/**
- * Deletes a heap.
- * This will free all resources (memory) associated with the heap.
- *
- * @param   pHeap   The heap to be deleted.
- */
-static void kLdrHeapDelete(PKLDRHEAPANCHOR pHeap)
-{
-    /*
-     * Free the segments, LIFO order.
-     * The head element is the last to be free, while the
-     * head.pNext is really the tail pointer - neat or what?
-     */
-    while (     pHeap->SegsHead.cSegs
-           ||   pHeap->SegsHead.pNext)
-    {
-        /* find the tail. */
-        KU32            iSeg;
-        PKLDRHEAPSEGS   pSegs = pHeap->SegsHead.pNext;
-        if (!pSegs)
-            pSegs = &pHeap->SegsHead;
-        else
-        {
-            pHeap->SegsHead.pNext = pSegs->pNext;
-            pSegs->pNext = NULL;
-        }
-
-        /* free the segments */
-        iSeg = pSegs->cSegs;
-        while (iSeg-- > 0)
-            kLdrHeapSegFree(&pSegs->aSegs[iSeg]);
-        pSegs->cSegs = 0;
-    }
-
-    /* Zap the anchor. */
-    pHeap->pHead = NULL;
-    pHeap->pTail = NULL;
-    pHeap->pFreeHead = NULL;
-    pHeap->SegsHead.pNext = NULL;
-    pHeap->SegsHead.cSegs = 0;
-}
-
-
-/**
- * Internal heap block allocator.
- */
-static void *   kldrHeapAllocSub(PKLDRHEAPANCHOR pHeap, KSIZE cb)
-{
-    /*
-     * Find a fitting free block.
-     */
-    const KSIZE     cbReq = K_ALIGN_Z(cb + sizeof(KLDRHEAPBLOCK), KLDRHEAPBLOCK_ALIGNMENT);
-    PKLDRHEAPFREE   pCur = pHeap->pFreeHead;
-    while (pCur)
-    {
-        if (pCur->Core.cb >= cbReq)
-        {
-            if (pCur->Core.cb != cbReq)
-            {
-                /* check and see if there is a better match close by. */
-                PKLDRHEAPFREE pCur2 = pCur->pNext;
-                unsigned i = 16;
-                while (i-- > 0 && pCur2)
-                {
-                    if (pCur2->Core.cb >= cbReq)
-                    {
-                        if (pCur2->Core.cb == cbReq)
-                        {
-                            pCur = pCur2;
-                            break;
-                        }
-                        if (pCur2->Core.cb < pCur->Core.cb)
-                            pCur = pCur2;
-                    }
-
-                    /* next */
-                    KLDRHEAP_ASSERT_FREE(pHeap, pCur2);
-                    pCur2 = pCur2->pNext;
-                }
-            }
-            break;
-        }
-
-        /* next */
-        KLDRHEAP_ASSERT_FREE(pHeap, pCur);
-        pCur = pCur->pNext;
-    }
-    if (!pCur)
-        return NULL;
-    KLDRHEAP_ASSERT_FREE(pHeap, pCur);
-
-    /*
-     * Do we need to split out a block?
-     */
-    if (pCur->Core.cb - cbReq >= KLDRHEAPBLOCK_ALIGNMENT * 2)
-    {
-        PKLDRHEAPBLOCK pNew;
-
-        pCur->Core.cb -= cbReq;
-
-        pNew = (PKLDRHEAPBLOCK)((KUPTR)pCur + pCur->Core.cb);
-        pNew->fFlags = 0;
-        pNew->cb = cbReq;
-        pNew->pNext = pCur->Core.pNext;
-        if (pNew->pNext)
-            pNew->pNext->pPrev = pNew;
-        else
-            pHeap->pTail = pNew;
-        pNew->pPrev = &pCur->Core;
-        pCur->Core.pNext = pNew;
-
-        KLDRHEAP_ASSERT_FREE(pHeap, pCur);
-        KLDRHEAP_ASSERT_BLOCK(pHeap, pNew);
-        return pNew + 1;
-    }
-
-    /*
-     * No, just unlink it from the free list and return.
-     */
-    if (pCur->pNext)
-        pCur->pNext->pPrev = pCur->pPrev;
-    if (pCur->pPrev)
-        pCur->pPrev->pNext = pCur->pNext;
-    else
-        pHeap->pFreeHead = pCur->pNext;
-    pCur->Core.fFlags &= ~KLDRHEAPBLOCK_FLAG_FREE;
-
-    KLDRHEAP_ASSERT_BLOCK(pHeap, &pCur->Core);
-    return &pCur->Core + 1;
-}
-
-
-/**
- * Allocate a heap block.
- *
- * @returns Pointer to the allocated heap block on success. On failure NULL is returned.
- * @param   pHeap   The heap.
- * @param   cb      The requested heap block size.
- */
-static void *   kLdrHeapAlloc(PKLDRHEAPANCHOR pHeap, KSIZE cb)
-{
-    void *pv;
-
-    /* adjust the requested block size. */
-    cb = K_ALIGN_Z(cb, KLDRHEAPBLOCK_ALIGNMENT);
-    if (!cb)
-        cb = KLDRHEAPBLOCK_ALIGNMENT;
-
-    /* try allocate the block. */
-    pv = kldrHeapAllocSub(pHeap, cb);
-    if (!pv)
-    {
-        /*
-         * Failed, add another segment and try again.
-         */
-        KLDRHEAPSEG Seg;
-        if (kLdrHeapSegAlloc(&Seg, cb + sizeof(KLDRHEAPSEGS) + sizeof(KLDRHEAPBLOCK) * 16))
-            return NULL;
-
-        /* donate before insterting the segment, this makes sure we got heap to expand the segment list. */
-        kLdrHeapDonate(pHeap, Seg.pvBase, Seg.cb);
-
-        /* insert the segment. */
-        if (pHeap->SegsHead.cSegs < sizeof(pHeap->SegsHead.aSegs) / sizeof(pHeap->SegsHead.aSegs[0]))
-            pHeap->SegsHead.aSegs[pHeap->SegsHead.cSegs++] = Seg;
-        else if (   pHeap->SegsHead.pNext
-                 && pHeap->SegsHead.pNext->cSegs < sizeof(pHeap->SegsHead.aSegs) / sizeof(pHeap->SegsHead.aSegs[0]))
-            pHeap->SegsHead.pNext->aSegs[pHeap->SegsHead.pNext->cSegs++] = Seg;
-        else
-        {
-            PKLDRHEAPSEGS pSegs = (PKLDRHEAPSEGS)kldrHeapAllocSub(pHeap, sizeof(*pSegs));
-            KLDRHEAP_ASSERT(pSegs);
-            pSegs->pNext = pHeap->SegsHead.pNext;
-            pHeap->SegsHead.pNext = pSegs;
-            pSegs->aSegs[0] = Seg;
-            pSegs->cSegs = 1;
-        }
-
-        /* retry (should succeed) */
-        pv = kldrHeapAllocSub(pHeap, cb);
-        KLDRHEAP_ASSERT(pv);
-    }
-
-    return pv;
-}
-
-
-/**
- * Frees a heap block.
- *
- * @param   pHeap   The heap.
- * @param   pv      The pointer returned by kLdrHeapAlloc().
- */
-static void     kLdrHeapFree(PKLDRHEAPANCHOR pHeap, void *pv)
-{
-    PKLDRHEAPFREE pFree, pLeft, pRight;
-
-    /* ignore NULL pointers. */
-    if (!pv)
-        return;
-
-    pFree = (PKLDRHEAPFREE)((PKLDRHEAPBLOCK)pv - 1);
-    KLDRHEAP_ASSERT_BLOCK(pHeap, &pFree->Core);
-    KLDRHEAP_ASSERT(KLDRHEAPBLOCK_IS_ALLOCATED(&pFree->Core));
-
-    /*
-     * Merge or link with left node?
-     */
-    pLeft = (PKLDRHEAPFREE)pFree->Core.pPrev;
-    if (    pLeft
-        &&  KLDRHEAPBLOCK_IS_FREE(&pLeft->Core)
-        &&  KLDRHEAPBLOCK_IS_ADJACENT(&pLeft->Core, &pFree->Core)
-       )
-    {
-        /* merge left */
-        pLeft->Core.pNext = pFree->Core.pNext;
-        if (pFree->Core.pNext)
-            pFree->Core.pNext->pPrev = &pLeft->Core;
-        else
-            pHeap->pTail = &pLeft->Core;
-
-        pLeft->Core.cb += pFree->Core.cb;
-        pFree->Core.fFlags = ~0;
-        pFree = pLeft;
-    }
-    else
-    {
-        /* link left */
-        while (pLeft && !KLDRHEAPBLOCK_IS_FREE(&pLeft->Core))
-            pLeft = (PKLDRHEAPFREE)pLeft->Core.pPrev;
-        if (pLeft)
-        {
-            pFree->pPrev = pLeft;
-            pFree->pNext = pLeft->pNext;
-            if (pLeft->pNext)
-                pLeft->pNext->pPrev = pFree;
-            pLeft->pNext  = pFree;
-        }
-        else
-        {
-            pFree->pPrev = NULL;
-            pFree->pNext = pHeap->pFreeHead;
-            if (pHeap->pFreeHead)
-                pHeap->pFreeHead->pPrev = pFree;
-            pHeap->pFreeHead = pFree;
-        }
-        pFree->Core.fFlags |= KLDRHEAPBLOCK_FLAG_FREE;
-    }
-    KLDRHEAP_ASSERT_FREE(pHeap, pFree);
-
-    /*
-     * Merge right?
-     */
-    pRight = (PKLDRHEAPFREE)pFree->Core.pNext;
-    if (    pRight
-        &&  KLDRHEAPBLOCK_IS_FREE(&pRight->Core)
-        &&  KLDRHEAPBLOCK_IS_ADJACENT(&pFree->Core, pRight)
-       )
-    {
-        /* unlink pRight from the global list. */
-        pFree->Core.pNext = pRight->Core.pNext;
-        if (pRight->Core.pNext)
-            pRight->Core.pNext->pPrev = &pFree->Core;
-        else
-            pHeap->pTail = &pFree->Core;
-
-        /* unlink pRight from the free list. */
-        pFree->pNext = pRight->pNext;
-        if (pRight->pNext)
-            pRight->pNext->pPrev = pFree;
-
-        /* update size and invalidate pRight. */
-        pFree->Core.cb += pRight->Core.cb;
-        pRight->Core.fFlags = ~0;
-    }
-}
-
-
-/**
- * Donates memory to the heap.
- *
- * The donated memory is returned to the donator when the heap is deleted.
- *
- * @param pHeap The heap
- * @param pv    The pointer to the donated memory.
- * @param cb    Size of the donated memory.
- */
-static void     kLdrHeapDonate(PKLDRHEAPANCHOR pHeap, void *pv, KSIZE cb)
-{
-    PKLDRHEAPBLOCK pBlock;
-
-    /*
-     * Don't bother with small donations.
-     */
-    if (cb < KLDRHEAPBLOCK_ALIGNMENT * 4)
-        return;
-
-    /*
-     * Align the donation on a heap block boundrary.
-     */
-    if ((KUPTR)pv & (KLDRHEAPBLOCK_ALIGNMENT - 1))
-    {
-        cb -= (KUPTR)pv & 31;
-        pv = K_ALIGN_P(pv, KLDRHEAPBLOCK_ALIGNMENT);
-    }
-    cb &= ~(KSIZE)(KLDRHEAPBLOCK_ALIGNMENT - 1);
-
-    /*
-     * Create an allocated block, link it and free it.
-     */
-    pBlock = (PKLDRHEAPBLOCK)pv;
-    pBlock->pNext = NULL;
-    pBlock->pPrev = NULL;
-    pBlock->cb = cb;
-    pBlock->fFlags = 0;
-
-    /* insert */
-    if ((KUPTR)pBlock < (KUPTR)pHeap->pHead)
-    {
-        /* head */
-        pBlock->pNext = pHeap->pHead;
-        pHeap->pHead->pPrev = pBlock;
-        pHeap->pHead = pBlock;
-    }
-    else if ((KUPTR)pBlock > (KUPTR)pHeap->pTail)
-    {
-        if (pHeap->pTail)
-        {
-            /* tail */
-            pBlock->pPrev = pHeap->pTail;
-            pHeap->pTail->pNext = pBlock;
-            pHeap->pTail = pBlock;
-        }
-        else
-        {
-            /* first */
-            pHeap->pHead = pBlock;
-            pHeap->pTail = pBlock;
-        }
-    }
-    else
-    {
-        /* in list (unlikely) */
-        PKLDRHEAPBLOCK pPrev = pHeap->pHead;
-        PKLDRHEAPBLOCK pCur = pPrev->pNext;
-        for (;;)
-        {
-            KLDRHEAP_ASSERT_BLOCK(pHeap, pCur);
-            if ((KUPTR)pCur > (KUPTR)pBlock)
-                break;
-            pPrev = pCur;
-            pCur = pCur->pNext;
-        }
-
-        pBlock->pNext = pCur;
-        pBlock->pPrev = pPrev;
-        pPrev->pNext = pBlock;
-        pCur->pPrev = pBlock;
-    }
-    KLDRHEAP_ASSERT_BLOCK(pHeap, pBlock);
-
-    /* free it */
-    kLdrHeapFree(pHeap, pBlock + 1);
-}
-
-
-
-/**
- * Allocates a new segment.
- *
- * @returns 0 on success, non-zero OS status code on failure.
- * @param   pSeg    Where to put the info about the allocated segment.
- * @param   cbMin   The minimum segment size.
- */
-static int kLdrHeapSegAlloc(PKLDRHEAPSEG pSeg, KSIZE cbMin)
-{
-#ifdef __OS2__
-    APIRET rc;
-
-    pSeg->cb = (cbMin + 0xffff) & ~(KSIZE)0xffff;
-    pSeg->pvBase = NULL;
-    rc = DosAllocMem(&pSeg->pvBase, pSeg->cb, PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_ANY);
-    if (rc == ERROR_INVALID_PARAMETER)
-        rc = DosAllocMem(&pSeg->pvBase, pSeg->cb, PAG_COMMIT | PAG_READ | PAG_WRITE);
-    if (rc)
-    {
-        pSeg->pvBase = NULL;
-        pSeg->cb = 0;
-        return rc;
-    }
-
-#elif defined(__WIN__)
-    pSeg->cb = (cbMin + 0xffff) & ~(KSIZE)0xffff;
-    pSeg->pvBase = VirtualAlloc(NULL, pSeg->cb, MEM_COMMIT, PAGE_READWRITE);
-    if (!pSeg->pvBase)
-    {
-        pSeg->cb = 0;
-        return GetLastError();
-    }
-
-#else
-# error "Port me"
-#endif
-
-    return 0;
-}
-
-
-/**
- * Frees a segment.
- *
- * @param   pSeg    The segment to be freed.
- */
-static void kLdrHeapSegFree(PKLDRHEAPSEG pSeg)
-{
-#ifdef __OS2__
-    APIRET rc = DosFreeMem(pSeg->pvBase);
-    KLDRHEAP_ASSERT(!rc); (void)rc;
-
-#elif defined(__WIN__)
-    BOOL fRc = VirtualFree(pSeg->pvBase, 0 /*pSeg->cb*/, MEM_RELEASE);
-    KLDRHEAP_ASSERT(fRc); (void)fRc;
-
-#else
-# error "Port me"
-#endif
-}
-
Index: trunk/kStuff/kLdr/kLdrHlpMem.c
===================================================================
--- trunk/kStuff/kLdr/kLdrHlpMem.c	(revision 3572)
+++ 	(revision )
@@ -1,280 +1,0 @@
-/* $Id$ */
-/** @file
- *
- * kLdr - The Dynamic Loader, Memory Helper Functions.
- *
- * Copyright (c) 2006-2007 knut st. osmundsen <bird-kbuild-src@anduin.net>
- *
- *
- * This file is part of kLdr.
- *
- * kLdr is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * kLdr is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with kLdr; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-
-/*******************************************************************************
-*   Header Files                                                               *
-*******************************************************************************/
-#ifdef __OS2__
-# define INCL_BASE
-# define INCL_ERRORS
-# include <os2.h>
-#elif defined(__WIN__)
-# include <Windows.h>
-#else
-# error "port me"
-#endif
-
-#include <k/kLdr.h>
-#include "kLdrHlp.h"
-
-
-/*******************************************************************************
-*   Global Variables                                                           *
-*******************************************************************************/
-#ifdef __OS2__
-/** The base of the stub object.
- * The OS/2 exe stub consists of a single data object. When allocating memory
- * for an executable, we'll have to reuse this.  */
-static void            *g_pvStub = NULL;
-/** The size of the stub object - 0 if no stub. */
-static KSIZE            g_cbStub = 0;
-
-#elif defined(__WIN__)
-/** The system info. */
-static SYSTEM_INFO      g_SystemInfo;
-#else
-# error "port me"
-#endif
-
-
-
-#ifdef __OS2__
-static ULONG kldrHlpPageProtToNative(KPROT enmProt)
-{
-    switch (enmProt)
-    {
-        case KPROT_NOACCESS:             return PAG_EXECUTE | PAG_READ | PAG_WRITE;
-        case KPROT_READONLY:             return PAG_COMMIT | PAG_READ;
-        case KPROT_READWRITE:            return PAG_COMMIT | PAG_READ | PAG_WRITE;
-        case KPROT_EXECUTE:              return PAG_COMMIT | PAG_EXECUTE;
-        case KPROT_EXECUTE_READ:         return PAG_COMMIT | PAG_EXECUTE | PAG_READ;
-        case KPROT_EXECUTE_READWRITE:    return PAG_COMMIT | PAG_EXECUTE | PAG_READ | PAG_WRITE;
-        default:
-            kldrHlpAssert(0);
-            return ~0U;
-    }
-}
-#elif defined(__WIN__)
-static DWORD kldrHlpPageProtToNative(KPROT enmProt)
-{
-    switch (enmProt)
-    {
-        case KPROT_NOACCESS:             return PAGE_NOACCESS;
-        case KPROT_READONLY:             return PAGE_READONLY;
-        case KPROT_READWRITE:            return PAGE_READWRITE;
-        case KPROT_EXECUTE:              return PAGE_EXECUTE;
-        case KPROT_EXECUTE_READ:         return PAGE_EXECUTE_READ;
-        case KPROT_EXECUTE_READWRITE:    return PAGE_EXECUTE_READWRITE;
-        default:
-            kldrHlpAssert(0);
-            return ~0U;
-    }
-}
-#endif
-
-
-/**
- * Allocate a chunk of memory with page granularity.
- *
- * @returns 0 on success, non-zero OS status code on failure.
- * @param   ppv         Where to store the address of the allocated memory.
- *                      If fFixed is set, *ppv will on entry contain the desired address (page aligned).
- * @param   cb          Number of bytes. Page aligned.
- * @param   enmProt     The new protection. Copy-on-write is invalid.
- */
-int     kldrHlpPageAlloc(void **ppv, KSIZE cb, KPROT enmProt, unsigned fFixed)
-{
-#ifdef __OS2__
-    APIRET  rc;
-    ULONG   fFlags = kldrHlpPageProtToNative(enmProt);;
-
-    if (!fFixed)
-    {
-        /* simple */
-        rc = DosAllocMem(ppv, cb, fFlags | OBJ_ANY);
-        if (rc == ERROR_INVALID_PARAMETER)
-            rc = DosAllocMem(ppv, cb, fFlags);
-    }
-    else
-    {
-        /* not so simple. */
-        /** @todo I've got code for this in libc somewhere. */
-        rc = -1;
-    }
-    if (!rc)
-        return 0;
-    kldrHlpAssert(0);
-    return rc;
-
-#elif defined(__WIN__)
-    /* (We don't have to care about the stub here, because the stub will be unmapped before we get here.) */
-    int     rc;
-    DWORD   fProt = kldrHlpPageProtToNative(enmProt);
-
-    if (!g_SystemInfo.dwPageSize)
-        GetSystemInfo(&g_SystemInfo);
-
-    *ppv = VirtualAlloc(fFixed ? *ppv : NULL, cb, MEM_COMMIT, fProt);
-    if (*ppv != NULL)
-        return 0;
-    rc = GetLastError();
-    kldrHlpAssert(0);
-    return rc;
-
-#else
-# error "port me"
-#endif
-}
-
-
-/**
- * Change the protection of one or more pages in an allocation.
- *
- * (This will of course only work correctly on memory allocated by kldrHlpPageAlloc().)
- *
- * @returns 0 on success, non-zero OS status code on failure.
- * @param   pv          First page. Page aligned.
- * @param   cb          Number of bytes. Page aligned.
- * @param   enmProt     The new protection. Copy-on-write is invalid.
- */
-int     kldrHlpPageProtect(void *pv, KSIZE cb, KPROT enmProt)
-{
-#ifdef __OS2__
-    APIRET      rc;
-    ULONG       fFlags = kldrHlpPageProtToNative(enmProt);;
-
-    /*
-     * The non-stub pages.
-     */
-    rc = DosSetMem(pv, cb, fFlags);
-    if (rc && fFlags != PAG_DECOMMIT)
-        rc = DosSetMem(pv, cb, fFlags | PAG_COMMIT);
-    if (rc)
-    {
-        /* Try page by page. */
-        while (cb > 0)
-        {
-            rc = DosSetMem(pv, 0x1000, fFlags);
-            if (rc && fFlags != PAG_DECOMMIT)
-                rc = DosSetMem(pv, 0x1000, fFlags | PAG_COMMIT);
-            if (rc)
-                return rc;
-            pv = (void *)((KUPTR)pv + 0x1000);
-            cb -= 0x1000;
-        }
-    }
-    kldrHlpAssert(!rc);
-    return rc;
-
-#elif defined(__WIN__)
-    DWORD fOldProt = 0;
-    DWORD fProt = kldrHlpPageProtToNative(enmProt);
-    int rc = 0;
-
-    if (!VirtualProtect(pv, cb, fProt, &fOldProt))
-    {
-        rc = GetLastError();
-        kldrHlpAssert(0);
-    }
-    return rc;
-#else
-# error "port me"
-#endif
-}
-
-
-/**
- * Free memory allocated by kldrHlpPageAlloc().
- *
- * @returns 0 on success, non-zero OS status code on failure.
- * @param   pv          The address returned by kldrHlpPageAlloc().
- * @param   cb          The byte count requested from kldrHlpPageAlloc().
- */
-int     kldrHlpPageFree(void *pv, KSIZE cb)
-{
-#ifdef __OS2__
-    APIRET rc;
-
-    /*
-     * Deal with any portion overlapping with the stub.
-     */
-    KUPTR offStub = (KUPTR)pv - (KUPTR)g_pvStub;
-    if (offStub < g_cbStub)
-    {
-        /* decommit the pages in the stub. */
-        KSIZE cbStub = K_MIN(g_cbStub - offStub, cb);
-        rc = DosSetMem(pv, cbStub, PAG_DECOMMIT);
-        if (rc)
-        {
-            /* Page by page, ignoring errors after the first success. */
-            while (cbStub > 0)
-            {
-                if (!DosSetMem(pv, 0x1000, PAG_DECOMMIT))
-                    rc = 0;
-                pv = (void *)((KUPTR)pv + 0x1000);
-                cbStub -= 0x1000;
-                cb -= 0x1000;
-            }
-            if (rc)
-            {
-                kldrHlpAssert(!rc);
-                return rc;
-            }
-        }
-        else
-        {
-            cb -= cbStub;
-            if (!cb)
-                return 0;
-            pv = (void *)((KUPTR)pv + cbStub);
-        }
-    }
-
-    /*
-     * Free the object.
-     */
-    rc = DosFreeMem(pv);
-    kldrHlpAssert(!rc);
-    return rc;
-
-#elif defined(__WIN__)
-    /*
-     * Free the object.
-     */
-    int rc = 0;
-    if (!VirtualFree(pv, 0 /*cb*/, MEM_RELEASE))
-    {
-        rc = GetLastError();
-        kldrHlpAssert(0);
-    }
-    return rc;
-
-#else
-# error "port me"
-#endif
-}
-
Index: trunk/kStuff/kLdr/kLdrHlpPath.c
===================================================================
--- trunk/kStuff/kLdr/kLdrHlpPath.c	(revision 3572)
+++ 	(revision )
@@ -1,136 +1,0 @@
-/* $Id$ */
-/** @file
- *
- * kLdr - The Dynamic Loader, Path Helper Functions.
- *
- * Copyright (c) 2006-2007 knut st. osmundsen <bird-kbuild-src@anduin.net>
- *
- *
- * This file is part of kLdr.
- *
- * kLdr is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * kLdr is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with kLdr; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-
-/*******************************************************************************
-*   Header Files                                                               *
-*******************************************************************************/
-#include <k/kLdr.h>
-#include "kLdrHlp.h"
-
-
-/**
- * Get the pointer to the filename part of the name.
- *
- * @returns Pointer to where the filename starts within the string pointed to by pszFilename.
- * @returns Pointer to the terminator char if no filename.
- * @param   pszFilename     The filename to parse.
- */
-char   *kldrHlpGetFilename(const char *pszFilename)
-{
-    const char *pszLast = NULL;
-    for (;;)
-    {
-        char ch = *pszFilename;
-#if defined(__OS2__) || defined(__WIN__)
-        if (ch == '/' || ch == '\\' || ch == ':')
-        {
-            while ((ch = *++pszFilename) == '/' || ch == '\\' || ch == ':')
-                /* nothing */;
-            pszLast = pszFilename;
-        }
-#else
-        if (ch == '/')
-        {
-            while ((ch = *++pszFilename) == '/')
-                /* betsuni */;
-            pszLast = pszFilename;
-        }
-#endif
-        if (!ch)
-            return (char *)(pszLast ? pszLast : pszFilename);
-        pszFilename++;
-    }
-}
-
-
-/**
- * Gets the filename suffix.
- *
- * @returns Pointer to where the suffix starts within the string pointed to by pszFilename.
- * @returns Pointer to the terminator char if no suffix.
- * @param   pszFilename     The filename to parse.
- */
-char   *kldrHlpGetSuff(const char *pszFilename)
-{
-    const char *pszDot = NULL;
-    pszFilename = kldrHlpGetFilename(pszFilename);
-    for (;;)
-    {
-        char ch = *pszFilename;
-        if (ch == '.')
-        {
-            while ((ch = *++pszFilename) == '.')
-                /* nothing */;
-            if (ch)
-                pszDot = pszFilename - 1;
-        }
-        if (!ch)
-            return (char *)(pszDot ? pszDot : pszFilename);
-        pszFilename++;
-    }
-}
-
-
-/**
- * Gets the filename extention.
- *
- * @returns Pointer to where the extension starts within the string pointed to by pszFilename.
- * @returns Pointer to the terminator char if no extension.
- * @param   pszFilename     The filename to parse.
- */
-char   *kldrHlpGetExt(const char *pszFilename)
-{
-    char *psz = kldrHlpGetSuff(pszFilename);
-    return *psz ? psz + 1 : psz;
-}
-
-
-/**
- * Checks if this is only a filename or if it contains any kind
- * of drive, directory, or server specs.
- *
- * @returns 1 if this is a filename only.
- * @returns 0 of it's isn't only a filename.
- * @param   pszFilename     The filename to parse.
- */
-int kldrHlpIsFilenameOnly(const char *pszFilename)
-{
-    for (;;)
-    {
-        const char ch = *pszFilename++;
-#if defined(__OS2__) || defined(__WIN__)
-        if (ch == '/' || ch == '\\' || ch == ':')
-#else
-        if (ch == '/')
-#endif
-            return 0;
-        if (!ch)
-            return 1;
-    }
-}
-
-
Index: trunk/kStuff/kLdr/kLdrHlpSem.c
===================================================================
--- trunk/kStuff/kLdr/kLdrHlpSem.c	(revision 3572)
+++ 	(revision )
@@ -1,155 +1,0 @@
-/* $Id$ */
-/** @file
- *
- * kLdr - The Dynamic Loader, Semaphore Helper Functions.
- *
- * Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net>
- *
- *
- * This file is part of kLdr.
- *
- * kLdr is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * kLdr is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with kLdr; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-
-/*******************************************************************************
-*   Header Files                                                               *
-*******************************************************************************/
-#ifdef __OS2__
-# define INCL_BASE
-# define INCL_ERRORS
-# include <os2.h>
-#elif defined(__WIN__)
-# include <Windows.h>
-#else
-# error "port me"
-#endif
-
-#include <k/kLdr.h>
-#include "kLdrHlp.h"
-
-
-/*******************************************************************************
-*   Global Variables                                                           *
-*******************************************************************************/
-#ifdef __OS2__
-/** The loader sempahore. */
-static HMTX             g_hmtx;
-
-#elif defined(__WIN__)
-/** The loader sempahore. */
-static CRITICAL_SECTION g_CritSect;
-#else
-# error "port me"
-#endif
-
-
-/**
- * Initializes the loader semaphore.
- *
- * @returns 0 on success, non-zero OS status code on failure.
- */
-int     kldrHlpSemInit(void)
-{
-#ifdef __OS2__
-    APIRET rc;
-    g_hmtx = NULLHANDLE;
-    rc = DosCreateMutexSem(NULL, &g_hmtx, 0, FALSE);
-    if (rc)
-        return rc;
-
-#elif defined(__WIN__)
-    InitializeCriticalSection(&g_CritSect);
-
-#else
-# error "port me"
-#endif
-    return 0;
-}
-
-
-/**
- * Terminates the loader semaphore.
- */
-void    kldrHlpSemTerm(void)
-{
-#ifdef __OS2__
-    HMTX hmtx = g_hmtx;
-    g_hmtx = NULLHANDLE;
-    DosCloseMutexSem(hmtx);
-
-#elif defined(__WIN__)
-    DeleteCriticalSection(&g_CritSect);
-
-#else
-# error "port me"
-#endif
-}
-
-
-/**
- * Requests the loader sempahore ownership.
- * This can be done recursivly.
- *
- * @returns 0 on success, non-zero OS status code on failure.
- */
-int     kldrHlpSemRequest(void)
-{
-#ifdef __OS2__
-    APIRET rc = DosRequestMutexSem(g_hmtx, 5000);
-    if (rc == ERROR_TIMEOUT || rc == ERROR_SEM_TIMEOUT || rc == ERROR_INTERRUPT)
-    {
-        unsigned i = 0;
-        do
-        {
-            /** @todo check for deadlocks etc. */
-            rc = DosRequestMutexSem(g_hmtx, 1000);
-        } while (   (   rc == ERROR_TIMEOUT
-                     || rc == ERROR_SEM_TIMEOUT
-                     || rc == ERROR_INTERRUPT)
-                 && i++ < 120);
-    }
-    return rc;
-
-#elif defined(__WIN__)
-    EnterCriticalSection(&g_CritSect);
-    return 0;
-
-#else
-# error "port me"
-#endif
-}
-
-
-/**
- * Releases the loader semaphore ownership.
- * The caller is responsible for making sure it's the semaphore owner!
- */
-void    kldrHlpSemRelease(void)
-{
-#ifdef __OS2__
-    APIRET rc = DosReleaseMutexSem(g_hmtx);
-    kldrHlpAssert(!rc); (void)rc;
-
-#elif defined(__WIN__)
-    LeaveCriticalSection(&g_CritSect);
-
-#else
-# error "port me"
-#endif
-
-}
-
Index: trunk/kStuff/kLdr/kLdrHlpStr.c
===================================================================
--- trunk/kStuff/kLdr/kLdrHlpStr.c	(revision 3572)
+++ 	(revision )
@@ -1,194 +1,0 @@
-/* $Id$ */
-/** @file
- *
- * kLdr - The Dynamic Loader, String Helper Functions.
- *
- * Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net>
- *
- *
- * This file is part of kLdr.
- *
- * kLdr is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * kLdr is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with kLdr; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-
-/*******************************************************************************
-*   Header Files                                                               *
-*******************************************************************************/
-#include <k/kLdr.h>
-#include "kLdrHlp.h"
-
-
-/**
- * Converts an signed integer to an ascii string.
- *
- * @returns psz.
- * @param   psz         Pointer to the output buffer.
- * @param   cch         The size of the output buffer.
- * @param   lVal        The value.
- * @param   iBase       The base to format it. (2,8,10 or 16)
- */
-char *kldrHlpInt2Ascii(char *psz, KSIZE cch, long lVal, unsigned iBase)
-{
-    static const char s_szDigits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
-    char *pszRet = psz;
-
-    if (cch >= (lVal < 0 ? 3U : 2U) && psz)
-    {
-        /* prefix */
-        if (lVal < 0)
-        {
-            *psz++ = '-';
-            cch--;
-            lVal = -lVal;
-        }
-
-        /* the digits */
-        do
-        {
-            *psz++ = s_szDigits[lVal % iBase];
-            cch--;
-            lVal /= iBase;
-        } while (lVal && cch > 1);
-
-        /* overflow indicator */
-        if (lVal)
-            psz[-1] = '+';
-    }
-    else if (!pszRet)
-        return pszRet;
-    else if (cch < 1 || !pszRet)
-        return pszRet;
-    else
-        *psz++ = '+';
-    *psz = '\0';
-
-    return pszRet;
-}
-
-
-KSIZE  kLdrHlpStrNLen(const char *psz, KSIZE cchMax)
-{
-    const char * const pszStart = psz;
-    while (*psz && cchMax--)
-        psz++;
-    return psz - pszStart;
-}
-
-
-int     kLdrHlpMemIComp(const void *pv1, const void *pv2, KSIZE cb)
-{
-    const KU8 *pb1 = (const KU8 *)pv1;
-    const KU8 *pb2 = (const KU8 *)pv2;
-    while (cb-- > 0)
-    {
-        if (*pb1 != *pb2)
-        {
-            const KU8 u1 = *pb1 >= 'a' && *pb1 <= 'z' ? *pb1 - 'a' : *pb1;
-            const KU8 u2 = *pb2 >= 'a' && *pb2 <= 'z' ? *pb2 - 'a' : *pb2;
-            if (u1 != u2)
-                return (int)*pb1 - (int)*pb2;
-        }
-        pb1++;
-        pb2++;
-    }
-    return 0;
-}
-
-
-int     kLdrHlpStrIComp(const char *pv1, const char *pv2)
-{
-    const KU8 *pb1 = (const KU8 *)pv1;
-    const KU8 *pb2 = (const KU8 *)pv2;
-    for (;;)
-    {
-        if (*pb1 != *pb2)
-        {
-            const KU8 u1 = *pb1 >= 'a' && *pb1 <= 'z' ? *pb1 - 'a' : *pb1;
-            const KU8 u2 = *pb2 >= 'a' && *pb2 <= 'z' ? *pb2 - 'a' : *pb2;
-            if (u1 != u2)
-                return (int)*pb1 - (int)*pb2;
-        }
-        if (!*pb1)
-            break;
-        pb1++;
-        pb2++;
-    }
-    return 0;
-}
-
-
-#ifdef kLdrHlpStrChr_needed
-char   *kLdrHlpStrChr(const char *psz, int ch)
-{
-    while (*psz)
-    {
-        if (*psz == ch)
-            return (char *)psz;
-        psz++;
-    }
-    return NULL;
-}
-#endif
-
-
-#ifdef kLdrHlpMemChr_needed
-void   *kLdrHlpMemChr(const void *pv, int ch, KSIZE cb)
-{
-    const KU8 *pb = (const KU8 *)pv;
-    const KU8  b = (KU8)ch;
-    while (cb-- > 0)
-    {
-        if (*pb == b)
-            return (void *)pb;
-        pb++;
-    }
-    return NULL;
-}
-#endif
-
-
-#ifdef kLdrHlpMemMove_needed
-void   *kLdrHlpMemMove(void *pv1, const void *pv2, KSIZE cb)
-{
-    KU8            *pbDst = (KU8 *)pv1;
-    const KU8      *pbSrc = (const KU8 *)pv2;
-    while (cb-- > 0)
-    {
-        const KU8 b = *pbSrc++;
-        *pbDst++ = b;
-    }
-    return pv1;
-}
-#endif
-
-
-#ifdef kLdrHlpStrNComp_needed
-int     kLdrHlpStrNComp(const char *psz1, const char *psz2, KSIZE cch)
-{
-    while (cch-- > 0)
-    {
-        if (*psz1 != *psz2)
-            return (int)*psz1 - (int)*psz2;
-        if (!*psz1)
-            break;
-        psz1++;
-        psz2++;
-    }
-    return 0;
-}
-#endif
-
Index: trunk/kStuff/kLdr/kLdrInternal.h
===================================================================
--- trunk/kStuff/kLdr/kLdrInternal.h	(revision 3572)
+++ trunk/kStuff/kLdr/kLdrInternal.h	(revision 3573)
@@ -26,6 +26,8 @@
 
 
-#ifndef __kLdrInternal_h__
-#define __kLdrInternal_h__
+#ifndef ___kLdrInternal_h___
+#define ___kLdrInternal_h___
+
+#include <k/kHlp.h>
 
 #ifdef __cplusplus
@@ -442,4 +444,5 @@
 /** @} */
 
+
 /** @} */
 #ifdef __cplusplus
Index: trunk/kStuff/kLdr/kLdrMisc.c
===================================================================
--- trunk/kStuff/kLdr/kLdrMisc.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdrMisc.c	(revision 3573)
@@ -30,5 +30,4 @@
 *******************************************************************************/
 #include <k/kLdr.h>
-#include "kLdrHlp.h"
 #include "kLdrInternal.h"
 
Index: trunk/kStuff/kLdr/kLdrMod.c
===================================================================
--- trunk/kStuff/kLdr/kLdrMod.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdrMod.c	(revision 3573)
@@ -30,5 +30,4 @@
 *******************************************************************************/
 #include <k/kLdr.h>
-#include "kLdrHlp.h"
 #include "kLdrInternal.h"
 #include <k/kLdrFmts/mz.h>
@@ -53,5 +52,5 @@
  */
 #ifdef KLDRMOD_STRICT
-# define KLDRMOD_ASSERT(expr)  kldrHlpAssert(expr)
+# define KLDRMOD_ASSERT(expr)  kHlpAssert(expr)
 #else
 # define KLDRMOD_ASSERT(expr)  do {} while (0)
@@ -268,5 +267,5 @@
         *puValue = 0;
     if (pfKind)
-        KLDRHLP_VALIDATE_FLAGS(*pfKind, KLDRSYMKIND_REQ_SEGMENTED);
+        K_VALIDATE_FLAGS(*pfKind, KLDRSYMKIND_REQ_SEGMENTED);
     return pMod->pOps->pfnQuerySymbol(pMod, pvBits, BaseAddress, iSymbol, pchSymbol, cchSymbol, pszVersion,
                                       pfnGetForwarder, pvUser, puValue, pfKind);
@@ -292,5 +291,5 @@
 {
     KLDRMOD_VALIDATE(pMod);
-    KLDRHLP_VALIDATE_FLAGS(fFlags, KLDRMOD_ENUM_SYMS_FLAGS_ALL);
+    K_VALIDATE_FLAGS(fFlags, KLDRMOD_ENUM_SYMS_FLAGS_ALL);
     return pMod->pOps->pfnEnumSymbols(pMod, pvBits, BaseAddress, fFlags, pfnCallback, pvUser);
 }
@@ -653,5 +652,5 @@
 {
     KLDRMOD_VALIDATE(pMod);
-    KLDRHLP_VALIDATE_FLAGS(fAttachingOrDetaching, 1);
+    K_VALIDATE_FLAGS(fAttachingOrDetaching, 1);
     return pMod->pOps->pfnCallThread(pMod, uHandle, fAttachingOrDetaching);
 }
Index: trunk/kStuff/kLdr/kLdrModLX.c
===================================================================
--- trunk/kStuff/kLdr/kLdrModLX.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdrModLX.c	(revision 3573)
@@ -30,5 +30,4 @@
 *******************************************************************************/
 #include <k/kLdr.h>
-#include "kLdrHlp.h"
 #include "kLdrInternal.h"
 #include <k/kLdrFmts/lx.h>
@@ -46,5 +45,5 @@
  */
 #ifdef KLDRMODLX_STRICT
-# define KLDRMODLX_ASSERT(expr)  kldrHlpAssert(expr)
+# define KLDRMODLX_ASSERT(expr)  kHlpAssert(expr)
 #else
 # define KLDRMODLX_ASSERT(expr)  do {} while (0)
@@ -162,5 +161,5 @@
         return 0;
     }
-    kldrHlpFree(pModLX);
+    kHlpFree(pModLX);
     return rc;
 }
@@ -267,10 +266,10 @@
      * Calc the instance size, allocate and initialize it.
      */
-    cchFilename = kLdrHlpStrLen(kLdrRdrName(pRdr));
+    cchFilename = kHlpStrLen(kLdrRdrName(pRdr));
     cb = K_ALIGN_Z(sizeof(KLDRMODLX), 8)
        + K_ALIGN_Z(K_OFFSETOF(KLDRMOD, aSegments[Hdr.e32_objcnt + 1]), 8)
        + K_ALIGN_Z(cchFilename + 1, 8)
        + Hdr.e32_ldrsize + 2; /* +2 for two extra zeros. */
-    pModLX = (PKLDRMODLX)kldrHlpAlloc(cb);
+    pModLX = (PKLDRMODLX)kHlpAlloc(cb);
     if (!pModLX)
         return KLDR_ERR_NO_MEMORY;
@@ -285,5 +284,5 @@
     pMod->cchFilename = cchFilename;
     pMod->pszFilename = (char *)K_ALIGN_P(&pMod->aSegments[pMod->cSegments], 8);
-    kLdrHlpMemCopy((char *)pMod->pszFilename, kLdrRdrName(pRdr), cchFilename + 1);
+    kHlpMemCopy((char *)pMod->pszFilename, kLdrRdrName(pRdr), cchFilename + 1);
     pMod->pszName = NULL; /* finalized further down */
     pMod->cchName = 0;
@@ -387,5 +386,5 @@
         return KLDR_ERR_LX_NO_SONAME;
     pMod->cchName = *(const KU8 *)pMod->pszName++;
-    if (pMod->cchName != kLdrHlpStrLen(pMod->pszName))
+    if (pMod->cchName != kHlpStrLen(pMod->pszName))
         return KLDR_ERR_LX_BAD_SONAME;
 
@@ -533,15 +532,15 @@
     if (pModLX->pbNonResNameTab)
     {
-        kldrHlpFree(pModLX->pbNonResNameTab);
+        kHlpFree(pModLX->pbNonResNameTab);
         pModLX->pbNonResNameTab = NULL;
     }
     if (pModLX->pbFixupSection)
     {
-        kldrHlpFree(pModLX->pbFixupSection);
+        kHlpFree(pModLX->pbFixupSection);
         pModLX->pbFixupSection = NULL;
     }
     pMod->u32Magic = 0;
     pMod->pOps = NULL;
-    kldrHlpFree(pModLX);
+    kHlpFree(pModLX);
     return rc;
 }
@@ -789,5 +788,5 @@
 
         if (    cbName == cbSymbol8Bit
-            &&  !kLdrHlpMemComp(pbNameTable + 1, pchSymbol, cbName))
+            &&  !kHlpMemComp(pbNameTable + 1, pchSymbol, cbName))
             return pbNameTable;
 
@@ -937,5 +936,5 @@
     void *pv;
 
-    pv = kldrHlpAlloc(pModLX->Hdr.e32_fixupsize);
+    pv = kHlpAlloc(pModLX->Hdr.e32_fixupsize);
     if (!pv)
         return KLDR_ERR_NO_MEMORY;
@@ -962,5 +961,5 @@
     }
     else
-        kldrHlpFree(pv);
+        kHlpFree(pv);
     return rc;
 }
@@ -1208,5 +1207,5 @@
     if (*pb < cchName)
     {
-        kLdrHlpMemCopy(pszName, pb + 1, *pb);
+        kHlpMemCopy(pszName, pb + 1, *pb);
         pszName[*pb] = '\0';
         rc = 0;
@@ -1214,5 +1213,5 @@
     else
     {
-        kLdrHlpMemCopy(pszName, pb + 1, cchName);
+        kHlpMemCopy(pszName, pb + 1, cchName);
         if (cchName)
             pszName[cchName - 1] = '\0';
@@ -1345,5 +1344,5 @@
             return KLDR_ERR_ADDRESS_OVERFLOW;
     }
-    rc = kldrHlpPageAlloc(&pvBase, pModLX->cbMapped, KPROT_EXECUTE_READWRITE, fFixed);
+    rc = kHlpPageAlloc(&pvBase, pModLX->cbMapped, KPROT_EXECUTE_READWRITE, fFixed);
     if (rc)
         return rc;
@@ -1366,5 +1365,5 @@
     }
     else
-        kldrHlpPageFree(pvBase, pModLX->cbMapped);
+        kHlpPageFree(pvBase, pModLX->cbMapped);
     return rc;
 }
@@ -1413,5 +1412,5 @@
                         rc = kLdrRdrRead(pRdr, pbPage, pMap->o32_pagesize,
                                          pModLX->Hdr.e32_datapage + (pMap->o32_pagedataoffset << pModLX->Hdr.e32_pageshift));
-                        kLdrHlpMemSet(pbPage + pMap->o32_pagesize, 0, OBJPAGELEN - pMap->o32_pagesize);
+                        kHlpMemSet(pbPage + pMap->o32_pagesize, 0, OBJPAGELEN - pMap->o32_pagesize);
                     }
                     else
@@ -1424,5 +1423,5 @@
                     if (!pbTmpPage)
                     {
-                        pbTmpPage = kldrHlpAlloc(OBJPAGELEN + 256);
+                        pbTmpPage = kHlpAlloc(OBJPAGELEN + 256);
                         if (!pbTmpPage)
                             break;
@@ -1440,5 +1439,5 @@
                     if (rc)
                         break;
-                    kLdrHlpMemSet(pbTmpPage + pMap->o32_pagesize, 0, 4);
+                    kHlpMemSet(pbTmpPage + pMap->o32_pagesize, 0, 4);
 
                     /* unpack it into the image page. */
@@ -1451,5 +1450,5 @@
                 case INVALID: /* we're probably not dealing correctly with INVALID pages... */
                 case ZEROED:
-                    kLdrHlpMemSet(pbPage, 0, OBJPAGELEN);
+                    kHlpMemSet(pbPage, 0, OBJPAGELEN);
                     break;
 
@@ -1468,9 +1467,9 @@
          */
         if (iPage < cPages)
-            kLdrHlpMemSet(pbPage, 0, (cPages - iPage) * OBJPAGELEN);
+            kHlpMemSet(pbPage, 0, (cPages - iPage) * OBJPAGELEN);
     }
 
     if (pbTmpPage)
-        kldrHlpFree(pbTmpPage);
+        kHlpFree(pbTmpPage);
     return rc;
 }
@@ -1513,5 +1512,5 @@
                 return KLDR_ERR_LX_BAD_ITERDATA;
 
-            kLdrHlpMemSet(pbDst, pIter->LX_Iterdata, pIter->LX_nIter);
+            kHlpMemSet(pbDst, pIter->LX_Iterdata, pIter->LX_nIter);
             pbDst += pIter->LX_nIter;
             pIter++;
@@ -1533,5 +1532,5 @@
 
             for (i = pIter->LX_nIter; i > 0; i--, pbDst += pIter->LX_nBytes)
-                kLdrHlpMemCopy(pbDst, &pIter->LX_Iterdata, pIter->LX_nBytes);
+                kHlpMemCopy(pbDst, &pIter->LX_Iterdata, pIter->LX_nBytes);
             pIter   = (struct LX_Iter *)((char*)pIter + 4 + pIter->LX_nBytes);
         }
@@ -1542,5 +1541,5 @@
      */
     if (cbDst > 0)
-        kLdrHlpMemSet(pbDst, 0, cbDst);
+        kHlpMemSet(pbDst, 0, cbDst);
 
     return 0;
@@ -1599,5 +1598,5 @@
                     if (cbSrc < 0)
                         return KLDR_ERR_LX_BAD_ITERDATA2;
-                    kLdrHlpMemCopy(pbDst, ++pbSrc, cb);
+                    kHlpMemCopy(pbDst, ++pbSrc, cb);
                     pbDst += cb;
                     pbSrc += cb;
@@ -1616,5 +1615,5 @@
                     if (cbSrc < 0)
                         return KLDR_ERR_LX_BAD_ITERDATA2;
-                    kLdrHlpMemSet(pbDst, pbSrc[2], cb);
+                    kHlpMemSet(pbDst, pbSrc[2], cb);
                     pbDst += cb;
                     pbSrc += 3;
@@ -1652,5 +1651,5 @@
                     if (cbDst < 0)
                         return KLDR_ERR_LX_BAD_ITERDATA2;
-                    kLdrHlpMemCopy(pbDst, pbSrc, cb1);
+                    kHlpMemCopy(pbDst, pbSrc, cb1);
                     pbDst += cb1;
                     pbSrc += cb1;
@@ -1661,5 +1660,5 @@
                     if (cbDst < 0)
                         return KLDR_ERR_LX_BAD_ITERDATA2;
-                    kLdrHlpMemMove(pbDst, pbDst - off, cb2);
+                    kHlpMemMove(pbDst, pbDst - off, cb2);
                     pbDst += cb2;
                 }
@@ -1733,5 +1732,5 @@
                     if (cbDst < 0)
                         return KLDR_ERR_LX_BAD_ITERDATA2;
-                    kLdrHlpMemCopy(pbDst, pbSrc, cb1);
+                    kHlpMemCopy(pbDst, pbSrc, cb1);
                     pbDst += cb1;
                     pbSrc += cb1;
@@ -1757,5 +1756,5 @@
      */
     if (cbDst > 0)
-        kLdrHlpMemSet(pbDst, 0, cbDst);
+        kHlpMemSet(pbDst, 0, cbDst);
 
     return 0;
@@ -1867,5 +1866,5 @@
         pv = (KU8 *)pvBits + pMod->aSegments[i].RVA;
 
-        rc = kldrHlpPageProtect(pv, pMod->aSegments[i].cbMapped, enmProt);
+        rc = kHlpPageProtect(pv, pMod->aSegments[i].cbMapped, enmProt);
         if (rc)
             break;
@@ -1894,5 +1893,5 @@
      * Free the mapping and update the segments.
      */
-    rc = kldrHlpPageFree((void *)pModLX->pvMapping, pModLX->cbMapped);
+    rc = kHlpPageFree((void *)pModLX->pvMapping, pModLX->cbMapped);
     KLDRMODLX_ASSERT(!rc);
     pModLX->pvMapping = NULL;
Index: trunk/kStuff/kLdr/kLdrModMachO.c
===================================================================
--- trunk/kStuff/kLdr/kLdrModMachO.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdrModMachO.c	(revision 3573)
@@ -30,5 +30,4 @@
 *******************************************************************************/
 #include <k/kLdr.h>
-#include "kLdrHlp.h"
 #include "kLdrInternal.h"
 #include <k/kLdrFmts/mach-o.h>
@@ -46,5 +45,5 @@
  */
 #ifdef KLDRMODMACHO_STRICT
-# define KLDRMODMACHO_ASSERT(expr)  kldrHlpAssert(expr)
+# define KLDRMODMACHO_ASSERT(expr)  kHlpAssert(expr)
 #else
 # define KLDRMODMACHO_ASSERT(expr)  do {} while (0)
@@ -215,6 +214,6 @@
     if (pModMachO)
     {
-        kldrHlpFree(pModMachO->pbLoadCommands);
-        kldrHlpFree(pModMachO);
+        kHlpFree(pModMachO->pbLoadCommands);
+        kHlpFree(pModMachO);
     }
     return rc;
@@ -279,5 +278,5 @@
      * Read and pre-parse the load commands to figure out how many segments we'll be needing.
      */
-    pbLoadCommands = kldrHlpAlloc(s.Hdr32.sizeofcmds);
+    pbLoadCommands = kHlpAlloc(s.Hdr32.sizeofcmds);
     if (!pbLoadCommands)
         return KLDR_ERR_NO_MEMORY;
@@ -290,5 +289,5 @@
     if (rc)
     {
-        kldrHlpFree(pbLoadCommands);
+        kHlpFree(pbLoadCommands);
         return rc;
     }
@@ -298,5 +297,5 @@
      * Calc the instance size, allocate and initialize it.
      */
-    cchFilename = kLdrHlpStrLen(kLdrRdrName(pRdr));
+    cchFilename = kHlpStrLen(kLdrRdrName(pRdr));
     cb = K_ALIGN_Z(  K_OFFSETOF(KLDRMODMACHO, aSegments[cSegments])
                       + sizeof(KLDRMODMACHOSECT) * cSections, 16)
@@ -304,5 +303,5 @@
        + cchFilename + 1
        + cbStringPool;
-    pModMachO = (PKLDRMODMACHO)kldrHlpAlloc(cb);
+    pModMachO = (PKLDRMODMACHO)kHlpAlloc(cb);
     if (!pModMachO)
         return KLDR_ERR_NO_MEMORY;
@@ -319,6 +318,6 @@
     pMod->cchFilename = cchFilename;
     pMod->pszFilename = (char *)&pMod->aSegments[pMod->cSegments];
-    kLdrHlpMemCopy((char *)pMod->pszFilename, kLdrRdrName(pRdr), cchFilename + 1);
-    pMod->pszName = kldrHlpGetFilename(pMod->pszFilename);
+    kHlpMemCopy((char *)pMod->pszFilename, kLdrRdrName(pRdr), cchFilename + 1);
+    pMod->pszName = kHlpGetFilename(pMod->pszFilename);
     pMod->cchName = cchFilename - (pMod->pszName - pMod->pszFilename);
     switch (s.Hdr32.cputype)
@@ -619,5 +618,5 @@
                             /* a new segment? */
                             if (    !cSegments
-                                ||  kLdrHlpStrNComp(pSect->segname, (pSect - 1)->segname, sizeof(pSect->segname)))
+                                ||  kHlpStrNComp(pSect->segname, (pSect - 1)->segname, sizeof(pSect->segname)))
                             {
 #if 0 /** @todo This  doesn't work because of BSS. */
@@ -626,5 +625,5 @@
                                 while ((KUPTR)pCur >= (KUPTR)pFirstSect)
                                 {
-                                    if (!kLdrHlpStrNComp(pCur->segname, pSect->segname, sizeof(pSect->segname)))
+                                    if (!kHlpStrNComp(pCur->segname, pSect->segname, sizeof(pSect->segname)))
                                         return KLDR_ERR_MACHO_BAD_SECTION_ORDER;
                                     pCur--;
@@ -634,5 +633,5 @@
                                 /* ok. count it and the string. */
                                 cSegments++;
-                                cbStringPool += kLdrHlpStrNLen(&pSect->segname[0], sizeof(pSect->segname)) + 1;
+                                cbStringPool += kHlpStrNLen(&pSect->segname[0], sizeof(pSect->segname)) + 1;
                             }
                             break;
@@ -858,5 +857,5 @@
 
                             if (    fFirstSegment
-                                ||  kLdrHlpStrNComp(pSect->segname, (pSect - 1)->segname, sizeof(pSect->segname)))
+                                ||  kHlpStrNComp(pSect->segname, (pSect - 1)->segname, sizeof(pSect->segname)))
                             {
                                 /* close the previous segment */
@@ -867,6 +866,6 @@
                                 pSeg->pvUser = NULL;
                                 pSeg->pchName = pbStringPool;
-                                pSeg->cchName = (KU32)kLdrHlpStrNLen(&pSect->segname[0], sizeof(pSect->sectname));
-                                kLdrHlpMemCopy(pbStringPool, &pSect->segname[0], pSeg->cchName);
+                                pSeg->cchName = (KU32)kHlpStrNLen(&pSect->segname[0], sizeof(pSect->sectname));
+                                kHlpMemCopy(pbStringPool, &pSect->segname[0], pSeg->cchName);
                                 pbStringPool += pSeg->cchName;
                                 *pbStringPool++ = '\0';
@@ -1002,5 +1001,5 @@
         while (j-- > 0)
         {
-            kldrHlpFree(pModMachO->aSegments[i].paSections[j].paFixups);
+            kHlpFree(pModMachO->aSegments[i].paSections[j].paFixups);
             pModMachO->aSegments[i].paSections[j].paFixups = NULL;
         }
@@ -1014,11 +1013,11 @@
     pMod->u32Magic = 0;
     pMod->pOps = NULL;
-    kldrHlpFree(pModMachO->pbLoadCommands);
+    kHlpFree(pModMachO->pbLoadCommands);
     pModMachO->pbLoadCommands = NULL;
-    kldrHlpFree(pModMachO->pchStrings);
+    kHlpFree(pModMachO->pchStrings);
     pModMachO->pchStrings = NULL;
-    kldrHlpFree(pModMachO->pvaSymbols);
+    kHlpFree(pModMachO->pvaSymbols);
     pModMachO->pvaSymbols = NULL;
-    kldrHlpFree(pModMachO);
+    kHlpFree(pModMachO);
     return rc;
 }
@@ -1152,5 +1151,5 @@
             if (psz[cchSymbol])
                 continue;
-            if (kLdrHlpMemComp(psz, pchSymbol, cchSymbol))
+            if (kHlpMemComp(psz, pchSymbol, cchSymbol))
                 continue;
 
@@ -1325,5 +1324,5 @@
             return KLDR_ERR_MACHO_BAD_SYMBOL;
         psz = &pchStrings[paSyms[iSym].n_un.n_strx];
-        cch = kLdrHlpStrLen(psz);
+        cch = kHlpStrLen(psz);
         if (!cch)
             psz = NULL;
@@ -1757,5 +1756,5 @@
                     return KLDR_ERR_MACHO_BAD_SYMBOL;
                 pszSymbol = &pModMachO->pchStrings[paSyms[iSym].n_un.n_strx];
-                cchSymbol = kLdrHlpStrLen(pszSymbol);
+                cchSymbol = kHlpStrLen(pszSymbol);
                 rc = pfnGetImport(pModMachO->pMod, NIL_KLDRMOD_IMPORT, iSym, pszSymbol, cchSymbol, NULL,
                                   &Value, &fKind, pvUser);
@@ -1808,5 +1807,5 @@
                     return KLDR_ERR_MACHO_BAD_SYMBOL;
                 pszSymbol = &pModMachO->pchStrings[paSyms[iSym].n_un.n_strx];
-                cchSymbol = kLdrHlpStrLen(pszSymbol);
+                cchSymbol = kHlpStrLen(pszSymbol);
                 rc = pfnGetImport(pModMachO->pMod, NIL_KLDRMOD_IMPORT, iSym, pszSymbol, cchSymbol, NULL,
                                   &Value, &fKind, pvUser);
@@ -2142,11 +2141,11 @@
             return KLDR_ERR_SIZE_OVERFLOW;
         rc = KLDR_ERR_NO_MEMORY;
-        pvSyms = kldrHlpAlloc(cbSyms);
+        pvSyms = kHlpAlloc(cbSyms);
         if (pvSyms)
         {
             if (pModMachO->cchStrings)
-                pvStrings = kldrHlpAlloc(pModMachO->cchStrings);
+                pvStrings = kHlpAlloc(pModMachO->cchStrings);
             else
-                pvStrings = kldrHlpAllocZ(4);
+                pvStrings = kHlpAllocZ(4);
             if (pvStrings)
             {
@@ -2188,7 +2187,7 @@
                     return 0;
                 }
-                kldrHlpFree(pvStrings);
+                kHlpFree(pvStrings);
             }
-            kldrHlpFree(pvSyms);
+            kHlpFree(pvSyms);
         }
     }
@@ -2220,5 +2219,5 @@
     if (cbFixups / sizeof(*paFixups) != cFixups)
         return KLDR_ERR_SIZE_OVERFLOW;
-    paFixups = (macho_relocation_info_t *)kldrHlpAlloc(cbFixups);
+    paFixups = (macho_relocation_info_t *)kHlpAlloc(cbFixups);
     if (!paFixups)
         return KLDR_ERR_NO_MEMORY;
@@ -2244,5 +2243,5 @@
     }
     else
-        kldrHlpFree(paFixups);
+        kHlpFree(paFixups);
     return rc;
 }
@@ -2306,5 +2305,5 @@
      * Zero the entire buffer first to simplify things.
      */
-    kLdrHlpMemSet(pvBits, 0, (KSIZE)pModMachO->cbImage);
+    kHlpMemSet(pvBits, 0, (KSIZE)pModMachO->cbImage);
 
     /*
Index: trunk/kStuff/kLdr/kLdrModNative.c
===================================================================
--- trunk/kStuff/kLdr/kLdrModNative.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdrModNative.c	(revision 3573)
@@ -30,5 +30,4 @@
 *******************************************************************************/
 #include <k/kLdr.h>
-#include "kLdrHlp.h"
 #include "kLdrInternal.h"
 #ifdef __OS2__
@@ -81,5 +80,5 @@
  */
 #ifdef KLDRMODNATIVE_STRICT
-# define KLDRMODNATIVE_ASSERT(expr)  kldrHlpAssert(expr)
+# define KLDRMODNATIVE_ASSERT(expr)  kHlpAssert(expr)
 #else
 # define KLDRMODNATIVE_ASSERT(expr)  do {} while (0)
@@ -300,9 +299,9 @@
      * Calc the instance size, allocate and initialize it.
      */
-    cchFilename = kLdrHlpStrLen(szFilename);
+    cchFilename = kHlpStrLen(szFilename);
     cb = K_ALIGN_Z(sizeof(KLDRMODNATIVE), 16)
        + K_OFFSETOF(KLDRMOD, aSegments[cSegments])
        + cchFilename + 1;
-    pModNative = (PKLDRMODNATIVE)kldrHlpAlloc(cb);
+    pModNative = (PKLDRMODNATIVE)kHlpAlloc(cb);
     if (!pModNative)
         return KLDR_ERR_NO_MEMORY;
@@ -316,6 +315,6 @@
     pMod->cchFilename = cchFilename;
     pMod->pszFilename = (char *)&pMod->aSegments[pMod->cSegments];
-    kLdrHlpMemCopy((char *)pMod->pszFilename, szFilename, cchFilename + 1);
-    pMod->pszName = kldrHlpGetFilename(pMod->pszFilename); /** @todo get soname */
+    kHlpMemCopy((char *)pMod->pszFilename, szFilename, cchFilename + 1);
+    pMod->pszName = kHlpGetFilename(pMod->pszFilename); /** @todo get soname */
     pMod->cchName = cchFilename - (pMod->pszName - pMod->pszFilename);
 #if defined(__i386__) || defined(__X86__) || defined(_M_IX86)
@@ -492,5 +491,5 @@
             case IMAGE_SCN_ALIGN_4096BYTES:     pMod->aSegments[i + 1].Alignment = 4096; break;
             case IMAGE_SCN_ALIGN_8192BYTES:     pMod->aSegments[i + 1].Alignment = 8192; break;
-            default: kldrHlpAssert(0);          pMod->aSegments[i + 1].Alignment = 0; break;
+            default: kHlpAssert(0);          pMod->aSegments[i + 1].Alignment = 0; break;
         }
     }
@@ -535,5 +534,5 @@
     pMod->u32Magic = 0;
     pMod->pOps = NULL;
-    kldrHlpFree(pModNative);
+    kHlpFree(pModNative);
     return rc;
 }
@@ -561,6 +560,6 @@
     if (pszSymbol && pszSymbol[cchSymbol])
     {
-        char *pszCopy = kLdrHlpAllocA(cchSymbol + 1);
-        kLdrHlpMemCopy(pszCopy, pchSymbol, cchSymbol);
+        char *pszCopy = kHlpAllocA(cchSymbol + 1);
+        kHlpMemCopy(pszCopy, pchSymbol, cchSymbol);
         pszCopy[cchSymbol] = '\0';
         pszSymbol = pszCopy;
@@ -756,13 +755,13 @@
                                       const IMAGE_IMPORT_DESCRIPTOR *);
     pszImportName = KLDRMODNATIVE_RVA2TYPE(pModNative->hmod, pImpDesc->Name, const char *);
-    cchImportName = kLdrHlpStrLen(pszImportName);
+    cchImportName = kHlpStrLen(pszImportName);
     if (cchImportName < cchName)
     {
-        kLdrHlpMemCopy(pszName, pszImportName, cchImportName + 1);
+        kHlpMemCopy(pszName, pszImportName, cchImportName + 1);
         rc = 0;
     }
     else
     {
-        kLdrHlpMemCopy(pszName, pszImportName, cchName);
+        kHlpMemCopy(pszName, pszImportName, cchName);
         if (cchName)
             pszName[cchName - 1] = '\0';
Index: trunk/kStuff/kLdr/kLdrModPE.c
===================================================================
--- trunk/kStuff/kLdr/kLdrModPE.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdrModPE.c	(revision 3573)
@@ -30,5 +30,4 @@
 *******************************************************************************/
 #include <k/kLdr.h>
-#include "kLdrHlp.h"
 #include "kLdrInternal.h"
 #include <k/kLdrFmts/pe.h>
@@ -46,5 +45,5 @@
  */
 #ifdef KLDRMODPE_STRICT
-# define KLDRMODPE_ASSERT(expr)  kldrHlpAssert(expr)
+# define KLDRMODPE_ASSERT(expr)  kHlpAssert(expr)
 #else
 # define KLDRMODPE_ASSERT(expr)  do {} while (0)
@@ -151,5 +150,5 @@
         return 0;
     }
-    kldrHlpFree(pModPE);
+    kHlpFree(pModPE);
     return rc;
 }
@@ -200,9 +199,9 @@
      * Calc the instance size, allocate and initialize it.
      */
-    cchFilename = kLdrHlpStrLen(kLdrRdrName(pRdr));
+    cchFilename = kHlpStrLen(kLdrRdrName(pRdr));
     cb = K_ALIGN_Z(K_OFFSETOF(KLDRMODPE, aShdrs[s.FileHdr.NumberOfSections]), 16)
        + K_OFFSETOF(KLDRMOD, aSegments[s.FileHdr.NumberOfSections + 1])
        + cchFilename + 1;
-    pModPE = (PKLDRMODPE)kldrHlpAlloc(cb);
+    pModPE = (PKLDRMODPE)kHlpAlloc(cb);
     if (!pModPE)
         return KLDR_ERR_NO_MEMORY;
@@ -217,6 +216,6 @@
     pMod->cchFilename = cchFilename;
     pMod->pszFilename = (char *)&pMod->aSegments[pMod->cSegments];
-    kLdrHlpMemCopy((char *)pMod->pszFilename, kLdrRdrName(pRdr), cchFilename + 1);
-    pMod->pszName = kldrHlpGetFilename(pMod->pszFilename);
+    kHlpMemCopy((char *)pMod->pszFilename, kLdrRdrName(pRdr), cchFilename + 1);
+    pMod->pszName = kHlpGetFilename(pMod->pszFilename);
     pMod->cchName = cchFilename - (pMod->pszName - pMod->pszFilename);
     switch (s.FileHdr.Machine)
@@ -234,5 +233,5 @@
             break;
         default:
-            kldrHlpAssert(0);
+            kHlpAssert(0);
             break;
     }
@@ -410,5 +409,5 @@
             case IMAGE_SCN_ALIGN_4096BYTES:     pMod->aSegments[i + 1].Alignment = 4096; break;
             case IMAGE_SCN_ALIGN_8192BYTES:     pMod->aSegments[i + 1].Alignment = 8192; break;
-            default: kldrHlpAssert(0);          pMod->aSegments[i + 1].Alignment = 0; break;
+            default: kHlpAssert(0);          pMod->aSegments[i + 1].Alignment = 0; break;
         }
     }
@@ -536,5 +535,5 @@
     pMod->u32Magic = 0;
     pMod->pOps = NULL;
-    kldrHlpFree(pModPE);
+    kHlpFree(pModPE);
     return rc;
 }
@@ -751,6 +750,6 @@
                 {
                     pszName = KLDRMODPE_RVA2TYPE(pvBits, paRVANames[i], const char *);
-                    KLDRMODPE_ASSERT(kLdrHlpStrNComp(pszName, pchSymbol, cchSymbol) || pszName[cchSymbol]);
-                    KLDRMODPE_ASSERT(i == 0 || kLdrHlpStrComp(pszName, KLDRMODPE_RVA2TYPE(pvBits, paRVANames[i - 1], const char *)));
+                    KLDRMODPE_ASSERT(kHlpStrNComp(pszName, pchSymbol, cchSymbol) || pszName[cchSymbol]);
+                    KLDRMODPE_ASSERT(i == 0 || kHlpStrComp(pszName, KLDRMODPE_RVA2TYPE(pvBits, paRVANames[i - 1], const char *)));
                 }
 #endif
@@ -760,5 +759,5 @@
             i = (iEnd - iStart) / 2 + iStart;
             pszName = KLDRMODPE_RVA2TYPE(pvBits, paRVANames[i - 1], const char *);
-            diff = kLdrHlpStrNComp(pszName, pchSymbol, cchSymbol);
+            diff = kHlpStrNComp(pszName, pchSymbol, cchSymbol);
             if (!diff)
                 diff = pszName[cchSymbol] - 0;
@@ -903,5 +902,5 @@
     {
         const char *pszName = KLDRMODPE_RVA2TYPE(pvBits, paImpDir[iImpModule].Name, const char *);
-        KSIZE       cchName = kLdrHlpStrLen(pszName);
+        KSIZE       cchName = kHlpStrLen(pszName);
         if (    (   cchName == cchImpModule
                  || (   cchName > cchImpModule
@@ -911,5 +910,5 @@
                      && (pszName[cchImpModule + 3] == 'l' || pszName[cchImpModule + 3] == 'L'))
                 )
-            &&  kLdrHlpMemIComp(pszName, pszForwarder, cchImpModule)
+            &&  kHlpMemIComp(pszName, pszForwarder, cchImpModule)
            )
         {
@@ -918,5 +917,5 @@
              */
             rc = pfnGetForwarder(pModPE->pMod, iImpModule, iSymbol, pszSymbol,
-                                 pszSymbol ? kLdrHlpStrLen(pszSymbol) : 0, NULL, puValue, pfKind, pvUser);
+                                 pszSymbol ? kHlpStrLen(pszSymbol) : 0, NULL, puValue, pfKind, pvUser);
             if (!rc && pfKind)
                 *pfKind |= KLDRSYMKIND_FORWARDER;
@@ -989,5 +988,5 @@
             fFoundName = 1;
             pszName = KLDRMODPE_RVA2TYPE(pvBits, paRVANames[iName], const char *);
-            rc = pfnCallback(pMod, iFunction + pExpDir->Base, pszName, kLdrHlpStrLen(pszName), NULL,
+            rc = pfnCallback(pMod, iFunction + pExpDir->Base, pszName, kHlpStrLen(pszName), NULL,
                              uValue, fKind, pvUser);
             if (rc)
@@ -1040,13 +1039,13 @@
                                   const IMAGE_IMPORT_DESCRIPTOR *);
     pszImportName = KLDRMODPE_RVA2TYPE(pvBits, pImpDesc->Name, const char *);
-    cchImportName = kLdrHlpStrLen(pszImportName);
+    cchImportName = kHlpStrLen(pszImportName);
     if (cchImportName < cchName)
     {
-        kLdrHlpMemCopy(pszName, pszImportName, cchImportName + 1);
+        kHlpMemCopy(pszName, pszImportName, cchImportName + 1);
         rc = 0;
     }
     else
     {
-        kLdrHlpMemCopy(pszName, pszImportName, cchName);
+        kHlpMemCopy(pszName, pszImportName, cchName);
         if (cchName)
             pszName[cchName - 1] = '\0';
@@ -1594,5 +1593,5 @@
                 const IMAGE_IMPORT_BY_NAME *pName = KLDRMODPE_RVA2TYPE(pvMapping, pThunk->u1.Ordinal, const IMAGE_IMPORT_BY_NAME *);
                 rc = pfnGetImport(pMod, iImp, NIL_KLDRMOD_SYM_ORDINAL, (const char *)pName->Name,
-                                  kLdrHlpStrLen((const char *)pName->Name), NULL, &Value, &fKind, pvUser);
+                                  kHlpStrLen((const char *)pName->Name), NULL, &Value, &fKind, pvUser);
             }
             else
@@ -1662,5 +1661,5 @@
                 const IMAGE_IMPORT_BY_NAME *pName = KLDRMODPE_RVA2TYPE(pvMapping, pThunk->u1.Ordinal, const IMAGE_IMPORT_BY_NAME *);
                 rc = pfnGetImport(pMod, iImp, NIL_KLDRMOD_SYM_ORDINAL, (const char *)pName->Name,
-                                  kLdrHlpStrLen((const char *)pName->Name), NULL, &Value, &fKind, pvUser);
+                                  kHlpStrLen((const char *)pName->Name), NULL, &Value, &fKind, pvUser);
             }
             else
@@ -1902,5 +1901,5 @@
      * Zero the entire buffer first to simplify things.
      */
-    kLdrHlpMemSet(pvBits, 0, pModPE->Hdrs.OptionalHeader.SizeOfImage);
+    kHlpMemSet(pvBits, 0, pModPE->Hdrs.OptionalHeader.SizeOfImage);
 
     /*
Index: trunk/kStuff/kLdr/kLdrRdr.c
===================================================================
--- trunk/kStuff/kLdr/kLdrRdr.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdrRdr.c	(revision 3573)
@@ -44,5 +44,5 @@
  */
 #ifdef KLDRRDR_STRICT
-# define KLDRRDR_ASSERT(expr)  kldrHlpAssert(expr)
+# define KLDRRDR_ASSERT(expr)  kHlpAssert(expr)
 #else
 # define KLDRRDR_ASSERT(expr)  do {} while (0)
Index: trunk/kStuff/kLdr/kLdrRdrFile.c
===================================================================
--- trunk/kStuff/kLdr/kLdrRdrFile.c	(revision 3572)
+++ trunk/kStuff/kLdr/kLdrRdrFile.c	(revision 3573)
@@ -153,5 +153,4 @@
 
 #include <k/kLdr.h>
-#include "kLdrHlp.h"
 
 
@@ -167,5 +166,5 @@
  */
 #ifdef KLDRRDRFILE_STRICT
-# define KLDRRDRFILE_ASSERT(expr)  kldrHlpAssert(expr)
+# define KLDRRDRFILE_ASSERT(expr)  kHlpAssert(expr)
 #else
 # define KLDRRDRFILE_ASSERT(expr)  do {} while (0)
@@ -377,5 +376,5 @@
 {
     kldrRdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, 1 /* unprotect */);
-    return kldrHlpPageFree(pPrep->pv, pPrep->cb);
+    return kHlpPageFree(pPrep->pv, pPrep->cb);
 }
 
@@ -452,5 +451,5 @@
         pv = (KU8 *)pPrep->pv + paSegments[i].RVA;
 
-        rc = kldrHlpPageProtect(pv, paSegments[i].cbMapped, enmProt);
+        rc = kHlpPageProtect(pv, paSegments[i].cbMapped, enmProt);
         if (rc)
             break;
@@ -502,5 +501,5 @@
      */
     /** @todo only zero the areas not covered by raw file bits. */
-    kLdrHlpMemSet(pPrep->pv, 0, pPrep->cb);
+    kHlpMemSet(pPrep->pv, 0, pPrep->cb);
 
     /*
@@ -769,7 +768,7 @@
 
     /*
-     * Generic mapping code using kldrHlpPageAlloc(), kldrHlpPageFree() and kldrHlpPageProtect().
-     */
-    rc = kldrHlpPageAlloc(&pPrep->pv, pPrep->cb, KPROT_EXECUTE_READWRITE, fFixed);
+     * Generic mapping code using kHlpPageAlloc(), kHlpPageFree() and kHlpPageProtect().
+     */
+    rc = kHlpPageAlloc(&pPrep->pv, pPrep->cb, KPROT_EXECUTE_READWRITE, fFixed);
     if (rc)
         return rc;
@@ -804,5 +803,5 @@
 
     /* bailout */
-    kldrHlpPageFree(pPrep->pv, pPrep->cb);
+    kHlpPageFree(pPrep->pv, pPrep->cb);
     return rc;
 }
@@ -896,5 +895,5 @@
     if (!--pRdrFile->cMappings)
     {
-        kldrHlpFree(pRdrFile->pvMapping);
+        kHlpFree(pRdrFile->pvMapping);
         pRdrFile->pvMapping = NULL;
     }
@@ -917,5 +916,5 @@
         KLDRFOFF cb = pRdrFile->Core.pOps->pfnSize(pRdr);
 
-        pRdrFile->pvMapping = kldrHlpAlloc(cb);
+        pRdrFile->pvMapping = kHlpAlloc(cb);
         if (!pRdrFile->pvMapping)
 #if defined(__OS2__) || defined(__WIN__)
@@ -927,5 +926,5 @@
         if (rc)
         {
-            kldrHlpFree(pRdrFile->pvMapping);
+            kHlpFree(pRdrFile->pvMapping);
             pRdrFile->pvMapping = NULL;
             return rc;
@@ -1047,9 +1046,9 @@
     if (pRdrFile->pvMapping)
     {
-        kldrHlpFree(pRdrFile->pvMapping);
+        kHlpFree(pRdrFile->pvMapping);
         pRdrFile->pvMapping = NULL;
     }
 
-    kldrHlpFree(pRdr);
+    kHlpFree(pRdr);
     return rc;
 }
@@ -1076,7 +1075,7 @@
     {
         char *psz;
-        cchFilename = kLdrHlpStrLen(szFilename);
-        psz = (char *)kLdrHlpAllocA(cchFilename + 1);
-        kLdrHlpMemCopy(psz, pszFilename, cchFilename + 1);
+        cchFilename = kHlpStrLen(szFilename);
+        psz = (char *)kHlpAllocA(cchFilename + 1);
+        kHlpMemCopy(psz, pszFilename, cchFilename + 1);
         pszFilename = psz;
     }
@@ -1147,6 +1146,6 @@
      * Allocate the reader instance.
      */
-    cchFilename = kLdrHlpStrLen(szFilename);
-    pRdrFile = (PKLDRRDRFILE)kldrHlpAlloc(sizeof(*pRdrFile) + cchFilename);
+    cchFilename = kHlpStrLen(szFilename);
+    pRdrFile = (PKLDRRDRFILE)kHlpAlloc(sizeof(*pRdrFile) + cchFilename);
     if (!pRdrFile)
 #if defined(__OS2__)
@@ -1174,5 +1173,5 @@
     pRdrFile->cMappings = 0;
     pRdrFile->cPreps = 0;
-    kLdrHlpMemCopy(&pRdrFile->szFilename[0], szFilename, cchFilename + 1);
+    kHlpMemCopy(&pRdrFile->szFilename[0], szFilename, cchFilename + 1);
 
     *ppRdr = &pRdrFile->Core;
Index: trunk/kStuff/kLdr/tstkLdrHeap.c
===================================================================
--- trunk/kStuff/kLdr/tstkLdrHeap.c	(revision 3572)
+++ trunk/kStuff/kLdr/tstkLdrHeap.c	(revision 3573)
@@ -30,5 +30,5 @@
 *******************************************************************************/
 #include <k/kLdr.h>
-#include "kLdrHlp.h"
+#include <k/kHlp.h>
 
 #include <stdio.h>
@@ -44,5 +44,5 @@
 
 #define CHECK(expr) \
-    do { if (!(expr)) { printf("tstkLdrHeap(%d): ERROR - %s\n", __LINE__, #expr); cErrors++; kldrHlpBreakpoint();} \
+    do { if (!(expr)) { printf("tstkLdrHeap(%d): ERROR - %s\n", __LINE__, #expr); cErrors++; kHlpAssertBreakpoint();} \
     } while (0)
 
@@ -72,6 +72,6 @@
 
 #if 0
-# define kldrHlpAlloc(a) malloc(a)
-# define kldrHlpFree(a) free(a)
+# define kHlpAlloc(a) malloc(a)
+# define kHlpFree(a) free(a)
 #endif
 
@@ -93,11 +93,11 @@
      * Some simple init / term.
      */
-    rc = kldrHlpHeapInit();
-    CHECK_FATAL(!rc);
-    kldrHlpHeapTerm();
-
-    rc = kldrHlpHeapInit();
-    CHECK_FATAL(!rc);
-    kldrHlpHeapTerm();
+    rc = kHlpHeapInit();
+    CHECK_FATAL(!rc);
+    kHlpHeapTerm();
+
+    rc = kHlpHeapInit();
+    CHECK_FATAL(!rc);
+    kHlpHeapTerm();
 
 
@@ -105,5 +105,5 @@
      * Simple alloc all, free all in FIFO order.
      */
-    rc = kldrHlpHeapInit();
+    rc = kHlpHeapInit();
     CHECK_FATAL(!rc);
 
@@ -112,5 +112,5 @@
     {
         s_aAllocs[i].cb = RandSize();
-        s_aAllocs[i].pv = kldrHlpAlloc(s_aAllocs[i].cb);
+        s_aAllocs[i].pv = kHlpAlloc(s_aAllocs[i].cb);
         CHECK(s_aAllocs[i].pv);
     }
@@ -118,8 +118,8 @@
     /* 2. free all slots. */
     for (i = 0; i < MAX_ALLOCS; i++)
-        kldrHlpFree(s_aAllocs[i].pv);
+        kHlpFree(s_aAllocs[i].pv);
 
     /* terminate */
-    kldrHlpHeapTerm();
+    kHlpHeapTerm();
 
 
@@ -127,5 +127,5 @@
      * Simple alloc all, free all in LIFO order.
      */
-    rc = kldrHlpHeapInit();
+    rc = kHlpHeapInit();
     CHECK_FATAL(!rc);
 
@@ -134,5 +134,5 @@
     {
         s_aAllocs[i].cb = RandSize();
-        s_aAllocs[i].pv = kldrHlpAlloc(s_aAllocs[i].cb);
+        s_aAllocs[i].pv = kHlpAlloc(s_aAllocs[i].cb);
         CHECK(s_aAllocs[i].pv);
     }
@@ -141,8 +141,8 @@
     i = MAX_ALLOCS;
     while (i-- > 0)
-        kldrHlpFree(s_aAllocs[i].pv);
+        kHlpFree(s_aAllocs[i].pv);
 
     /* terminate */
-    kldrHlpHeapTerm();
+    kHlpHeapTerm();
 
 
@@ -150,5 +150,5 @@
      * Bunch of allocations, free half, allocate and free in pairs, free all.
      */
-    rc = kldrHlpHeapInit();
+    rc = kHlpHeapInit();
     CHECK_FATAL(!rc);
 
@@ -157,5 +157,5 @@
     {
         s_aAllocs[i].cb = RandSize();
-        s_aAllocs[i].pv = kldrHlpAlloc(s_aAllocs[i].cb);
+        s_aAllocs[i].pv = kHlpAlloc(s_aAllocs[i].cb);
         CHECK(s_aAllocs[i].pv);
     }
@@ -166,5 +166,5 @@
     {
         i = RandIdx(cAllocs);
-        kldrHlpFree(s_aAllocs[i].pv);
+        kHlpFree(s_aAllocs[i].pv);
         cAllocs--;
         if (i != cAllocs)
@@ -181,5 +181,5 @@
             i = cAllocs;
             s_aAllocs[i].cb = RandSize();
-            s_aAllocs[i].pv = kldrHlpAlloc(s_aAllocs[i].cb);
+            s_aAllocs[i].pv = kHlpAlloc(s_aAllocs[i].cb);
             CHECK(s_aAllocs[i].pv);
             cAllocs++;
@@ -191,5 +191,5 @@
         {
             i = RandIdx(cAllocs);
-            kldrHlpFree(s_aAllocs[i].pv);
+            kHlpFree(s_aAllocs[i].pv);
             cAllocs--;
             if (i != cAllocs)
@@ -202,5 +202,5 @@
     {
         i = RandIdx(cAllocs);
-        kldrHlpFree(s_aAllocs[i].pv);
+        kHlpFree(s_aAllocs[i].pv);
         cAllocs--;
         if (i != cAllocs)
@@ -209,5 +209,5 @@
 
     /* terminate */
-    kldrHlpHeapTerm();
+    kHlpHeapTerm();
 
 
