Index: trunk/src/kernel32/heapshared.cpp
===================================================================
--- trunk/src/kernel32/heapshared.cpp	(revision 1432)
+++ trunk/src/kernel32/heapshared.cpp	(revision 1432)
@@ -0,0 +1,177 @@
+/* $Id: heapshared.cpp,v 1.1 1999-10-24 22:53:24 sandervl Exp $ */
+/*
+ * Shared heap functions for OS/2
+ *
+ * Initially commit 16 kb, add more when required
+ *
+ * NOTE: Hardcoded limit of 256 KB per process (increase when required)
+ *
+ * TODO: Not process/thread safe (initializing/destroying heap)
+ * 
+ * ASSUMPTION: Rtl library takes care of protection of heap increase/decrease
+ *             (from multiple threads/processes)
+ *
+ * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
+ *
+ */
+#define INCL_BASE
+#define INCL_DOSMEMMGR
+#include <os2wrap.h>
+#include <misc.h>
+#include "heapshared.h"
+
+//Global DLL Data
+#pragma data_seg(_GLOBALDATA)
+       Heap_t  sharedHeap = 0;
+static PVOID   pSharedMem = NULL;
+static BYTE    pageBitmap[MAX_HEAPPAGES] = {0};
+static ULONG   refCount = 0;
+#pragma data_seg()
+
+void * _LNK_CONV getmoreShared(Heap_t pHeap, size_t *size, int *clean);
+void _LNK_CONV releaseShared(Heap_t pHeap, void *block, size_t size);
+
+//******************************************************************************
+//******************************************************************************
+BOOL InitializeSharedHeap()
+{
+ APIRET rc;
+
+  if(pSharedMem == NULL) {
+  	dprintf(("KERNEL32: InitializeSharedHeap"));
+  	rc = DosAllocSharedMem(&pSharedMem, NULL, MAX_HEAPSIZE, PAG_READ|PAG_WRITE|OBJ_GETTABLE);
+  	if(rc != 0) {
+		dprintf(("InitializeSharedHeap: DosAllocSharedMem failed with %d", rc));
+		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;
+	}
+  	sharedHeap = _ucreate(pSharedMem, INCR_HEAPSIZE, _BLOCK_CLEAN,
+        	              _HEAP_REGULAR|_HEAP_SHARED,
+                	      getmoreShared, releaseShared);
+
+  	if(sharedHeap == NULL) {
+		DosFreeMem(pSharedMem);
+		dprintf(("InitializeSharedHeap: _ucreate failed!"));
+		return FALSE;
+	}
+	for(int i=0;i<INCR_HEAPSIZE/PAGE_SIZE;i++) {
+	  	pageBitmap[i] = 1; //mark as committed
+	}
+  }
+  else {
+	if(DosGetSharedMem(pSharedMem, PAG_READ|PAG_WRITE) != 0) {
+		dprintf(("InitializeSharedHeap: DosGetSharedMem failed!"));
+		return FALSE;
+	}
+  }
+  refCount++;
+  return TRUE;
+}
+//******************************************************************************
+//******************************************************************************
+void DestroySharedHeap()
+{
+  dprintf(("KERNEL32: DestroySharedHeap %d", refCount));
+  if(--refCount == 0) {
+  	if(sharedHeap) {
+		_uclose(sharedHeap);
+		_udestroy(sharedHeap, _FORCE);
+		sharedHeap = NULL;
+	}
+	if(pSharedMem) {
+		DosFreeMem(pSharedMem);
+		pSharedMem = NULL;
+	}
+  }
+}
+//******************************************************************************
+//******************************************************************************
+void  *_smalloc(size_t size)
+{
+  return _umalloc(sharedHeap, size);
+}
+//******************************************************************************
+//******************************************************************************
+ULONG GetPageRangeFree(ULONG pageoffset)
+{
+  dprintf(("KERNEL32: GetPageRangeFree(%08xh)\n",
+           pageoffset));
+
+  for(int i=pageoffset;i<MAX_HEAPPAGES;i++) {
+	if(pageBitmap[i] == 1) {
+		break;
+	}
+  }
+  return i-pageoffset;
+}
+//******************************************************************************
+//******************************************************************************
+void * _LNK_CONV getmoreShared(Heap_t pHeap, size_t *size, int *clean)
+{
+ APIRET rc;
+ ULONG newsize;
+ PVOID newblock;
+
+ dprintf(("KERNEL32: getmoreShared(%08xh, %08xh, %08xh)\n",
+          pHeap,
+          *size,
+          *clean));
+
+  /* round the size up to a multiple of 4K */
+  *size = (*size / 4096) * 4096 + 4096;
+  *size = max(*size, INCR_HEAPSIZE);
+
+  for(int i=0;i<MAX_HEAPPAGES;i++)
+  {
+	int nrpagesfree = GetPageRangeFree(i);
+	if(nrpagesfree >= *size/PAGE_SIZE) {
+  		newblock = (PVOID)((ULONG)pSharedMem + i*PAGE_SIZE);
+  		rc = DosSetMem(newblock, *size, PAG_READ|PAG_WRITE|PAG_COMMIT);
+  		if(rc != 0) {
+			dprintf(("getmoreShared: DosSetMem failed with %d", rc));
+			return NULL;
+  		}
+  		for(int j=0;j < *size/PAGE_SIZE; j++)
+                {
+  			pageBitmap[i+j] = 1; //mark as committed
+  		}
+
+		*clean = _BLOCK_CLEAN;
+		dprintf(("KERNEL32: getmoreShared %x %d", newblock, *size));
+		return newblock;
+	}
+	if(nrpagesfree)
+		i += nrpagesfree-1;
+  }
+  dprintf(("KERNEL32: getmoreShared NOTHING LEFT (%d)", *size));
+  return NULL;
+}
+//******************************************************************************
+//******************************************************************************
+void _LNK_CONV releaseShared(Heap_t pHeap, void *block, size_t size)
+{
+ ULONG pagenr;
+
+  dprintf(("KERNEL32: releaseShared %x %d", block, size));
+  DosSetMem(block, size, PAG_READ|PAG_WRITE|PAG_DECOMMIT);
+
+  pagenr  = (ULONG)block - (ULONG)pSharedMem;
+  pagenr /= PAGE_SIZE;
+  for(int i=pagenr;i<pagenr+size/PAGE_SIZE;i++) {
+  	pageBitmap[i] = 0; //mark as decommitted
+  }
+}
+//******************************************************************************
+//******************************************************************************
+DWORD  HeapGetSharedMemBase()
+{
+  dprintf(("KERNEL32: HeapGetSharedMemBase()\n"));
+  return (DWORD) pSharedMem;
+}
+//******************************************************************************
+//******************************************************************************
Index: trunk/src/kernel32/heapshared.h
===================================================================
--- trunk/src/kernel32/heapshared.h	(revision 1432)
+++ trunk/src/kernel32/heapshared.h	(revision 1432)
@@ -0,0 +1,28 @@
+/* $Id: heapshared.h,v 1.1 1999-10-24 22:53:25 sandervl Exp $ */
+/*
+ * Shared heap functions for OS/2
+ *
+ * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
+ *
+ */
+#ifndef __HEAPSHARED_H__
+#define __HEAPSHARED_H__
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <umalloc.h>
+
+#define PAGE_SIZE		4096
+#define MAX_HEAPSIZE            (256*1024)
+#define MAX_HEAPPAGES		(MAX_HEAPSIZE/PAGE_SIZE)
+#define INCR_HEAPSIZE		(16*1024)
+
+extern Heap_t sharedHeap;
+
+BOOL   InitializeSharedHeap();
+void   DestroySharedHeap();
+DWORD  HeapGetSharedMemBase();
+
+void  *_smalloc(size_t size);
+
+#endif
Index: trunk/src/kernel32/hmmmap.cpp
===================================================================
--- trunk/src/kernel32/hmmmap.cpp	(revision 1431)
+++ trunk/src/kernel32/hmmmap.cpp	(revision 1432)
@@ -1,3 +1,3 @@
-/* $Id: hmmmap.cpp,v 1.6 1999-08-27 16:51:00 sandervl Exp $ */
+/* $Id: hmmmap.cpp,v 1.7 1999-10-24 22:51:21 sandervl Exp $ */
 
 /*
@@ -31,4 +31,5 @@
 #include "HMMMap.h"
 #include "mmap.h"
+#include "heapshared.h"
 
 /*****************************************************************************
@@ -64,4 +65,5 @@
 
 	dprintf(("CreateFileMappingA: invalid parameter (combination)!"));
+        dprintf(("Parameters: %x %x %x %x %s", hFile, protect, size_high, size_low, name));
 	return ERROR_INVALID_PARAMETER;
   }
Index: trunk/src/kernel32/initterm.cpp
===================================================================
--- trunk/src/kernel32/initterm.cpp	(revision 1431)
+++ trunk/src/kernel32/initterm.cpp	(revision 1432)
@@ -1,3 +1,3 @@
-/* $Id: initterm.cpp,v 1.16 1999-10-23 12:34:46 sandervl Exp $ */
+/* $Id: initterm.cpp,v 1.17 1999-10-24 22:51:21 sandervl Exp $ */
 
 /*
@@ -40,4 +40,5 @@
 #include <odinlx.h>
 #include "oslibmisc.h"
+#include "heapshared.h"
 
 /*-------------------------------------------------------------------*/
@@ -101,4 +102,7 @@
             CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/
 
+            if(InitializeSharedHeap() == FALSE)
+                return 0UL;
+
             if(RegisterLxDll(hModule, 0, 0) == FALSE)
                 return 0UL;
Index: trunk/src/kernel32/makefile
===================================================================
--- trunk/src/kernel32/makefile	(revision 1431)
+++ trunk/src/kernel32/makefile	(revision 1432)
@@ -1,3 +1,3 @@
-# $Id: makefile,v 1.45 1999-10-23 12:34:47 sandervl Exp $
+# $Id: makefile,v 1.46 1999-10-24 22:51:21 sandervl Exp $
 
 #
@@ -23,5 +23,5 @@
 CONBUFFER.OBJ CONOUT.OBJ UNICODE.OBJ network.OBJ DEVIO.OBJ \
 profile.obj THREAD.OBJ virtual.obj THUNK.OBJ OBSOLETE.OBJ COMM.OBJ\
-MESSAGE.OBJ RESOURCE.OBJ EXCEPTIONS.OBJ \
+MESSAGE.OBJ RESOURCE.OBJ EXCEPTIONS.OBJ heapshared.obj \
 LFILE.OBJ NPIPE.OBJ oslibdos.obj oslibmisc.obj MISC.OBJ EXCEPTUTIL.OBJ \
 LANG.OBJ ICCIO.OBJ MAP.OBJ WIN32UTIL.OBJ heap.OBJ heapstring.obj \
@@ -100,5 +100,5 @@
 
 atom.obj: atom.cpp \
-    $(PDWIN32_INCLUDE)\unicode.h
+    $(PDWIN32_INCLUDE)\unicode.h 
 
 time.obj: time.cpp \
@@ -132,5 +132,5 @@
     os2heap.h
 
-initterm.OBJ: .\initterm.cpp initterm.h
+initterm.OBJ: .\initterm.cpp initterm.h  heapshared.h 
 
 thunk.OBJ: \
@@ -311,5 +311,5 @@
         .\hmopen32.h
 
-hmmmap.obj: hmmmap.cpp hmdevice.h hmopen32.h mmap.h
+hmmmap.obj: hmmmap.cpp hmdevice.h hmopen32.h mmap.h heapshared.h
 
 conprop.OBJ: \
@@ -324,5 +324,5 @@
 
 virtual.obj:   virtual.cpp $(PDWIN32_INCLUDE)\win\virtual.h $(PDWIN32_INCLUDE)\handlemanager.h mmap.h
-mmap.obj:      mmap.cpp mmap.h $(PDWIN32_INCLUDE)\vmutex.h oslibdos.h
+mmap.obj:      mmap.cpp mmap.h $(PDWIN32_INCLUDE)\vmutex.h oslibdos.h heapshared.h
 
 pefile.OBJ:    pefile.cpp $(PDWIN32_INCLUDE)\pefile.h $(PDWIN32_INCLUDE)\winres.h
@@ -362,4 +362,7 @@
 toolhelp.obj: toolhelp.cpp
 
+heapshared.obj: heapshared.cpp heapshared.h
+
+
 clean:
         $(RM) *.OBJ *.LIB *.dll *.lrf *.res *.map *.pch
Index: trunk/src/kernel32/mmap.cpp
===================================================================
--- trunk/src/kernel32/mmap.cpp	(revision 1431)
+++ trunk/src/kernel32/mmap.cpp	(revision 1432)
@@ -1,3 +1,3 @@
-/* $Id: mmap.cpp,v 1.18 1999-09-01 00:03:51 phaller Exp $ */
+/* $Id: mmap.cpp,v 1.19 1999-10-24 22:51:21 sandervl Exp $ */
 
 /*
@@ -30,6 +30,11 @@
 #include "oslibdos.h"
 
-VMutex globalmapMutex;
-VMutex globalviewMutex;
+//Global DLL Data
+#pragma data_seg(_GLOBALDATA)
+Win32MemMapView *Win32MemMapView::mapviews = NULL;
+Win32MemMap     *Win32MemMap::memmaps = NULL;
+VMutex           globalmapMutex(VMUTEX_SHARED);
+VMutex           globalviewMutex(VMUTEX_SHARED);
+#pragma data_seg()
 
 //******************************************************************************
@@ -48,7 +53,8 @@
   mSize      = size;
   mProtFlags = fdwProtect;
+  mProcessId  = GetCurrentProcess();
 
   if(lpszName) {
-	lpszMapName = (char *)malloc(strlen(lpszName)+1);
+	lpszMapName = (char *)_smalloc(strlen(lpszName)+1);
 	strcpy(lpszMapName, lpszName);
   }
@@ -62,5 +68,5 @@
   if(hMemFile != -1)
   {
-     	if(DuplicateHandle(GetCurrentProcess(), hMemFile, GetCurrentProcess(),
+     	if(DuplicateHandle(mProcessId, hMemFile, GetCurrentProcess(),
                            &hMemFile, 0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE)
      	{
@@ -87,7 +93,6 @@
 Win32MemMap::~Win32MemMap()
 {
-  for(int i=0;i<nrMappings;i++) {
-	Win32MemMapView::deleteView(this); //delete all views of our memory mapped file
-  }
+  Win32MemMapView::deleteViews(this); //delete all views of our memory mapped file
+
   mapMutex.enter();
   if(lpszMapName) {
@@ -95,5 +100,9 @@
   }
   if(pMapping) {
-	VirtualFree(pMapping, mSize, MEM_RELEASE);
+	if(lpszMapName) {
+		OSLibDosFreeMem(pMapping);
+	}
+	else	VirtualFree(pMapping, mSize, MEM_RELEASE);
+
 	pMapping = NULL;
   }
@@ -206,5 +215,4 @@
 }
 //******************************************************************************
-//todo: unalias memory
 //******************************************************************************
 BOOL Win32MemMap::unmapViewOfFile(Win32MemMapView *view)
@@ -231,4 +239,6 @@
 LPVOID Win32MemMap::mapViewOfFile(ULONG size, ULONG offset, ULONG fdwAccess)
 {
+ DWORD processId = GetCurrentProcess();
+
   mapMutex.enter();
   ULONG memFlags = (mProtFlags & (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY));
@@ -270,5 +280,10 @@
         //     when allocating memory with the PAG_ANY bit set. (without this
         //     flag it will also crash)
-  	pMapping = VirtualAlloc(0, mSize, fAlloc, PAGE_READWRITE);
+	if(lpszMapName) {
+		pMapping = VirtualAllocShared(mSize, fAlloc, PAGE_READWRITE, lpszMapName);
+	}
+	else {
+  		pMapping = VirtualAlloc(0, mSize, fAlloc, PAGE_READWRITE);
+	}
   	if(pMapping == NULL) {
 		dprintf(("Win32MemMap::mapFileView: VirtualAlloc %x %x %x failed!", mSize, fAlloc, memFlags));
@@ -375,4 +390,7 @@
 Win32MemMap *Win32MemMap::findMap(LPSTR lpszName)
 {
+  if(lpszName == NULL)
+	return NULL;
+
   globalmapMutex.enter();
   Win32MemMap *map = memmaps;
@@ -414,12 +432,20 @@
 void Win32MemMap::deleteAll()
 {
-  while(memmaps) {
-	CloseHandle(memmaps->hMemMap);
-  }
-}
-//******************************************************************************
-//******************************************************************************
-Win32MemMap *Win32MemMap::memmaps = NULL;
-
+ Win32MemMap *map = memmaps, *nextmap;
+ DWORD processId = GetCurrentProcess();
+
+  //delete all maps created by this process
+  while(map) {
+	nextmap = map->next;
+	if(map->getProcessId() == processId) {
+		CloseHandle(memmaps->hMemMap);
+	}
+	else {
+  		//delete all views created by this process for this map
+  		Win32MemMapView::deleteViews(map); 
+	}
+	map = nextmap;
+  }
+}
 //******************************************************************************
 //******************************************************************************
@@ -435,4 +461,5 @@
   mSize    = size;
   mOffset  = offset;
+  mProcessId = GetCurrentProcess();
 
   switch(fdwAccess) {
@@ -447,4 +474,14 @@
 	break;
   }
+  if(map->getMemName() != NULL) {
+	//shared memory map, so map it into our address space
+	if(OSLibDosGetNamedSharedMem((LPVOID *)&viewaddr, map->getMemName()) != OSLIB_NOERROR) {
+		dprintf(("new OSLibDosGetNamedSharedMem FAILED"));
+		SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+		errorState = 1;
+	  	return;
+	}
+  }
+  
   if(OSLibDosAliasMem(viewaddr, size, &pMapView, accessAttr) != OSLIB_NOERROR) {
 	dprintf(("new OSLibDosAliasMem FAILED"));
@@ -506,18 +543,21 @@
 //******************************************************************************
 //******************************************************************************
-void Win32MemMapView::deleteView(Win32MemMap *map)
-{
+void Win32MemMapView::deleteViews(Win32MemMap *map)
+{
+  DWORD processId = GetCurrentProcess();
+
   globalviewMutex.enter();
-  Win32MemMapView *view = mapviews;
+  Win32MemMapView *view = mapviews, *nextview;
 
   if(view != NULL) {
   	while(view) {
-		if(view->getParentMap() == map)
+		nextview = view->next;
+		if(view->getParentMap() == map && view->getProcessId() == processId)
 		{
 			globalviewMutex.leave();
 			delete view;
-			return;
-		}
-		view = view->next;
+			globalviewMutex.enter();
+		}
+		view = nextview;
 	}
   }
@@ -573,4 +613,3 @@
 //******************************************************************************
 //******************************************************************************
-Win32MemMapView *Win32MemMapView::mapviews = NULL;
-
+
Index: trunk/src/kernel32/mmap.h
===================================================================
--- trunk/src/kernel32/mmap.h	(revision 1431)
+++ trunk/src/kernel32/mmap.h	(revision 1432)
@@ -1,3 +1,3 @@
-/* $Id: mmap.h,v 1.9 1999-08-27 16:51:00 sandervl Exp $ */
+/* $Id: mmap.h,v 1.10 1999-10-24 22:51:22 sandervl Exp $ */
 
 /*
@@ -14,4 +14,5 @@
 
 #include <vmutex.h>
+#include "heapshared.h"
 
 #ifndef PAGE_SIZE
@@ -45,4 +46,5 @@
    DWORD  getProtFlags()                 { return mProtFlags; };
    LPVOID getMappingAddr()               { return pMapping; };
+   DWORD  getProcessId()                 { return mProcessId;};
 
    void   AddRef()                       { ++referenced; };
@@ -57,8 +59,29 @@
 static void deleteAll();
 
+#ifdef __DEBUG_ALLOC__
+	void *operator new(size_t size, const char *filename, size_t lineno)
+	{
+		return _umalloc(sharedHeap, size);
+	}
+	void operator delete(void *location, const char *filename, size_t lineno)
+	{
+		free(location);
+	}
+#else
+	void *operator new(size_t size)
+	{
+		return _umalloc(sharedHeap, size);
+	}
+	void operator delete(void *location)
+	{
+		free(location);
+	}
+#endif
+
 protected:
    HFILE  hMemMap, hMemFile;
    ULONG  mSize;
    ULONG  mProtFlags;
+   ULONG  mProcessId;
    ULONG  mMapAccess;
    LPSTR  lpszMapName;
@@ -92,11 +115,33 @@
 
 Win32MemMap *getParentMap()              { return mParentMap;};
+   DWORD  getProcessId()                 { return mProcessId;};
 
-static void             deleteView(Win32MemMap *map);
+static void             deleteViews(Win32MemMap *map);
 static Win32MemMap     *findMapByView(ULONG address, ULONG *offset, ULONG accessType, Win32MemMapView **pView=NULL);
 static Win32MemMapView *findView(LPVOID address);
 
+#ifdef __DEBUG_ALLOC__
+	void *operator new(size_t size, const char *filename, size_t lineno)
+	{
+		return _umalloc(sharedHeap, size);
+	}
+	void operator delete(void *location, const char *filename, size_t lineno)
+	{
+		free(location);
+	}
+#else
+	void *operator new(size_t size)
+	{
+		return _umalloc(sharedHeap, size);
+	}
+	void operator delete(void *location)
+	{
+		free(location);
+	}
+#endif
+
 protected:
    ULONG  mSize, errorState;
+   ULONG  mProcessId;
    ULONG  mfAccess, mOffset;
    void  *pMapView;
Index: trunk/src/kernel32/oslibdos.cpp
===================================================================
--- trunk/src/kernel32/oslibdos.cpp	(revision 1431)
+++ trunk/src/kernel32/oslibdos.cpp	(revision 1432)
@@ -1,3 +1,3 @@
-/* $Id: oslibdos.cpp,v 1.4 1999-09-21 11:00:22 phaller Exp $ */
+/* $Id: oslibdos.cpp,v 1.5 1999-10-24 22:51:22 sandervl Exp $ */
 
 /*
@@ -44,4 +44,46 @@
 }
 //******************************************************************************
+//NOTE: If name == NULL, allocated gettable unnamed shared memory
+//******************************************************************************
+DWORD OSLibDosAllocSharedMem(LPVOID *lplpMemAddr, DWORD size, DWORD flags, LPSTR name)
+{
+ APIRET rc;
+ char  *sharedmemname = NULL;
+  
+  if(name) {
+	sharedmemname = (char *)malloc(strlen(name) + 16);
+	strcpy(sharedmemname, "\\SHAREMEM\\");
+	strcat(sharedmemname, name);
+  }
+  else	flags |= OBJ_GETTABLE;
+ 
+  rc = DosAllocSharedMem(lplpMemAddr, sharedmemname, size, flags);
+  if(name) { 
+	free(sharedmemname);
+  }
+  return rc;
+}
+//******************************************************************************
+//NOTE: If name == NULL, assume gettable unnamed shared memory
+//******************************************************************************
+DWORD OSLibDosGetNamedSharedMem(LPVOID *lplpMemAddr, LPSTR name)
+{
+ APIRET rc;
+ char  *sharedmemname = NULL;
+  
+  if(name) {
+	sharedmemname = (char *)malloc(strlen(name) + 16);
+	strcpy(sharedmemname, "\\SHAREMEM\\");
+	strcat(sharedmemname, name);
+	rc = DosGetNamedSharedMem(lplpMemAddr, sharedmemname, PAG_READ|PAG_WRITE);
+	if(name) { 
+		free(sharedmemname);
+	}
+  }
+  else	rc = DosGetSharedMem((LPVOID)*(DWORD *)lplpMemAddr, PAG_READ|PAG_WRITE);
+
+  return rc;
+}
+//******************************************************************************
 //******************************************************************************
 DWORD OSLibDosQueryMem(LPVOID lpMemAddr, DWORD *lpRangeSize, DWORD *lpAttr)
Index: trunk/src/kernel32/oslibdos.h
===================================================================
--- trunk/src/kernel32/oslibdos.h	(revision 1431)
+++ trunk/src/kernel32/oslibdos.h	(revision 1432)
@@ -1,3 +1,3 @@
-/* $Id: oslibdos.h,v 1.4 1999-09-21 11:00:23 phaller Exp $ */
+/* $Id: oslibdos.h,v 1.5 1999-10-24 22:51:22 sandervl Exp $ */
 
 /*
@@ -19,4 +19,6 @@
 DWORD OSLibDosQueryMem(LPVOID lpMemAddr, DWORD *lpRangeSize, DWORD *lpAttr);
 DWORD OSLibDosSetMem(LPVOID lpMemAddr, DWORD size, DWORD flags);
+DWORD OSLibDosAllocSharedMem(LPVOID *lplpMemAddr, DWORD size, DWORD flags, LPSTR name);
+DWORD OSLibDosGetNamedSharedMem(LPVOID *lplpMemAddr, LPSTR name);
 
 BOOL OSLibDosGetFileAttributesEx(PSZ pszName, ULONG ulDummy, PVOID pBuffer);
Index: trunk/src/kernel32/virtual.cpp
===================================================================
--- trunk/src/kernel32/virtual.cpp	(revision 1431)
+++ trunk/src/kernel32/virtual.cpp	(revision 1432)
@@ -1,3 +1,3 @@
-/* $Id: virtual.cpp,v 1.20 1999-10-21 19:24:23 sandervl Exp $ */
+/* $Id: virtual.cpp,v 1.21 1999-10-24 22:51:22 sandervl Exp $ */
 
 /*
@@ -676,2 +676,69 @@
   }
 }
+
+//******************************************************************************
+//SvL: Private api
+//******************************************************************************
+LPVOID VirtualAllocShared(DWORD  cbSize, DWORD  fdwAllocationType,
+                          DWORD  fdwProtect, LPSTR name)
+{
+  LPVOID Address;
+  ULONG flag = 0, base;
+  DWORD rc;
+
+  dprintf(("VirtualAllocShared: %x %x %x %s", cbSize, fdwAllocationType, fdwProtect, name));
+
+  if (cbSize > 0x7fc00000)  /* 2Gb - 4Mb */
+  {
+   	dprintf(("VirtualAllocShared: size too large"));
+        SetLastError( ERROR_OUTOFMEMORY );
+        return NULL;
+  }
+
+  if (!(fdwAllocationType & (MEM_COMMIT | MEM_RESERVE)) ||
+       (fdwAllocationType & ~(MEM_COMMIT | MEM_RESERVE)))
+  {
+   	dprintf(("VirtualAllocShared: Invalid parameter"));
+        SetLastError( ERROR_INVALID_PARAMETER );
+        return NULL;
+  }
+
+  if(fdwAllocationType & MEM_COMMIT)
+  {
+        dprintf(("VirtualAllocShared: commit\n"));
+        flag = PAG_COMMIT;
+  }
+
+  if(fdwProtect & PAGE_READONLY)     flag |= PAG_READ;
+  if(fdwProtect & PAGE_NOACCESS)     flag |= PAG_READ; //can't do this in OS/2
+  if(fdwProtect & PAGE_READWRITE)    flag |= (PAG_READ | PAG_WRITE);
+  if(fdwProtect & PAGE_WRITECOPY)    flag |= (PAG_READ | PAG_WRITE);
+
+  if(fdwProtect & PAGE_EXECUTE_READWRITE) flag |= (PAG_EXECUTE | PAG_WRITE | PAG_READ);
+  if(fdwProtect & PAGE_EXECUTE_READ) flag |= (PAG_EXECUTE | PAG_READ);
+  if(fdwProtect & PAGE_EXECUTE)      flag |= PAG_EXECUTE;
+
+  if(fdwProtect & PAGE_GUARD) {
+	dprintf(("ERROR: PAGE_GUARD bit set for VirtualAllocShared -> we don't support this right now!"));
+        flag |= PAG_GUARD;
+  }
+
+  //just do this if other options are used
+  if(!(flag & (PAG_READ | PAG_WRITE | PAG_EXECUTE)) || flag == 0)
+  {
+    dprintf(("VirtualAllocShared: Unknown protection flags, default to read/write"));
+    flag |= PAG_READ | PAG_WRITE;
+  }
+
+  rc = OSLibDosAllocSharedMem(&Address, cbSize, flag, name);
+
+  if(rc)
+  {
+    dprintf(("DosAllocSharedMem returned %d\n", rc));
+    SetLastError( ERROR_OUTOFMEMORY );
+    return(NULL);
+  }
+
+  dprintf(("VirtualAllocShared returned %X\n", Address));
+  return(Address);
+}
Index: trunk/src/kernel32/vmutex.cpp
===================================================================
--- trunk/src/kernel32/vmutex.cpp	(revision 1431)
+++ trunk/src/kernel32/vmutex.cpp	(revision 1432)
@@ -1,3 +1,3 @@
-/* $Id: vmutex.cpp,v 1.6 1999-08-28 19:33:44 sandervl Exp $ */
+/* $Id: vmutex.cpp,v 1.7 1999-10-24 22:51:22 sandervl Exp $ */
 
 /*
@@ -22,5 +22,5 @@
  APIRET rc;
 
-  rc = DosCreateMutexSem(NULL, &sem_handle, (fShared) ? DC_SEM_SHARED : 0, FALSE);
+  rc = DosCreateMutexSem(NULL, &sem_handle, (fShared == VMUTEX_SHARED) ? DC_SEM_SHARED : 0, FALSE);
   if(rc != 0) {
     dprintf(("Error creating mutex %X\n", rc));
