Index: trunk/src/kernel32/heapshared.cpp
===================================================================
--- trunk/src/kernel32/heapshared.cpp	(revision 8895)
+++ trunk/src/kernel32/heapshared.cpp	(revision 8898)
@@ -1,3 +1,3 @@
-/* $Id: heapshared.cpp,v 1.9 2002-07-15 14:28:51 sandervl Exp $ */
+/* $Id: heapshared.cpp,v 1.10 2002-07-21 09:17:28 sandervl Exp $ */
 /*
  * Shared heap functions for OS/2
@@ -18,9 +18,15 @@
 #define INCL_DOSMEMMGR
 #include <os2wrap.h>
-#include <misc.h>
+#include <string.h>
+#include <dbglog.h>
 #include <heapshared.h>
+#include "initterm.h"
 
 #define DBG_LOCALLOG	DBG_heapshared
 #include "dbglocal.h"
+
+#define MAX_HEAPSIZE            (2048*1024)
+#define MAX_HEAPPAGES		(MAX_HEAPSIZE/PAGE_SIZE)
+#define INCR_HEAPSIZE		(16*1024)
 
 //Global DLL Data
@@ -32,4 +38,6 @@
 #pragma data_seg()
 
+static int     privateRefCount = 0;
+
 void * _LNK_CONV getmoreShared(Heap_t pHeap, size_t *size, int *clean);
 void _LNK_CONV releaseShared(Heap_t pHeap, void *block, size_t size);
@@ -37,19 +45,31 @@
 //******************************************************************************
 //******************************************************************************
-BOOL InitializeSharedHeap()
+BOOL SYSTEM InitializeSharedHeap()
 {
     APIRET rc;
+    ULONG  flAllocMem = 0, ulSysinfo;
+
+    //necessary until next WGSS update
+    if(++privateRefCount > 1) {
+        return TRUE;
+    }
+
+    rc = DosQuerySysInfo(QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &ulSysinfo, sizeof(ulSysinfo));
+    if (rc == 0 && ulSysinfo > 512)   //VirtualAddresslimit is in MB
+    {
+        flAllocMem = PAG_ANY;
+    }
 
     if(pSharedMem == NULL) {
-  	    rc = DosAllocSharedMem(&pSharedMem, NULL, MAX_HEAPSIZE, PAG_READ|PAG_WRITE|OBJ_GETTABLE);
+  	    rc = DosAllocSharedMem(&pSharedMem, NULL, MAX_HEAPSIZE, PAG_READ|PAG_WRITE|OBJ_GETTABLE|flAllocMem);
   	    if(rc != 0) {
     		dprintf(("InitializeSharedHeap: DosAllocSharedMem failed with %d", rc));
-		    return FALSE;
+            return FALSE;
 	    }
 	    rc = DosSetMem(pSharedMem, INCR_HEAPSIZE, PAG_READ|PAG_WRITE|PAG_COMMIT);
 	    if(rc != 0) {
     		DosFreeMem(pSharedMem);
-		    dprintf(("InitializeSharedHeap: DosSetMem failed with %d", rc));
-		    return FALSE;
+	        dprintf(("InitializeSharedHeap: DosSetMem failed with %d", rc));
+	        return FALSE;
 	    }
   	    sharedHeap = _ucreate(pSharedMem, INCR_HEAPSIZE, _BLOCK_CLEAN, _HEAP_REGULAR|_HEAP_SHARED,
@@ -58,6 +78,6 @@
   	    if(sharedHeap == NULL) {
     		DosFreeMem(pSharedMem);
-		    dprintf(("InitializeSharedHeap: _ucreate failed!"));
-		    return FALSE;
+	        dprintf(("InitializeSharedHeap: _ucreate failed!"));
+	        return FALSE;
 	    }
   	    dprintf(("KERNEL32: First InitializeSharedHeap %x %x", pSharedMem, sharedHeap));
@@ -82,7 +102,10 @@
 //******************************************************************************
 //******************************************************************************
-void DestroySharedHeap()
+void SYSTEM DestroySharedHeap()
 {
     dprintf(("KERNEL32: DestroySharedHeap %d", refCount));
+    if(--privateRefCount > 0) {
+        return;
+    }
     if(--refCount == 0) {
   	    if(sharedHeap) {
@@ -132,5 +155,6 @@
     {
     	int nrpagesfree = GetPageRangeFree(i);
-    	if(nrpagesfree >= *size/PAGE_SIZE) {
+    	if(nrpagesfree >= *size/PAGE_SIZE) 
+        {
   		    newblock = (PVOID)((ULONG)pSharedMem + i*PAGE_SIZE);
   		    rc = DosSetMem(newblock, *size, PAG_READ|PAG_WRITE|PAG_COMMIT);
@@ -171,9 +195,20 @@
 //******************************************************************************
 //******************************************************************************
-DWORD  HeapGetSharedMemBase()
-{
-    dprintf(("KERNEL32: HeapGetSharedMemBase()\n"));
-    return (DWORD) pSharedMem;
-}
-//******************************************************************************
-//******************************************************************************
+void * SYSTEM _smalloc(int size)
+{
+    return _umalloc(sharedHeap, size);
+}
+//******************************************************************************
+//******************************************************************************
+void * SYSTEM _smallocfill(int size, int filler)
+{
+    void *chunk;
+
+    chunk =  _umalloc(sharedHeap, size);
+    if(chunk) {
+        memset(chunk, 0, size);
+    }
+    return chunk;
+}
+//******************************************************************************
+//******************************************************************************
Index: trunk/src/kernel32/initkernel32.cpp
===================================================================
--- trunk/src/kernel32/initkernel32.cpp	(revision 8895)
+++ trunk/src/kernel32/initkernel32.cpp	(revision 8898)
@@ -1,3 +1,3 @@
-/* $Id: initkernel32.cpp,v 1.21 2002-07-15 14:40:16 sandervl Exp $
+/* $Id: initkernel32.cpp,v 1.22 2002-07-21 09:17:28 sandervl Exp $
  *
  * KERNEL32 DLL entry point
@@ -134,29 +134,7 @@
             OpenPrivateLogFiles();
 
-            if (InitializeSharedHeap() == FALSE)
-                return 0UL;
-
-            if (InitializeCodeHeap() == FALSE)
-                return 0UL;
-
             //SvL: Do it here instead of during the exe object creation
             //(std handles can be used in win32 dll initialization routines
             HMInitialize();             /* store standard handles within HandleManager */
-
-            InitializeMemMaps();
-
-            PROFILE_LoadOdinIni();
-            dllHandle = RegisterLxDll(hModule, 0, (PVOID)&kernel32_PEResTab);
-            if (dllHandle == 0)
-                return 0UL;
-
-            //SvL: Kernel32 is a special case; pe.exe loads it, so increase
-            //     the reference count here
-            Win32DllBase *module = Win32DllBase::findModule(dllHandle);
-            if (module)
-            {
-                module->AddRef();
-                module->DisableUnload();
-            }
 
             /* knut: check for high memory support */
@@ -174,4 +152,26 @@
             else
                 flAllocMem = 0;        // no high memory support
+
+            if (InitializeSharedHeap() == FALSE)
+                return 0UL;
+
+            if (InitializeCodeHeap() == FALSE)
+                return 0UL;
+
+            InitializeMemMaps();
+
+            PROFILE_LoadOdinIni();
+            dllHandle = RegisterLxDll(hModule, 0, (PVOID)&kernel32_PEResTab);
+            if (dllHandle == 0)
+                return 0UL;
+
+            //SvL: Kernel32 is a special case; pe.exe loads it, so increase
+            //     the reference count here
+            Win32DllBase *module = Win32DllBase::findModule(dllHandle);
+            if (module)
+            {
+                module->AddRef();
+                module->DisableUnload();
+            }
 
             OSLibDosSetInitialMaxFileHandles(ODIN_DEFAULT_MAX_FILEHANDLES);
