Index: /trunk/kLdr/Makefile.kmk
===================================================================
--- /trunk/kLdr/Makefile.kmk	(revision 2857)
+++ /trunk/kLdr/Makefile.kmk	(revision 2858)
@@ -68,11 +68,13 @@
  kLdr_TOOL = GCC3
  kLdr_TOOL = VCC70
- kLdr_CFLAGS = -W3 -Zl
+ kLdr_CFLAGS = -W3 -Zl -ML
  kLdr_ASFLAGS = -f win
- kLdr_LDFLAGS = -Entry:DllMain@12
+ kLdr_LDFLAGS = -Entry:DllMain@12 -Debug
  kLdr_DEFS = __WIN__
  kLdr_SDKS = WIN32SDK
  #kLdr_SDKS.x86 = WIN32SDK
  #kLdr_SDKS.amd64 = WIN64SDK
+ kLdr_LIBS = \
+   	$$(PATH_TOOL_VCC70_LIB)/LIBC.lib
 else
  ifneq ($(filter os2,$(BUILD_TARGET)),)
@@ -138,4 +140,18 @@
 	kLdrHlpHeap.c \
 
+#
+# Heap testcase.
+#
+PROGRAMS += tstkLdrMod
+tstkLdrMod_TEMPLATE = TST
+tstkLdrMod_SOURCES = \
+	tstkLdrMod.c
+ifneq ($(filter win win32 win64 nt,$(BUILD_TARGET)),)
+tstkLdrMod_LIBS = $(TARGET_kLdr:.dll=.lib)
+else
+tstkLdrMod_LIBS = $(TARGET_kLdr)
+endif
+
+
 
 # generate rules.
Index: /trunk/kLdr/kLdr-win.def
===================================================================
--- /trunk/kLdr/kLdr-win.def	(revision 2857)
+++ /trunk/kLdr/kLdr-win.def	(revision 2858)
@@ -38,8 +38,39 @@
     kLdrRdrTell
     kLdrRdrName
+    kLdrRdrPageSize
+    kLdrRdrPrepare
+    kLdrRdrMap
+    kLdrRdrRefreshMap
+    kLdrRdrProtect
+    kLdrRdrUnmap
+    kLdrRdrUnprepare
+    kLdrRdrDone
 
     ; The module interpreter API
+    kLdrModOpen
     kLdrModOpenFromRdr
-    kLdrModOpen
+    kLdrModOpenNative
+    kLdrModClose
+    kLdrModQuerySymbol
+    kLdrModEnumSymbols
+    kLdrModGetImport
+    kLdrModNumberOfImports
+    kLdrModCanExecuteOn
+    kLdrModGetStackInfo
+    kLdrModQueryMainEntrypoint
+    kLdrModEnumDbgInfo
+    kLdrModHasDbgInfo
+    kLdrModMap
+    kLdrModUnmap
+    kLdrModAllocTLS
+    kLdrModFreeTLS
+    kLdrModReload
+    kLdrModFixupMapping
+    kLdrModCallInit
+    kLdrModCallTerm
+    kLdrModCallThread
+    kLdrModSize
+    kLdrModGetBits
+    kLdrModRelocateBits
 
     ; Process Bootstrapping
Index: /trunk/kLdr/kLdr.h
===================================================================
--- /trunk/kLdr/kLdr.h	(revision 2857)
+++ /trunk/kLdr/kLdr.h	(revision 2858)
@@ -928,7 +928,7 @@
  */
 #ifdef __OS2__
-# define KLDR_ERR_BASE          0x7face000
+# define KLDR_ERR_BASE          420000
 #elif defined(__WIN__)
-# define KLDR_ERR_BASE          0x7face000
+# define KLDR_ERR_BASE          420000
 #else
 # error "port me"
Index: /trunk/kLdr/kLdrHlp.h
===================================================================
--- /trunk/kLdr/kLdrHlp.h	(revision 2857)
+++ /trunk/kLdr/kLdrHlp.h	(revision 2858)
@@ -38,5 +38,5 @@
 #define KLDR_MAX(a, b) ((a) >= (b) ? (a) : (b))
 /** Calculate the offset of a structure member. */
-#define KLDR_OFFSETOF(strct, memb)  ( (size_t)( ((strct *)0)->memb ) )
+#define KLDR_OFFSETOF(strct, memb)  ( (size_t)( &((strct *)0)->memb ) )
 /** Align a size_t value. */
 #define KLDR_ALIGN_Z(val, align)    ( ((val) + ((align) - 1)) & ~(size_t)((align) - 1) )
Index: /trunk/kLdr/kLdrInternal.h
===================================================================
--- /trunk/kLdr/kLdrInternal.h	(revision 2857)
+++ /trunk/kLdr/kLdrInternal.h	(revision 2858)
@@ -403,4 +403,9 @@
 
 
+/** @name Module interpreter method tables
+ * @{ */
+extern KLDRMODOPS       g_kLdrModPEOps;
+/** @} */
+
 /** @} */
 #ifdef __cplusplus
Index: /trunk/kLdr/kLdrMod.c
===================================================================
--- /trunk/kLdr/kLdrMod.c	(revision 2857)
+++ /trunk/kLdr/kLdrMod.c	(revision 2858)
@@ -183,5 +183,5 @@
         rc = KLDR_ERR_LE_NOT_SUPPORTED;
     else if (u.u32 == IMAGE_NT_SIGNATURE)
-        rc = KLDR_ERR_PE_NOT_SUPPORTED;
+        rc = g_kLdrModPEOps.pfnCreate(&g_kLdrModPEOps, pRdr, offHdr, ppMod);
     else if (u.u32 == IMAGE_ELF_SIGNATURE)
         rc = KLDR_ERR_ELF_NOT_SUPPORTED;
Index: /trunk/kLdr/kLdrModPE.c
===================================================================
--- /trunk/kLdr/kLdrModPE.c	(revision 2857)
+++ /trunk/kLdr/kLdrModPE.c	(revision 2858)
@@ -204,15 +204,14 @@
      */
     cchFilename = kLdrHlpStrLen(kLdrRdrName(pRdr));
-    cb = sizeof(KLDRMOD)
-       + s.FileHdr.NumberOfSections * sizeof(KLDRSEG)
-       + sizeof(KLDRMODPE) - sizeof(IMAGE_SECTION_HEADER)
-       + s.FileHdr.NumberOfSections * sizeof(IMAGE_SECTION_HEADER)
+    cb = KLDR_ALIGN_Z(KLDR_OFFSETOF(KLDRMODPE, aShdrs[s.FileHdr.NumberOfSections]), 16)
+       + KLDR_OFFSETOF(KLDRMOD, aSegments[s.FileHdr.NumberOfSections + 1])
        + cchFilename + 1;
     pModPE = (PKLDRMODPE)kldrHlpAlloc(cb);
     if (!pModPE)
         return KLDR_ERR_NO_MEMORY;
+    *ppModPE = pModPE;
 
     /* KLDRMOD */
-    pMod = (PKLDRMOD)((uint8_t *)pModPE + sizeof(KLDRMOD) + (s.FileHdr.NumberOfSections + 1) * sizeof(KLDRSEG));
+    pMod = (PKLDRMOD)((uint8_t *)pModPE + KLDR_ALIGN_Z(KLDR_OFFSETOF(KLDRMODPE, aShdrs[s.FileHdr.NumberOfSections]), 16));
     pMod->pvData = pModPE;
     pMod->pRdr = pRdr;
@@ -252,5 +251,4 @@
     pModPE->Hdrs.Signature = s.Signature;
     pModPE->Hdrs.FileHeader = s.FileHdr;
-    *ppModPE = pModPE;
 
     /*
@@ -811,6 +809,6 @@
 
 /** @copydoc kLdrModEnumSymbols */
-static int kldrModPEEnumSymbols(PKLDRMOD pMod, uint32_t fFlags, const void *pvBits, KLDRADDR BaseAddress,
-                                PFNKLDRMODENUMSYMS pfnCallback, void *pvUser)
+static int kldrModPEEnumSymbols(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress,
+                                uint32_t fFlags, PFNKLDRMODENUMSYMS pfnCallback, void *pvUser)
 {
     PKLDRMODPE                      pModPE = (PKLDRMODPE)pMod->pvData;
@@ -890,5 +888,5 @@
 
 /** @copydoc kLdrModGetImport */
-static int kldrModPEGetImport(PKLDRMOD pMod, void *pvBits, uint32_t iImport, char *pszName, size_t cchName)
+static int kldrModPEGetImport(PKLDRMOD pMod, const void *pvBits, uint32_t iImport, char *pszName, size_t cchName)
 {
     PKLDRMODPE                      pModPE = (PKLDRMODPE)pMod->pvData;
@@ -1940,2 +1938,35 @@
 }
 
+
+/**
+ * The PE module interpreter method table.
+ */
+KLDRMODOPS g_kLdrModPEOps =
+{
+    "PE",
+    NULL,
+    kldrModPECreate,
+    kldrModPEDestroy,
+    kldrModPEQuerySymbol,
+    kldrModPEEnumSymbols,
+    kldrModPEGetImport,
+    kldrModPENumberOfImports,
+    NULL /* can execute one is optional */,
+    kldrModPEGetStackInfo,
+    kldrModPEQueryMainEntrypoint,
+    kldrModPEEnumDbgInfo,
+    kldrModPEHasDbgInfo,
+    kldrModPEMap,
+    kldrModPEUnmap,
+    kldrModPEAllocTLS,
+    kldrModPEFreeTLS,
+    kldrModPEReload,
+    kldrModPEFixupMapping,
+    kldrModPECallInit,
+    kldrModPECallTerm,
+    kldrModPECallThread,
+    kldrModPESize,
+    kldrModPEGetBits,
+    kldrModPERelocateBits,
+    42 /* the end */
+};
Index: /trunk/kLdr/kLdrRdrFile.c
===================================================================
--- /trunk/kLdr/kLdrRdrFile.c	(revision 2857)
+++ /trunk/kLdr/kLdrRdrFile.c	(revision 2858)
@@ -232,5 +232,5 @@
 
         SetLastError(0);
-        offLow = SetFilePointer(pRdrFile->File, 0, &offHigh, FILE_BEGIN);
+        offLow = SetFilePointer(pRdrFile->File, 0, &offHigh, FILE_CURRENT);
         rc = GetLastError();
         if (rc)
@@ -325,5 +325,7 @@
 #ifdef __OS2__
         ULONG ulNew;
-        APIRET rc = DosSetFilePtr(pRdrFile->File, off, FILE_BEGIN, &ulNew);
+        APIRET rc;
+
+        rc = DosSetFilePtr(pRdrFile->File, off, FILE_BEGIN, &ulNew);
         if (rc)
         {
@@ -333,8 +335,11 @@
 
 #elif defined(__WIN__)
-        LONG offHigh = (LONG)(off >> 32);
-        LONG offLow = SetFilePointer(pRdrFile->File, (LONG)off, &offHigh, FILE_BEGIN);
+        LONG offHigh;
+        LONG offLow;
+
+        offHigh = sizeof(off_t) == 4 ? 0 : (off >> 32);
+        offLow = SetFilePointer(pRdrFile->File, (LONG)off, &offHigh, FILE_BEGIN);
         if (    offLow != (LONG)off
-            &&  offHigh != (LONG)(off >> 32))
+            ||  offHigh != (LONG)(sizeof(off_t) == 4 ? 0 : (off >> 32)))
         {
             int rc = GetLastError();
@@ -405,4 +410,5 @@
 
 #elif defined(__WIN__)
+    rc = 0;
     if (!CloseHandle(pRdrFile->File))
         rc = GetLastError();
@@ -433,9 +439,10 @@
      */
 #ifdef __OS2__
-    ULONG ulAction = 0;
-    FILESTATUS3 Info;
-    APIRET rc;
-    HFILE File = 0;
-    off_t cb;
+    ULONG           ulAction = 0;
+    FILESTATUS3     Info;
+    APIRET          rc;
+    HFILE           File = 0;
+    off_t           cb;
+    char            szFilename[CCHMAXPATH];
 
     if ((uintptr_t)pszFilename >= 0x20000000)
@@ -451,4 +458,11 @@
     if (rc)
         return rc;
+
+    rc = DosQueryPathInfo(pszFilename, FIL_QUERYFULLNAME, szFilename, sizeof(szFilename));
+    if (rc)
+    {
+        DosClose(File);
+        return rc;
+    }
 
     rc = DosQueryFileInfo(File, FIL_STANDARD, &Info, sizeof(Info));
@@ -467,4 +481,5 @@
     HANDLE              File;
     off_t               cb;
+    char                szFilename[MAX_PATH];
 
     SecAttr.bInheritHandle = FALSE;
@@ -475,4 +490,11 @@
         return GetLastError();
 
+    if (!GetFullPathName(pszFilename, sizeof(szFilename), szFilename, NULL))
+    {
+        rc = GetLastError();
+        CloseHandle(File);
+        return rc;
+    }
+
     SetLastError(0);
     Low = GetFileSize(File, &High);
@@ -483,5 +505,8 @@
         return rc;
     }
-    cb = ((off_t)High << 32) | Low;
+    if (sizeof(off_t) == 4)
+        cb = High ? 0x7fffffff : Low;
+    else
+        cb = ((off_t)High << 32) | Low;
 
 #else
@@ -493,5 +518,5 @@
      * Allocate the reader instance.
      */
-    cchFilename = kLdrHlpStrLen(pszFilename);
+    cchFilename = kLdrHlpStrLen(szFilename);
     pRdrFile = (PKLDRRDRFILE)kldrHlpAlloc(sizeof(*pRdrFile) + cchFilename);
     if (!pRdrFile)
@@ -513,8 +538,10 @@
      * Initialize it and return successfully.
      */
+    pRdrFile->Core.u32Magic = KLDRRDR_MAGIC;
     pRdrFile->Core.pOps = &g_kLdrRdrFileOps;
     pRdrFile->File = File;
+    pRdrFile->cb = cb;
     pRdrFile->off = 0;
-    kLdrHlpMemCopy(&pRdrFile->szFilename[0], pszFilename, cchFilename + 1);
+    kLdrHlpMemCopy(&pRdrFile->szFilename[0], szFilename, cchFilename + 1);
 
     *ppRdr = &pRdrFile->Core;
