Index: trunk/include/helpers/apps.h
===================================================================
--- trunk/include/helpers/apps.h	(revision 122)
+++ trunk/include/helpers/apps.h	(revision 123)
@@ -76,4 +76,6 @@
                     // V0.9.16 (2001-10-06)
 
+        #define PROG_WIN32              990     // added V0.9.16 (2001-12-08) [umoeller]
+
         APIRET appQueryAppType(const char *pcszExecutable,
                                 PULONG pulDosAppType,
Index: trunk/include/helpers/dosh.h
===================================================================
--- trunk/include/helpers/dosh.h	(revision 122)
+++ trunk/include/helpers/dosh.h	(revision 123)
@@ -57,4 +57,9 @@
     PVOID doshMalloc(ULONG cb,
                      APIRET *parc);
+
+    APIRET doshAllocArray(ULONG c,
+                          ULONG cbArrayItem,
+                          PBYTE *ppv,
+                          PULONG pcbAllocated);
 
     PVOID doshAllocSharedMem(ULONG ulSize,
@@ -353,5 +358,5 @@
                       LONG lOffset,
                       ULONG ulMethod,
-                      ULONG cb,
+                      PULONG pcb,
                       PBYTE pbData);
 
@@ -464,4 +469,6 @@
      ********************************************************************/
 
+    #pragma pack(1)
+
     /*
      *@@ DOSEXEHEADER:
@@ -473,5 +480,4 @@
      */
 
-    #pragma pack(1)
     typedef struct _DOSEXEHEADER
     {
@@ -532,4 +538,22 @@
         ULONG     ulChecksum;           // 08: MS: reserved, OS/2: checksum
         USHORT    usFlags;              // 0c: flags
+                           /*
+                              #define NENOTP          0x8000          // Not a process == library
+                              #define NENOTMPSAFE     0x4000          // Process is not multi-processor safe
+                              #define NEIERR          0x2000          // Errors in image
+                              #define NEBOUND         0x0800          // Bound Family/API
+                              #define NEAPPTYP        0x0700          // Application type mask
+                              #define NENOTWINCOMPAT  0x0100          // Not compatible with P.M. Windowing
+                              #define NEWINCOMPAT     0x0200          // Compatible with P.M. Windowing
+                              #define NEWINAPI        0x0300          // Uses P.M. Windowing API
+                              #define NEFLTP          0x0080          // Floating-point instructions
+                              #define NEI386          0x0040          // 386 instructions
+                              #define NEI286          0x0020          // 286 instructions
+                              #define NEI086          0x0010          // 8086 instructions
+                              #define NEPROT          0x0008          // Runs in protected mode only
+                              #define NEPPLI          0x0004          // Per-Process Library Initialization
+                              #define NEINST          0x0002          // Instance data
+                              #define NESOLO          0x0001          // Solo data (single data)
+                           */
         USHORT    usAutoDataSegNo;      // 0e: auto-data seg no.
         USHORT    usInitlHeapSize;      // 10: initl. heap size
@@ -581,4 +605,16 @@
         ULONG     ulModuleVersion;      // 0c: module version
         ULONG     ulFlags;              // 10: module flags
+                          /* #define E32NOTP          0x8000L        // Library Module - used as NENOTP
+                             #define E32NOLOAD        0x2000L        // Module not Loadable
+                             #define E32PMAPI         0x0300L        // Uses PM Windowing API
+                             #define E32PMW           0x0200L        // Compatible with PM Windowing
+                             #define E32NOPMW         0x0100L        // Incompatible with PM Windowing
+                             #define E32NOEXTFIX      0x0020L        // NO External Fixups in .EXE
+                             #define E32NOINTFIX      0x0010L        // NO Internal Fixups in .EXE
+                             #define E32SYSDLL        0x0008L        // System DLL, Internal Fixups discarded
+                             #define E32LIBINIT       0x0004L        // Per-Process Library Initialization
+                             #define E32LIBTERM       0x40000000L    // Per-Process Library Termination
+                             #define E32APPMASK       0x0300L        // Application Type Mask
+                          */
         ULONG     ulPageCount;          // 14: no. of pages in module
         ULONG     ulEIPRelObj;          // 18: object to which EIP is relative
@@ -680,43 +716,69 @@
     } PEHEADER, *PPEHEADER;
 
+    // additional LX structures
+
+    /*
+     *@@ RESOURCETABLEENTRY:
+     *     LX resource table entry.
+     *
+     *@@added V0.9.16 (2001-12-08) [umoeller]
+     */
+
+    typedef struct _RESOURCETABLEENTRY     // rsrc32
+    {
+        unsigned short  type;   // Resource type
+        unsigned short  name;   // Resource name
+        unsigned long   cb;     // Resource size
+        unsigned short  obj;    // Object number
+        unsigned long   offset; // Offset within object
+    } RESOURCETABLEENTRY;
+
+    /*
+     *@@ OBJECTTABLEENTRY:
+     *     LX object table entry.
+     *
+     *@@added V0.9.16 (2001-12-08) [umoeller]
+     */
+
+    typedef struct _OBJECTTABLEENTRY       // o32_obj
+    {
+        unsigned long   o32_size;     // Object virtual size
+        unsigned long   o32_base;     // Object base virtual address
+        unsigned long   o32_flags;    // Attribute flags
+        unsigned long   o32_pagemap;  // Object page map index
+        unsigned long   o32_mapsize;  // Number of entries in object page map
+        unsigned long   o32_reserved; // Reserved
+    } OBJECTTABLEENTRY;
+
+    /*
+     *@@ OBJECTPAGETABLEENTRY:
+     *     LX object _page_ table entry, sometimes
+     *     referred to as map entry.
+     *
+     *@@added V0.9.16 (2001-12-08) [umoeller]
+     */
+
+    typedef struct _OBJECTPAGETABLEENTRY   // o32_map
+    {
+        unsigned long   o32_pagedataoffset;     // file offset of page
+        unsigned short  o32_pagesize;           // # of real bytes of page data
+        unsigned short  o32_pageflags;          // Per-Page attributes
+    } OBJECTPAGETABLEENTRY;
+
+    /*
+     *@@ LXITER:
+     *      iteration Record format for 'EXEPACK'ed pages.
+     *
+     *@@added V0.9.16 (2001-12-08) [umoeller]
+     */
+
+    typedef struct _LXITER
+    {
+        unsigned short LX_nIter;            // number of iterations
+        unsigned short LX_nBytes;           // number of bytes
+        unsigned char  LX_Iterdata;         // iterated data byte(s)
+    } LXITER, *PLXITER;
+
     #pragma pack()
-
-    /*
-     *@@ FSYSMODULE:
-     *
-     *@@added V0.9.9 (2001-03-11) [lafaix]
-     */
-
-    typedef struct _FSYSMODULE
-    {
-        CHAR achModuleName[256];
-    } FSYSMODULE, *PFSYSMODULE;
-
-    /*
-     *@@ FSYSFUNCTION:
-     *
-     *@@added V0.9.9 (2001-03-11) [lafaix]
-     */
-
-    typedef struct _FSYSFUNCTION
-    {
-        ULONG ulOrdinal;
-        ULONG ulType;
-        CHAR achFunctionName[256];
-    } FSYSFUNCTION, *PFSYSFUNCTION;
-
-    /*
-     *@@ FSYSRESOURCE:
-     *
-     *@@added V0.9.7 (2000-12-18) [lafaix]
-     */
-
-    typedef struct _FSYSRESOURCE
-    {
-        ULONG ulID;                     // resource ID
-        ULONG ulType;                   // resource type
-        ULONG ulSize;                   // resource size in bytes
-        ULONG ulFlag;                   // resource flags
-    } FSYSRESOURCE, *PFSYSRESOURCE;
 
     // object/segment flags (in NE and LX)
@@ -822,4 +884,5 @@
                 // module info substring (if IBM BLDLEVEL format)
 
+#ifndef __STRIP_DOWN_EXECUTABLE__       // for mini stubs in warpin, to reduce code size
         // if pszInfo is extended DESCRIPTION field, the following
         // are set as well:
@@ -833,4 +896,11 @@
                             pszFixpak;
 
+        // the following fields are set after doshLoadLXMaps
+        BOOL                    fLXMapsLoaded;      // TRUE after doshLoadLXMaps
+        RESOURCETABLEENTRY      *pRsTbl;        // pLXHeader->ulResTblCnt
+        OBJECTTABLEENTRY        *pObjTbl;       // pLXHeader->ulObjCount
+        OBJECTPAGETABLEENTRY    *pObjPageTbl;   // pLXHeader->ulPageCount
+
+#endif
     } EXECUTABLE, *PEXECUTABLE;
 
@@ -838,7 +908,16 @@
                         PEXECUTABLE* ppExec);
 
-    APIRET doshExecClose(PEXECUTABLE pExec);
-
     APIRET doshExecQueryBldLevel(PEXECUTABLE pExec);
+
+    /*
+     *@@ FSYSMODULE:
+     *
+     *@@added V0.9.9 (2001-03-11) [lafaix]
+     */
+
+    typedef struct _FSYSMODULE
+    {
+        CHAR achModuleName[256];
+    } FSYSMODULE, *PFSYSMODULE;
 
     APIRET doshExecQueryImportedModules(PEXECUTABLE pExec,
@@ -848,4 +927,17 @@
     APIRET doshExecFreeImportedModules(PFSYSMODULE paModules);
 
+    /*
+     *@@ FSYSFUNCTION:
+     *
+     *@@added V0.9.9 (2001-03-11) [lafaix]
+     */
+
+    typedef struct _FSYSFUNCTION
+    {
+        ULONG ulOrdinal;
+        ULONG ulType;
+        CHAR achFunctionName[256];
+    } FSYSFUNCTION, *PFSYSFUNCTION;
+
     APIRET doshExecQueryExportedFunctions(PEXECUTABLE pExec,
                                           PFSYSFUNCTION *ppaFunctions,
@@ -854,4 +946,19 @@
     APIRET doshExecFreeExportedFunctions(PFSYSFUNCTION paFunctions);
 
+    /*
+     *@@ FSYSRESOURCE:
+     *
+     *@@added V0.9.7 (2000-12-18) [lafaix]
+     */
+
+    typedef struct _FSYSRESOURCE
+    {
+        ULONG ulID;                     // resource ID
+        ULONG ulType;                   // resource type
+        ULONG ulSize;                   // resource size in bytes
+        ULONG ulFlag;                   // resource flags
+
+    } FSYSRESOURCE, *PFSYSRESOURCE;
+
     APIRET doshExecQueryResources(PEXECUTABLE pExec,
                                   PFSYSRESOURCE *ppaResources,
@@ -859,4 +966,10 @@
 
     APIRET doshExecFreeResources(PFSYSRESOURCE paResources);
+
+    APIRET doshLoadLXMaps(PEXECUTABLE pExec);
+
+    VOID doshFreeLXMaps(PEXECUTABLE pExec);
+
+    APIRET doshExecClose(PEXECUTABLE *ppExec);
 
     APIRET doshSearchPath(PCSZ pcszPath,
Index: trunk/include/helpers/memdebug.h
===================================================================
--- trunk/include/helpers/memdebug.h	(revision 122)
+++ trunk/include/helpers/memdebug.h	(revision 123)
@@ -80,8 +80,17 @@
         typedef struct _HEAPITEM
         {
-            struct _HEAPITEM    *pNext;     // next item in linked list or NULL if last
+            // struct _HEAPITEM    *pNext;     // next item in linked list or NULL if last
 
-            void                *pAfterMagic; // memory pointer returned by memdMalloc;
-                                            // this points to after the magic string
+            TREE                Tree;           // tree node for tree.* functions;
+                                                // ulKey has the pointer that is returned
+                                                // by memdMalloc and points to after the
+                                                // magic string (in the buffer that was
+                                                // really allocated). Using this as the
+                                                // tree sort key allows us to do fast
+                                                // searches in memdFree.
+
+            // void                *pAfterMagic; // memory pointer returned by memdMalloc;
+                                              // this points to after the magic string
+
             unsigned long       ulSize;     // requested size (without magic head and tail)
 
@@ -97,5 +106,6 @@
         } HEAPITEM, *PHEAPITEM;
 
-        extern PHEAPITEM    G_pHeapItemsRoot;
+        extern TREE         *G_pHeapItemsRoot;
+        extern LONG         G_cHeapItems;
         extern ULONG        G_ulItemsReleased;
         extern ULONG        G_ulBytesReleased;
Index: trunk/include/helpers/standards.h
===================================================================
--- trunk/include/helpers/standards.h	(revision 122)
+++ trunk/include/helpers/standards.h	(revision 123)
@@ -63,4 +63,25 @@
 
     /*
+     *@@ FREE:
+     *      wrapper around the typical free() sequence.
+     *
+     *      Usage:
+     *
+     +          FREE(p)
+     *
+     *      This expands to:
+     *
+     +          if (p)
+     +          {
+     +              free(p);
+     +              p = NULL;
+     +          }
+     *
+     *@@added V0.9.16 (2001-12-08) [umoeller]
+     */
+
+    #define FREE(ptr) if ((ptr)) { free(ptr); ptr = NULL; }
+
+    /*
      *@@ ARRAYITEMCOUNT:
      *      helpful macro to count the count of items
Index: trunk/include/helpers/stringh.h
===================================================================
--- trunk/include/helpers/stringh.h	(revision 122)
+++ trunk/include/helpers/stringh.h	(revision 123)
@@ -32,5 +32,15 @@
     #define STRINGH_HEADER_INCLUDED
 
-    VOID XWPENTRY strhStore(PSZ *ppszTarget, PCSZ pcszSource, PULONG pulLength);
+    #if defined(__DEBUG_MALLOC_ENABLED__) && !defined(DONT_REPLACE_STRINGH_MALLOC) // setup.h, helpers\memdebug.c
+        APIRET XWPENTRY strhStoreDebug(PSZ *ppszTarget,
+                                       PCSZ pcszSource,
+                                       PULONG pulLength,
+                                       const char *pcszSourceFile,
+                                       unsigned long ulLine,
+                                       const char *pcszFunction);
+        #define strhStore(a, b, c) strhStoreDebug((a), (b), (c), __FILE__, __LINE__, __FUNCTION__)
+    #else
+        APIRET XWPENTRY strhStore(PSZ *ppszTarget, PCSZ pcszSource, PULONG pulLength);
+    #endif
 
     PSZ XWPENTRY strhcpy(PSZ string1, const char *string2);
Index: trunk/include/helpers/threads.h
===================================================================
--- trunk/include/helpers/threads.h	(revision 122)
+++ trunk/include/helpers/threads.h	(revision 123)
@@ -60,5 +60,5 @@
         HAB     hab;            // for PM threads
         HMQ     hmq;            // for PM threads
-        BOOL    fExitComplete;
+        HEV     hevExitComplete;    // posted when thread exits V0.9.16 (2001-12-08) [umoeller]
 
         // data to be maintained by application
