Index: trunk/src/kernel32/hmmmap.cpp
===================================================================
--- trunk/src/kernel32/hmmmap.cpp	(revision 3606)
+++ trunk/src/kernel32/hmmmap.cpp	(revision 3609)
@@ -1,3 +1,3 @@
-/* $Id: hmmmap.cpp,v 1.12 2000-05-24 01:56:08 phaller Exp $ */
+/* $Id: hmmmap.cpp,v 1.13 2000-05-26 18:42:55 sandervl Exp $ */
 
 /*
@@ -213,6 +213,9 @@
 	return ERROR_INVALID_HANDLE;
   }
+  //Although an application may close the file handle used to create a file
+  //mapping object, the system holds the corresponding file open until the last
+  //view of the file is unmapped.
   map = (Win32MemMap *)pHMHandleData->dwUserData;
-  map->Release();
+  map->close();
 
   return NO_ERROR;
Index: trunk/src/kernel32/mmap.cpp
===================================================================
--- trunk/src/kernel32/mmap.cpp	(revision 3606)
+++ trunk/src/kernel32/mmap.cpp	(revision 3609)
@@ -1,3 +1,3 @@
-/* $Id: mmap.cpp,v 1.40 2000-05-24 19:28:26 sandervl Exp $ */
+/* $Id: mmap.cpp,v 1.41 2000-05-26 18:42:55 sandervl Exp $ */
 
 /*
@@ -17,4 +17,6 @@
  * TODO: Sharing memory mapped files between multiple processes
  * TODO: Memory mapped files with views that extend the file (not 100% correct now)
+ * TODO: Suspend all threads when a page is committed (possible that another thread
+ *       accesses the same memory before the page is read from disk
  *
  * Project Odin Software License can be found in LICENSE.TXT
@@ -52,5 +54,6 @@
 //******************************************************************************
 Win32MemMap::Win32MemMap(HFILE hfile, ULONG size, ULONG fdwProtect, LPSTR lpszName)
-               : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0), image(0)
+               : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0), image(0),
+                 fClosed(FALSE)
 {
   globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
@@ -75,5 +78,6 @@
 //******************************************************************************
 Win32MemMap::Win32MemMap(Win32PeLdrImage *pImage, ULONG baseAddress, ULONG size)
-               : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0)
+               : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0), image(0),
+                 fClosed(FALSE)
 {
   globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
@@ -292,4 +296,10 @@
   }
   mapMutex.leave();
+  
+  //if there are no more mappings left and the memory map's handle has been
+  //closed, then delete the object
+  if(nrMappings == 0 && fClosed) {
+	delete this;
+  }
   return TRUE;
 fail:
@@ -526,5 +536,9 @@
 			delete map;
 		}
-		else	CloseHandle(memmaps->hMemMap);
+		else {
+			if(!map->isClosed()) 
+				CloseHandle(memmaps->hMemMap);
+			delete map;
+		}
 	}
 	else {
Index: trunk/src/kernel32/mmap.h
===================================================================
--- trunk/src/kernel32/mmap.h	(revision 3606)
+++ trunk/src/kernel32/mmap.h	(revision 3609)
@@ -1,3 +1,3 @@
-/* $Id: mmap.h,v 1.15 2000-02-05 14:09:32 sandervl Exp $ */
+/* $Id: mmap.h,v 1.16 2000-05-26 18:42:56 sandervl Exp $ */
 
 /*
@@ -61,4 +61,7 @@
    void   Release()                      { if(--referenced == 0) delete this; };
 
+   void   close()                        { fClosed = TRUE; };
+   BOOL   isClosed()                     { return fClosed; };
+
    BOOL   commitPage(ULONG offset, BOOL fWriteAccess, int nrpages = NRPAGES_TOCOMMIT);
 
@@ -97,4 +100,5 @@
    LPSTR  lpszMapName;
    void  *pMapping;
+   BOOL   fClosed;  //handle is removed by CloseHandle
 
    ULONG  nrMappings;
Index: trunk/src/kernel32/winimagebase.cpp
===================================================================
--- trunk/src/kernel32/winimagebase.cpp	(revision 3606)
+++ trunk/src/kernel32/winimagebase.cpp	(revision 3609)
@@ -1,3 +1,3 @@
-/* $Id: winimagebase.cpp,v 1.19 2000-05-02 20:53:14 sandervl Exp $ */
+/* $Id: winimagebase.cpp,v 1.20 2000-05-26 18:42:56 sandervl Exp $ */
 
 /*
@@ -145,4 +145,11 @@
   //dummy
   return FALSE;
+}
+//******************************************************************************
+//******************************************************************************
+ULONG Win32ImageBase::getImageSize()
+{
+  //dummy
+  return 0;
 }
 //******************************************************************************
Index: trunk/src/kernel32/winimagebase.h
===================================================================
--- trunk/src/kernel32/winimagebase.h	(revision 3606)
+++ trunk/src/kernel32/winimagebase.h	(revision 3609)
@@ -1,3 +1,3 @@
-/* $Id: winimagebase.h,v 1.8 2000-05-22 19:08:00 sandervl Exp $ */
+/* $Id: winimagebase.h,v 1.9 2000-05-26 18:42:56 sandervl Exp $ */
 
 /*
@@ -105,4 +105,6 @@
 virtual ULONG getApi(int ordinal) = 0;
 
+virtual ULONG getImageSize();
+
 virtual BOOL  isDll() = 0;
 
Index: trunk/src/kernel32/winimagepeldr.cpp
===================================================================
--- trunk/src/kernel32/winimagepeldr.cpp	(revision 3606)
+++ trunk/src/kernel32/winimagepeldr.cpp	(revision 3609)
@@ -1,3 +1,3 @@
-/* $Id: winimagepeldr.cpp,v 1.42 2000-05-02 20:53:15 sandervl Exp $ */
+/* $Id: winimagepeldr.cpp,v 1.43 2000-05-26 18:42:56 sandervl Exp $ */
 
 /*
@@ -1496,4 +1496,10 @@
 //******************************************************************************
 //******************************************************************************
+ULONG Win32PeLdrImage::getImageSize()
+{
+  return imageSize;
+}
+//******************************************************************************
+//******************************************************************************
 ULONG Win32PeLdrImage::getApi(char *name)
 {
Index: trunk/src/kernel32/winimagepeldr.h
===================================================================
--- trunk/src/kernel32/winimagepeldr.h	(revision 3606)
+++ trunk/src/kernel32/winimagepeldr.h	(revision 3609)
@@ -1,3 +1,3 @@
-/* $Id: winimagepeldr.h,v 1.2 2000-05-02 20:53:15 sandervl Exp $ */
+/* $Id: winimagepeldr.h,v 1.3 2000-05-26 18:42:57 sandervl Exp $ */
 
 /*
@@ -81,5 +81,5 @@
         //any dlls are loaded, so that exes without fixups can be loaded at a low
         //address)
-virtual BOOL  init(ULONG reservedMem);
+    virtual BOOL  init(ULONG reservedMem);
 
     virtual BOOL  insideModule(ULONG address);
@@ -88,4 +88,6 @@
     virtual ULONG getApi(char *name);
     virtual ULONG getApi(int ordinal);
+
+    virtual ULONG getImageSize();
 
     //Returns required OS version for this image
