Index: /trunk/kDbg/kDbg.h
===================================================================
--- /trunk/kDbg/kDbg.h	(revision 3528)
+++ /trunk/kDbg/kDbg.h	(revision 3529)
@@ -68,4 +68,8 @@
 /** A specified address or an address found in the debug info is invalid. */
 #define KDBG_ERR_INVALID_ADDRESS                        (KDBG_ERR_BASE + 12)
+/** The dbghelp.dll is too old or something like that. */
+#define KDBG_ERR_DBGHLP_VERSION_MISMATCH                (KDBG_ERR_BASE + 13)
+/** Invalid executable format. */
+#define KDBG_ERR_BAD_EXE_FORMAT                         (KDBG_ERR_BASE + 14)
 
 /** @} */
Index: /trunk/kDbg/kDbgHlp.h
===================================================================
--- /trunk/kDbg/kDbgHlp.h	(revision 3528)
+++ /trunk/kDbg/kDbgHlp.h	(revision 3529)
@@ -119,4 +119,13 @@
 
 /**
+ * Gets the native file handle.
+ *
+ * @return  The native file handle.
+ *          -1 on failure.
+ * @param   pFile           The file handle.
+ */
+uintptr_t kDbgHlpNativeFileHandle(PKDBGHLPFILE pFile);
+
+/**
  * Gets the size of an open file.
  *
@@ -206,5 +215,25 @@
 #endif
 
+/**
+ * Helper function that displays the first part of the assertion message.
+ *
+ * @param   pszExpr         The expression.
+ * @param   pszFile         The file name.
+ * @param   iLine           The line number is the file.
+ * @param   pszFunction     The function name.
+ */
+void kDbgAssertMsg1(const char *pszExpr, const char *pszFile, unsigned iLine, const char *pszFunction);
+
+/**
+ * Helper function that displays custom assert message.
+ *
+ * @param   pszFormat       Format string that get passed to vprintf.
+ * @param   ...             Format arguments.
+ */
+void kDbgAssertMsg2(const char *pszFormat, ...);
+
+
 #ifdef KDBG_STRICT
+
 # define kDbgAssert(expr) \
     do { \
@@ -246,9 +275,10 @@
         }
     } while (0)
+
 #else   /* !KDBG_STRICT */
 # define kDbgAssert(expr)                       do { } while (0)
-# define kDbgAssertReturn(expr, rcRet)          do { } while (0)
+# define kDbgAssertReturn(expr, rcRet)          return (rcRet)
 # define kDbgAssertMsg(expr, msg)               do { } while (0)
-# define kDbgAssertMsgReturn(expr, msg, rcRet)  do { } while (0)
+# define kDbgAssertMsgReturn(expr, msg, rcRet)  return (rcRet)
 #endif  /* !KDBG_STRICT */
 
@@ -257,4 +287,8 @@
 #define kDbgAssertRC(rc)                        kDbgAssertMsg((rc) == 0, ("%s = %d\n", #rc, (rc)))
 #define kDbgAssertRCReturn(rc, rcRet)           kDbgAssertMsgReturn((rc) == 0, ("%s = %d -> %d\n", #rc, (rc), (rcRet)), (rcRet))
+#define kDbgAssertFailed()                      kDbgAssert(0)
+#define kDbgAssertFailedReturn(rcRet)           kDbgAssertReturn(0, (rcRet))
+#define kDbgAssertMsgFailed(msg)                kDbgAssertMsg(0, msg)
+#define kDbgAssertMsgFailedReturn(msg, rcRet)   kDbgAssertMsgReturn(0, msg, (rcRet))
 
 /** @} */
Index: /trunk/kDbg/kDbgHlpCrt.cpp
===================================================================
--- /trunk/kDbg/kDbgHlpCrt.cpp	(revision 3528)
+++ /trunk/kDbg/kDbgHlpCrt.cpp	(revision 3529)
@@ -33,4 +33,7 @@
 #include <string.h>
 #include <errno.h>
+#ifdef _MSC_VER
+# include <io.h>
+#endif
 
 
@@ -126,4 +129,15 @@
 
 
+uintptr_t kDbgHlpNativeFileHandle(PKDBGHLPFILE pFile)
+{
+    int fd = fileno(pFile->pStrm);
+#ifdef _MSC_VER
+    return _get_osfhandle(fd);
+#else
+    return fd;
+#endif
+}
+
+
 int64_t kDbgHlpFileSize(PKDBGHLPFILE pFile)
 {
Index: /trunk/kDbg/kDbgModPE-generic.cpp
===================================================================
--- /trunk/kDbg/kDbgModPE-generic.cpp	(revision 3528)
+++ /trunk/kDbg/kDbgModPE-generic.cpp	(revision 3529)
@@ -63,5 +63,5 @@
  * @param   puRVA       Where to store the RVA on success.
  */
-static int rtDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA)
+static int kDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA)
 {
     if (iSegment >= 0)
@@ -83,5 +83,5 @@
         return 0;
     }
-    AssertMsgFailedReturn(("iSegment=%RI32\n", iSegment), KDBG_ERR_INVALID_ADDRESS);
+    kDbgAssertMsgFailedReturn(("iSegment=%d\n", iSegment), KDBG_ERR_INVALID_ADDRESS);
 }
 
@@ -97,5 +97,5 @@
  * @param   poff        Where to store the segment offset.
  */
-static int rtDbgModPeRVAToSegOff(PKDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff)
+static int kDbgModPeRVAToSegOff(PKDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff)
 {
     kDbgAssertMsgReturn(uRVA < pModPe->cbImage, ("uRVA=%x, cbImage=%x\n", uRVA, pModPe->cbImage),
@@ -112,5 +112,5 @@
         }
     }
-    AssertMsgFailedReturn(("uRVA=%x\n", uRVA), KDBG_ERR_INVALID_ADDRESS);
+    kDbgAssertMsgFailedReturn(("uRVA=%x\n", uRVA), KDBG_ERR_INVALID_ADDRESS);
 }
 
@@ -119,5 +119,5 @@
  * @copydoc KDBGMODOPS::pfnQueryLine
  */
-static DECLCALLBACK(int) rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)
+static int rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)
 {
     PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
@@ -127,5 +127,5 @@
      */
     uint32_t uRVA;
-    int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
+    int rc = kDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
     if (!rc)
     {
@@ -137,5 +137,5 @@
         {
             pLine->RVA = (KDBGADDR)(Line.Address - pModPe->ImageBase);
-            rc = rtDbgModPeRVAToSegOff(pModPe, pLine->RVA, &pLine->iSegment, &pLine->offSegment);
+            rc = kDbgModPeRVAToSegOff(pModPe, pLine->RVA, &pLine->iSegment, &pLine->offSegment);
             pLine->iLine = Line.LineNumber;
             pLine->cchFile = strlen(Line.FileName);
@@ -147,5 +147,5 @@
         {
             DWORD Err = GetLastError();
-            rc = RTErrConvertFromWin32(Err);
+            rc = kDbgModPeConvWinError(Err);
         }
 #endif
@@ -159,5 +159,5 @@
  * @copydoc KDBGMODOPS::pfnQuerySymbol
  */
-static DECLCALLBACK(int) rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)
+static int rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)
 {
     PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
@@ -167,5 +167,5 @@
      */
     uint32_t uRVA;
-    int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
+    int rc = kDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
     if (!rc)
     {
@@ -200,5 +200,5 @@
             {
                 pSym->RVA        = (KDBGADDR)(Buf.Sym.Address - pModPe->ImageBase);
-                rc = rtDbgModPeRVAToSegOff(pModPe, pSym->RVA, &pSym->iSegment, &pSym->offSegment);
+                rc = kDbgModPeRVAToSegOff(pModPe, pSym->RVA, &pSym->iSegment, &pSym->offSegment);
             }
             pSym->cchName = (uint16_t)Buf.Sym.NameLen;
@@ -211,5 +211,5 @@
         {
             DWORD Err = GetLastError();
-            rc = RTErrConvertFromWin32(Err);
+            rc = kDbgModPeConvWinError(Err);
         }
 #endif
@@ -223,5 +223,5 @@
  * @copydoc KDBGMODOPS::pfnClose
  */
-static DECLCALLBACK(int) rtDbgModPEClose(PKDBGMOD pMod)
+static int rtDbgModPEClose(PKDBGMOD pMod)
 {
     PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
@@ -231,6 +231,6 @@
     //
     //DWORD Err = GetLastError();
-    //int rc = RTErrConvertFromWin32(Err);
-    //AssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
+    //int rc = kDbgModPeConvWinError(Err);
+    //kDbgAssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
     //return rc;
     return VERR_NOT_IMPLEMENTED;
@@ -255,5 +255,5 @@
  * @returns IPRT status code.
  *
- * @param   File                The handle to the module.
+ * @param   pFile               The handle to the module.
  * @param   offHdr              The offset of the PE header.
  * @param   pszModulePath       The path to the module.
@@ -261,5 +261,5 @@
  *
  */
-int kdbgModPEOpen(RTFILE File, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)
+int kdbgModPEOpen(PKDBGHLPFILE pFile, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)
 {
     /*
@@ -356,6 +356,6 @@
 
             DWORD Err = GetLastError();
-            rc = RTErrConvertFromWin32(Err);
-            AssertMsgFailed(("SymLoadModule64 failed: Err=%d rc=%Rrc\n", Err, rc));
+            rc = kDbgModPeConvWinError(Err);
+            kDbgAssertMsgFailed(("SymLoadModule64 failed: Err=%d rc=%Rrc\n", Err, rc));
             g_pfnSymCleanup(hSymInst);
         }
@@ -363,6 +363,6 @@
         {
             DWORD Err = GetLastError();
-            rc = RTErrConvertFromWin32(Err);
-            AssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
+            rc = kDbgModPeConvWinError(Err);
+            kDbgAssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
         }
 #endif
Index: /trunk/kDbg/kDbgModPE-win.cpp
===================================================================
--- /trunk/kDbg/kDbgModPE-win.cpp	(revision 3528)
+++ /trunk/kDbg/kDbgModPE-win.cpp	(revision 3529)
@@ -32,4 +32,5 @@
 #define _IMAGEHLP64
 #include <DbgHelp.h>
+#include <malloc.h> /* alloca */
 
 #include "kDbgInternal.h"
@@ -81,4 +82,20 @@
 
 /**
+ * Convers a Windows error to kDbg error code.
+ *
+ * @returns kDbg status code.
+ * @param   rc          The Windows error.
+ */
+static int kDbgModPeConvWinError(DWORD rc)
+{
+    switch (rc)
+    {
+        case 0:                     return 0;
+        default:                    return KDBG_ERR_GENERAL_FAILURE;
+    }
+}
+
+
+/**
  * Calcs the RVA for a segment:offset address.
  *
@@ -90,5 +107,5 @@
  * @param   puRVA       Where to store the RVA on success.
  */
-static int rtDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA)
+static int kDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA)
 {
     if (iSegment >= 0)
@@ -99,5 +116,5 @@
                             ("off=" PRI_KDBGADDR " VirtualSize=%x\n", off, pModPe->aSections[iSegment].Misc.VirtualSize),
                             KDBG_ERR_INVALID_ADDRESS);
-        *puRVA = pModPe->aSections[iSegment].VirtualAddress + off;
+        *puRVA = pModPe->aSections[iSegment].VirtualAddress + (uint32_t)off;
         return 0;
     }
@@ -107,8 +124,8 @@
         kDbgAssertMsgReturn(off < pModPe->cbImage, ("off=" PRI_KDBGADDR ", cbImage=%x\n", off, pModPe->cbImage),
                             KDBG_ERR_INVALID_ADDRESS);
-        *puRVA = off;
+        *puRVA = (uint32_t)off;
         return 0;
     }
-    AssertMsgFailedReturn(("iSegment=%RI32\n", iSegment), KDBG_ERR_INVALID_ADDRESS);
+    kDbgAssertMsgFailedReturn(("iSegment=%d\n", iSegment), KDBG_ERR_INVALID_ADDRESS);
 }
 
@@ -124,5 +141,5 @@
  * @param   poff        Where to store the segment offset.
  */
-static int rtDbgModPeRVAToSegOff(PKDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff)
+static int kDbgModPeRVAToSegOff(PKDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff)
 {
     kDbgAssertMsgReturn(uRVA < pModPe->cbImage, ("uRVA=%x, cbImage=%x\n", uRVA, pModPe->cbImage),
@@ -139,5 +156,5 @@
         }
     }
-    AssertMsgFailedReturn(("uRVA=%x\n", uRVA), KDBG_ERR_INVALID_ADDRESS);
+    kDbgAssertMsgFailedReturn(("uRVA=%x\n", uRVA), KDBG_ERR_INVALID_ADDRESS);
 }
 
@@ -146,5 +163,5 @@
  * @copydoc KDBGMODOPS::pfnQueryLine
  */
-static DECLCALLBACK(int) rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)
+static int rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)
 {
     PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
@@ -154,5 +171,5 @@
      */
     uint32_t uRVA;
-    int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
+    int rc = kDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
     if (!rc)
     {
@@ -163,15 +180,17 @@
         {
             pLine->RVA = (KDBGADDR)(Line.Address - pModPe->ImageBase);
-            rc = rtDbgModPeRVAToSegOff(pModPe, pLine->RVA, &pLine->iSegment, &pLine->offSegment);
+            rc = kDbgModPeRVAToSegOff(pModPe, (uint32_t)pLine->RVA, &pLine->iSegment, &pLine->offSegment);
             pLine->iLine = Line.LineNumber;
-            pLine->cchFile = strlen(Line.FileName);
-            if (pLine->cchFile >= sizeof(pLine->szFile))
-                pLine->cchFile = sizeof(pLine->szFile) - 1;
-            memcpy(pLine->szFile, Line.FileName, pLine->cchFile + 1);
+            size_t cchFile = strlen(Line.FileName);
+            pLine->cchFile = cchFile < sizeof(pLine->szFile)
+                           ? (uint16_t)cchFile
+                           : (uint16_t)sizeof(pLine->szFile) - 1;
+            memcpy(pLine->szFile, Line.FileName, pLine->cchFile);
+            pLine->szFile[pLine->cchFile] = '\0';
         }
         else
         {
             DWORD Err = GetLastError();
-            rc = RTErrConvertFromWin32(Err);
+            rc = kDbgModPeConvWinError(Err);
         }
     }
@@ -183,5 +202,5 @@
  * @copydoc KDBGMODOPS::pfnQuerySymbol
  */
-static DECLCALLBACK(int) rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)
+static int rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)
 {
     PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
@@ -191,5 +210,5 @@
      */
     uint32_t uRVA;
-    int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
+    int rc = kDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
     if (!rc)
     {
@@ -223,5 +242,5 @@
             {
                 pSym->RVA        = (KDBGADDR)(Buf.Sym.Address - pModPe->ImageBase);
-                rc = rtDbgModPeRVAToSegOff(pModPe, pSym->RVA, &pSym->iSegment, &pSym->offSegment);
+                rc = kDbgModPeRVAToSegOff(pModPe, (uint32_t)pSym->RVA, &pSym->iSegment, &pSym->offSegment);
             }
             pSym->cchName = (uint16_t)Buf.Sym.NameLen;
@@ -234,5 +253,5 @@
         {
             DWORD Err = GetLastError();
-            rc = RTErrConvertFromWin32(Err);
+            rc = kDbgModPeConvWinError(Err);
         }
     }
@@ -244,5 +263,5 @@
  * @copydoc KDBGMODOPS::pfnClose
  */
-static DECLCALLBACK(int) rtDbgModPEClose(PKDBGMOD pMod)
+static int rtDbgModPEClose(PKDBGMOD pMod)
 {
     PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
@@ -252,6 +271,6 @@
 
     DWORD Err = GetLastError();
-    int rc = RTErrConvertFromWin32(Err);
-    AssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
+    int rc = kDbgModPeConvWinError(Err);
+    kDbgAssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
     return rc;
 }
@@ -301,14 +320,14 @@
                     rc = 0;
                 else
-                    rc = VERR_VERSION_MISMATCH;
+                    rc = KDBG_ERR_DBGHLP_VERSION_MISMATCH;
             }
             else
-                rc = VERR_GENERAL_FAILURE;
+                rc = KDBG_ERR_GENERAL_FAILURE;
         }
         else
-            rc = RTErrConvertFromWin32(GetLastError());
+            rc = kDbgModPeConvWinError(GetLastError());
     }
     else
-        rc = RTErrConvertFromWin32(GetLastError());
+        rc = kDbgModPeConvWinError(GetLastError());
     return rc;
 }
@@ -325,13 +344,13 @@
     uint32_t FileVersionMS = 0;
     uint32_t FileVersionLS = 0;
-    int rc = VERR_GENERAL_FAILURE;
+    int rc = KDBG_ERR_GENERAL_FAILURE;
     static char s_szDbgHelp[] = "\\dbghelp.dll";
-    if (GetCurrentDirectory(cchPath - sizeof(s_szDbgHelp) + 1, pszPath))
+    if (GetCurrentDirectory((DWORD)(cchPath - sizeof(s_szDbgHelp) + 1), pszPath))
     {
         strcat(pszPath, s_szDbgHelp);
         int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
-        if (RT_SUCCESS(rc2))
+        if (!rc2)
             return rc2;
-        if (rc != VERR_VERSION_MISMATCH)
+        if (rc != KDBG_ERR_DBGHLP_VERSION_MISMATCH)
             rc = rc2;
     }
@@ -340,5 +359,5 @@
      * Try the application directory.
      */
-    if (GetModuleFileName(NULL, pszPath, cchPath - sizeof(s_szDbgHelp) + 1))
+    if (GetModuleFileName(NULL, pszPath, (DWORD)(cchPath - sizeof(s_szDbgHelp) + 1)))
     {
         strcat(strrchr(pszPath, '\\'), s_szDbgHelp);
@@ -346,5 +365,5 @@
         if (!rc)
             return rc2;
-        if (rc != VERR_VERSION_MISMATCH)
+        if (rc != KDBG_ERR_DBGHLP_VERSION_MISMATCH)
             rc = rc2;
     }
@@ -353,11 +372,11 @@
      * Try the windows directory.
      */
-    if (GetSystemDirectory(pszPath, cchPath - sizeof(s_szDbgHelp) + 1))
+    if (GetSystemDirectory(pszPath, (DWORD)(cchPath - sizeof(s_szDbgHelp) + 1)))
     {
         strcat(pszPath, s_szDbgHelp);
         int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
-        if (RT_SUCCESS(rc2))
+        if (!rc2)
             return rc2;
-        if (rc != VERR_VERSION_MISMATCH)
+        if (rc != KDBG_ERR_DBGHLP_VERSION_MISMATCH)
             rc = rc2;
     }
@@ -366,11 +385,11 @@
      * Try the windows directory.
      */
-    if (GetWindowsDirectory(pszPath, cchPath - sizeof(s_szDbgHelp) + 1))
+    if (GetWindowsDirectory(pszPath, (DWORD)(cchPath - sizeof(s_szDbgHelp) + 1)))
     {
         strcat(pszPath, s_szDbgHelp);
         int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
-        if (RT_SUCCESS(rc2))
+        if (!rc2)
             return rc2;
-        if (rc != VERR_VERSION_MISMATCH)
+        if (rc != KDBG_ERR_DBGHLP_VERSION_MISMATCH)
             rc = rc2;
     }
@@ -397,7 +416,7 @@
                 memcpy(&pszPath[pszEnd - psz], s_szDbgHelp, sizeof(s_szDbgHelp));
                 int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
-                if (RT_SUCCESS(rc2))
+                if (!rc2)
                     return rc2;
-                if (rc != VERR_VERSION_MISMATCH)
+                if (rc != KDBG_ERR_DBGHLP_VERSION_MISMATCH)
                     rc = rc2;
             }
@@ -410,11 +429,11 @@
     }
 
-    if (rc == VERR_VERSION_MISMATCH)
-        AssertMsgFailed(("dbghelp.dll found, but it was ancient! The highest file version found was 0x%08x'%08x.\n"
+    if (rc == KDBG_ERR_DBGHLP_VERSION_MISMATCH)
+        kDbgAssertMsgFailed(("dbghelp.dll found, but it was ancient! The highest file version found was 0x%08x'%08x.\n"
                          "This program require a file version of at least 0x00060004'00000000. Please download\n"
                          "the latest windbg and use the dbghelp.dll from that package. Just put it somewhere in\n"
                          "the PATH and we'll find it.\n", FileVersionMS, FileVersionLS));
     else
-        AssertMsgFailed(("dbghelp.dll was not found! Download the latest windbg and use the dbghelp.dll\n"
+        kDbgAssertMsgFailed(("dbghelp.dll was not found! Download the latest windbg and use the dbghelp.dll\n"
                          "from that package - just put it somewhere in the PATH and we'll find it.\n"));
     return rc;
@@ -435,10 +454,10 @@
     /* primitive locking - make some useful API for this kind of spinning! */
     static volatile uint32_t s_u32Lock = 0;
-    while (!ASMAtomicCmpXchgU32(&s_u32Lock, 1, 0))
+    while (!InterlockedCompareExchange((long volatile *)&s_u32Lock, 1, 0))
         while (s_u32Lock)
-            RTThreadYield();
+            Sleep(1);
     if (g_hDbgHelp)
     {
-        ASMAtomicXchgU32(&s_u32Lock, 0);
+        InterlockedExchange((long volatile *)&s_u32Lock, 0);
         return 0;
     }
@@ -451,5 +470,5 @@
     if (rc)
     {
-        ASMAtomicXchgU32(&s_u32Lock, 0);
+        InterlockedExchange((volatile long *)&s_u32Lock, 0);
         return rc;
     }
@@ -459,6 +478,6 @@
     {
         DWORD Err = GetLastError();
-        int rc = RTErrConvertFromWin32(Err);
-        AssertMsgFailedReturn(("Failed to load '%s', Err=%d rc=%Rrc\n", szPath, Err, rc), rc);
+        int rc = kDbgModPeConvWinError(Err);
+        kDbgAssertMsgFailedReturn(("Failed to load '%s', Err=%d rc=%Rrc\n", szPath, Err, rc), rc);
     }
 
@@ -496,5 +515,5 @@
                 { "SymGetLineFromAddr64", (FARPROC *)&g_pfnSymGetLineFromAddr64 },
             };
-            for (unsigned i = 0; i < ELEMENTS(s_aFunctions); i++)
+            for (unsigned i = 0; i < KDBG_ELEMENTS(s_aFunctions); i++)
             {
                 FARPROC pfn = GetProcAddress(hmod, s_aFunctions[i].pszName);
@@ -502,6 +521,6 @@
                 {
                     DWORD Err = GetLastError();
-                    rc = RTErrConvertFromWin32(Err);
-                    AssertMsgFailed(("Failed to resolve %s in dbghelp, Err=%d rc=%Rrc\n",
+                    rc = kDbgModPeConvWinError(Err);
+                    kDbgAssertMsgFailed(("Failed to resolve %s in dbghelp, Err=%d rc=%Rrc\n",
                                      s_aFunctions[i].pszName, Err, rc));
                     break;
@@ -511,6 +530,8 @@
             if (!rc)
             {
-                ASMAtomicXchgSize(&g_hDbgHelp, hmod);
-                ASMAtomicXchgU32(&s_u32Lock, 0);
+                //InterlockedExchange(&g_hDbgHelp, hmod);
+                g_hDbgHelp = hmod;
+                Sleep(1);
+                InterlockedExchange((volatile long *)&s_u32Lock, 0);
                 return 0;
             }
@@ -518,6 +539,6 @@
         else
         {
-            rc = VERR_VERSION_MISMATCH;
-            AssertMsgFailed(("ImagehlpApiVersion -> %p and MajorVersion=%d.\n", pVersion, pVersion ? pVersion->MajorVersion : 0));
+            rc = KDBG_ERR_DBGHLP_VERSION_MISMATCH;
+            kDbgAssertMsgFailed(("ImagehlpApiVersion -> %p and MajorVersion=%d.\n", pVersion, pVersion ? pVersion->MajorVersion : 0));
         }
     }
@@ -525,9 +546,9 @@
     {
         DWORD Err = GetLastError();
-        rc = RTErrConvertFromWin32(Err);
-        AssertMsgFailed(("Failed to resolve ImagehlpApiVersionEx in dbghelp, Err=%d rc=%Rrc\n", Err, rc));
+        rc = kDbgModPeConvWinError(Err);
+        kDbgAssertMsgFailed(("Failed to resolve ImagehlpApiVersionEx in dbghelp, Err=%d rc=%Rrc\n", Err, rc));
     }
     FreeLibrary(hmod);
-    ASMAtomicXchgU32(&s_u32Lock, 0);
+    InterlockedExchange((long volatile *)&s_u32Lock, 0);
     return rc;
 }
@@ -539,5 +560,5 @@
  * @returns IPRT status code.
  *
- * @param   File                The handle to the module.
+ * @param   pFile               The handle to the module.
  * @param   offHdr              The offset of the PE header.
  * @param   pszModulePath       The path to the module.
@@ -545,5 +566,5 @@
  *
  */
-int kdbgModPEOpen(RTFILE File, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)
+int kdbgModPEOpen(PKDBGHLPFILE pFile, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)
 {
     /*
@@ -551,17 +572,17 @@
      */
     IMAGE_FILE_HEADER FHdr;
-    int rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, FileHeader), &FHdr, sizeof(FHdr), NULL);
-    AssertRCReturn(rc, rc);
+    int rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, FileHeader), &FHdr, sizeof(FHdr));
+    kDbgAssertRCReturn(rc, rc);
 
     uint32_t cbImage;
     if (FHdr.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER32))
-        rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader.SizeOfImage),
-                          &cbImage, sizeof(cbImage), NULL);
+        rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader.SizeOfImage),
+                           &cbImage, sizeof(cbImage));
     else if (FHdr.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER64))
-        rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS64, OptionalHeader.SizeOfImage),
-                          &cbImage, sizeof(cbImage), NULL);
+        rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS64, OptionalHeader.SizeOfImage),
+                           &cbImage, sizeof(cbImage));
     else
-        AssertFailedReturn(VERR_BAD_EXE_FORMAT);
-    AssertRCReturn(rc, rc);
+        kDbgAssertFailedReturn(KDBG_ERR_BAD_EXE_FORMAT);
+    kDbgAssertRCReturn(rc, rc);
 
     /*
@@ -575,13 +596,13 @@
      * Allocate the module and read/construct the section headers.
      */
-    PKDBGMODPE pModPe = (PKDBGMODPE)RTMemAlloc(KDBG_OFFSETOF(KDBGMODPE, aSections[FHdr.NumberOfSections + 2]));
-    AssertReturn(pModPe, KDBG_ERR_NO_MEMORY);
+    PKDBGMODPE pModPe = (PKDBGMODPE)kDbgHlpAlloc(KDBG_OFFSETOF(KDBGMODPE, aSections[FHdr.NumberOfSections + 2]));
+    kDbgAssertReturn(pModPe, KDBG_ERR_NO_MEMORY);
     pModPe->Core.u32Magic   = KDBGMOD_MAGIC;
     pModPe->Core.pOps       = &g_rtDbgModPEOps;
-    pModPe->Core.File       = File;
+    pModPe->Core.pFile      = pFile;
     pModPe->cbImage         = cbImage;
     pModPe->cSections       = 1 + FHdr.NumberOfSections;
-    rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader) + FHdr.SizeOfOptionalHeader,
-                      &pModPe->aSections[1], sizeof(pModPe->aSections[0]) * FHdr.NumberOfSections, NULL);
+    rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader) + FHdr.SizeOfOptionalHeader,
+                       &pModPe->aSections[1], sizeof(pModPe->aSections[0]) * FHdr.NumberOfSections);
     if (!rc)
     {
@@ -622,9 +643,9 @@
          */
         static volatile uint32_t s_u32LastHandle = 1;
-        HANDLE hSymInst = (HANDLE)ASMAtomicIncU32(&s_u32LastHandle);
+        HANDLE hSymInst = (HANDLE)InterlockedIncrement((long *)&s_u32LastHandle);
         while (     hSymInst == INVALID_HANDLE_VALUE
                ||   hSymInst == (HANDLE)0
                ||   hSymInst == GetCurrentProcess())
-            hSymInst = (HANDLE)ASMAtomicIncU32(&s_u32LastHandle);
+            hSymInst = (HANDLE)InterlockedIncrement((long *)&s_u32LastHandle);
 
         /*
@@ -635,6 +656,7 @@
             g_pfnSymSetOptions(SYMOPT_LOAD_LINES | SYMOPT_AUTO_PUBLICS | SYMOPT_ALLOW_ABSOLUTE_SYMBOLS);
 
-            RTFileSeek(File, 0, RTFILE_SEEK_BEGIN, NULL); /* don't know if this is required or not... */
-            DWORD64 ImageBase = g_pfnSymLoadModule64(hSymInst, (HANDLE)File, pszModulePath, NULL, 0x00400000, 0);
+            kDbgHlpSeek(pFile, 0); /* don't know if this is required or not... */
+            DWORD64 ImageBase = g_pfnSymLoadModule64(hSymInst, (HANDLE)kDbgHlpNativeFileHandle(pFile),
+                                                     pszModulePath, NULL, 0x00400000, 0);
             if (ImageBase)
             {
@@ -646,6 +668,6 @@
 
             DWORD Err = GetLastError();
-            rc = RTErrConvertFromWin32(Err);
-            AssertMsgFailed(("SymLoadModule64 failed: Err=%d rc=%Rrc\n", Err, rc));
+            rc = kDbgModPeConvWinError(Err);
+            kDbgAssertMsgFailed(("SymLoadModule64 failed: Err=%d rc=%Rrc\n", Err, rc));
             g_pfnSymCleanup(hSymInst);
         }
@@ -653,10 +675,10 @@
         {
             DWORD Err = GetLastError();
-            rc = RTErrConvertFromWin32(Err);
-            AssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
+            rc = kDbgModPeConvWinError(Err);
+            kDbgAssertMsgFailed(("SymInitialize failed: Err=%d rc=%Rrc\n", Err, rc));
         }
     }
     else
-        AssertRC(rc);
+        kDbgAssertRC(rc);
 
     kDbgHlpFree(pModPe);
