Index: trunk/src/kernel32/HandleManager.cpp
===================================================================
--- trunk/src/kernel32/HandleManager.cpp	(revision 677)
+++ trunk/src/kernel32/HandleManager.cpp	(revision 678)
@@ -1,3 +1,3 @@
-/* $Id: HandleManager.cpp,v 1.14 1999-08-25 08:55:17 phaller Exp $ */
+/* $Id: HandleManager.cpp,v 1.15 1999-08-25 10:28:39 sandervl Exp $ */
 
 /*
@@ -2279,5 +2279,5 @@
                                                   /* call the device handler */
   rc = pDeviceHandler->OpenFileMapping(&TabWin32Handles[iIndexNew].hmHandleData,
-                                       fdwAccess,
+				       fdwAccess,
                                        fInherit,
                                        lpName);
@@ -2290,45 +2290,4 @@
 
   return iIndexNew;                                   /* return valid handle */
-}
-
-
-/*****************************************************************************
- * Name      : HMMapViewOfFile
- * Purpose   : router function for MapViewOfFile
- * Parameters:
- * Variables :
- * Result    :
- * Remark    :
- * Status    :
- *
- * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
- *****************************************************************************/
-
-LPVOID HMMapViewOfFile(HANDLE hFileMappingObject,
-                       DWORD  dwDesiredAccess,
-                       DWORD  dwFileOffsetHigh,
-                       DWORD  dwFileOffsetLow,
-                       DWORD  dwNumberOfBytesToMap)
-{
-  int       iIndex;                           /* index into the handle table */
-  LPVOID    lpResult;                /* result from the device handler's API */
-  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
-
-                                                          /* validate handle */
-  iIndex = _HMHandleQuery(hFileMappingObject);              /* get the index */
-  if (-1 == iIndex)                                               /* error ? */
-  {
-    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
-    return (NULL);                                         /* signal failure */
-  }
-
-  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
-  lpResult = pHMHandle->pDeviceHandler->MapViewOfFile(&pHMHandle->hmHandleData,
-                                                      dwDesiredAccess,
-                                                      dwFileOffsetHigh,
-                                                      dwFileOffsetLow,
-                                                      dwNumberOfBytesToMap);
-
-  return (lpResult);                                  /* deliver return code */
 }
 
@@ -2376,74 +2335,4 @@
 }
 
-
-/*****************************************************************************
- * Name      : HMUnmapViewOfFile
- * Purpose   : router function for UnmapViewOfFile
- * Parameters:
- * Variables :
- * Result    :
- * Remark    :
- * Status    :
- *
- * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
- *****************************************************************************/
-
-BOOL HMUnmapViewOfFile(LPVOID lpBaseAddress)
-{
-  int       iIndex;                           /* index into the handle table */
-  BOOL      bResult;                 /* result from the device handler's API */
-  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
-
-                                                          /* validate handle */
-  iIndex = HMDeviceMemMapClass::findByBaseAddress(lpBaseAddress);
-  if (-1 == iIndex)                                               /* error ? */
-  {
-    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
-    return (NULL);                                         /* signal failure */
-  }
-
-  bResult = pHMHandle->pDeviceHandler->UnmapViewOfFile(&pHMHandle->hmHandleData,
-                                                       lpBaseAddress);
-
-  return (bResult);                                   /* deliver return code */
-}
-
-
-/*****************************************************************************
- * Name      : HMFlushViewOfFile
- * Purpose   : router function for FlushViewOfFile
- * Parameters:
- * Variables :
- * Result    :
- * Remark    :
- * Status    :
- *
- * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
- *****************************************************************************/
-
-BOOL HMFlushViewOfFile(LPVOID lpBaseAddress,
-                       DWORD  dwNumberOfBytesToFlush)
-{
-  int       iIndex;                           /* index into the handle table */
-  BOOL      bResult;                 /* result from the device handler's API */
-  PHMHANDLE pHMHandle;       /* pointer to the handle structure in the table */
-
-                                                          /* validate handle */
-  iIndex = HMDeviceMemMapClass::findByBaseAddress(lpBaseAddress);
-  if (-1 == iIndex)                                               /* error ? */
-  {
-    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
-    return (NULL);                                         /* signal failure */
-  }
-
-  bResult = pHMHandle->pDeviceHandler->FlushViewOfFile(&pHMHandle->hmHandleData,
-                                                       lpBaseAddress,
-                                                       dwNumberOfBytesToFlush);
-
-  return (bResult);                                  /* deliver return code */
-}
-
-
-
 /*****************************************************************************
  * Name      : HMWaitForMultipleObjects
Index: trunk/src/kernel32/exceptions.cpp
===================================================================
--- trunk/src/kernel32/exceptions.cpp	(revision 677)
+++ trunk/src/kernel32/exceptions.cpp	(revision 678)
@@ -1,3 +1,3 @@
-/* $Id: exceptions.cpp,v 1.11 1999-08-22 22:11:21 sandervl Exp $ */
+/* $Id: exceptions.cpp,v 1.12 1999-08-25 10:28:40 sandervl Exp $ */
 
 /*
@@ -56,5 +56,6 @@
 #include "exceptions.h"
 #include "exceptutil.h"
-#include "misc.h"
+#include <misc.h>
+#include "mmap.h"
 
 //Global Process Unhandled exception filter
@@ -873,25 +874,63 @@
   switch(pERepRec->ExceptionNum)
   {
-    case XCPT_FLOAT_DENORMAL_OPERAND:
-    case XCPT_FLOAT_DIVIDE_BY_ZERO:
-    case XCPT_FLOAT_INEXACT_RESULT:
-    case XCPT_FLOAT_INVALID_OPERATION:
-    case XCPT_FLOAT_OVERFLOW:
-    case XCPT_FLOAT_STACK_CHECK:
-    case XCPT_FLOAT_UNDERFLOW:
-      dprintf(("KERNEL32: OS2ExceptionHandler: FPU exception, fix and continue\n"));
-               pCtxRec->ctx_env[0] |= 0x1F;
-               pCtxRec->ctx_stack[0].losig = 0;
-               pCtxRec->ctx_stack[0].hisig = 0;
-               pCtxRec->ctx_stack[0].signexp = 0;
-
-      return (XCPT_CONTINUE_EXECUTION);
-
-    case XCPT_PROCESS_TERMINATE:
-    case XCPT_ASYNC_PROCESS_TERMINATE:
-      SetExceptionChain((ULONG)0);
-      return (XCPT_CONTINUE_SEARCH);
+  case XCPT_FLOAT_DENORMAL_OPERAND:
+  case XCPT_FLOAT_DIVIDE_BY_ZERO:
+  case XCPT_FLOAT_INEXACT_RESULT:
+  case XCPT_FLOAT_INVALID_OPERATION:
+  case XCPT_FLOAT_OVERFLOW:
+  case XCPT_FLOAT_STACK_CHECK:
+  case XCPT_FLOAT_UNDERFLOW:
+  	dprintf(("KERNEL32: OS2ExceptionHandler: FPU exception, fix and continue\n"));
+        pCtxRec->ctx_env[0] |= 0x1F;
+        pCtxRec->ctx_stack[0].losig = 0;
+        pCtxRec->ctx_stack[0].hisig = 0;
+        pCtxRec->ctx_stack[0].signexp = 0;
+
+      	return (XCPT_CONTINUE_EXECUTION);
+
+  case XCPT_PROCESS_TERMINATE:
+  case XCPT_ASYNC_PROCESS_TERMINATE:
+      	SetExceptionChain((ULONG)0);
+      	return (XCPT_CONTINUE_SEARCH);
 
   case XCPT_ACCESS_VIOLATION:
+  {	
+   Win32MemMap *map;
+  
+	if(pERepRec->ExceptionInfo[1] == 0 && pERepRec->ExceptionInfo[1] == XCPT_DATA_UNKNOWN) {
+		goto continueFail;
+	}
+       	map = Win32MemMap::findMap(pERepRec->ExceptionInfo[0]);
+	if(map == NULL) {
+		goto continueFail;
+	}
+	switch(pERepRec->ExceptionInfo[0]) {
+	case XCPT_READ_ACCESS:
+		if(map->hasReadAccess() == FALSE) {
+			goto continueFail;
+		}
+		break;
+	case XCPT_WRITE_ACCESS:
+		if(map->hasWriteAccess() == FALSE) {
+			goto continueFail;
+		}
+		break;
+	case XCPT_EXECUTE_ACCESS:
+		if(map->hasExecuteAccess() == FALSE) {
+			goto continueFail;
+		}
+		break;
+	default:
+		goto continueFail;
+	}
+	//Might want to consider mapping more than one page if access is at
+        //a high offset in the page
+	if(map->commitPage((LPVOID)pERepRec->ExceptionInfo[1], 1) == TRUE)
+		return (XCPT_CONTINUE_EXECUTION);
+
+	//no break;
+  }
+continueFail:
+
   case XCPT_BREAKPOINT:
   case XCPT_ARRAY_BOUNDS_EXCEEDED:
@@ -907,10 +946,10 @@
   case XCPT_IN_PAGE_ERROR:
   case XCPT_SIGNAL:
-    dprintf(("KERNEL32: OS2ExceptionHandler: Continue and kill\n"));
-    pCtxRec->ctx_RegEip = (ULONG)KillWin32Process;
-    pCtxRec->ctx_RegEsp = pCtxRec->ctx_RegEsp + 0x10;
-    pCtxRec->ctx_RegEax = pERepRec->ExceptionNum;
-    pCtxRec->ctx_RegEbx = pCtxRec->ctx_RegEip;
-    return (XCPT_CONTINUE_EXECUTION);
+    	dprintf(("KERNEL32: OS2ExceptionHandler: Continue and kill\n"));
+    	pCtxRec->ctx_RegEip = (ULONG)KillWin32Process;
+    	pCtxRec->ctx_RegEsp = pCtxRec->ctx_RegEsp + 0x10;
+    	pCtxRec->ctx_RegEax = pERepRec->ExceptionNum;
+    	pCtxRec->ctx_RegEbx = pCtxRec->ctx_RegEip;
+    	return (XCPT_CONTINUE_EXECUTION);
 
   default: //non-continuable exceptions
Index: trunk/src/kernel32/hmdevice.cpp
===================================================================
--- trunk/src/kernel32/hmdevice.cpp	(revision 677)
+++ trunk/src/kernel32/hmdevice.cpp	(revision 678)
@@ -1,3 +1,3 @@
-/* $Id: hmdevice.cpp,v 1.5 1999-08-25 08:55:18 phaller Exp $ */
+/* $Id: hmdevice.cpp,v 1.6 1999-08-25 10:28:40 sandervl Exp $ */
 
 /*
@@ -983,5 +983,5 @@
   dprintf(("KERNEL32: HandleManager::DeviceHandler::OpenFileMapping(%08xh,%08xh,%08xh,%08xh)\n",
            pHMHandleData->hHMHandle,
-           fdwAccess,
+	   fdwAccess,
            fInherit,
            lpName));
@@ -1006,44 +1006,10 @@
  *****************************************************************************/
 
-LPVOID HMDeviceHandler::MapViewOfFile(PHMHANDLEDATA pHMHandleData,
+LPVOID HMDeviceHandler::MapViewOfFileEx(PHMHANDLEDATA pHMHandleData,
                                       DWORD         dwDesiredAccess,
                                       DWORD         dwFileOffsetHigh,
                                       DWORD         dwFileOffsetLow,
-                                      DWORD         dwNumberOfBytesToMap)
-{
-  dprintf(("KERNEL32: HandleManager::DeviceHandler::MapViewOfFile(%08xh,%08xh,%08xh,%08xh,%08xh)\n",
-           pHMHandleData->hHMHandle,
-           dwDesiredAccess,
-           dwFileOffsetHigh,
-           dwFileOffsetLow,
-           dwNumberOfBytesToMap));
-
-  return(NULL);
-}
-
-
-/*****************************************************************************
- * Name      : DWORD HMDeviceHandler::MapViewOfFileEx
- * Purpose   : map memory mapped file
- * Parameters: PHMHANDLEDATA pHMHandleData
- *             DWORD         dwDesiredAccess,
- *             DWORD         dwFileOffsetHigh,
- *             DWORD         dwFileOffsetLow,
- *             DWORD         dwNumberOfBytesToMap
- *             LPVOID        lpBaseAddress
- * Variables :
- * Result    : address to memory mapped region
- * Remark    :
- * Status    :
- *
- * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
- *****************************************************************************/
-
-LPVOID HMDeviceHandler::MapViewOfFileEx(PHMHANDLEDATA pHMHandleData,
-                                        DWORD         dwDesiredAccess,
-                                        DWORD         dwFileOffsetHigh,
-                                        DWORD         dwFileOffsetLow,
-                                        DWORD         dwNumberOfBytesToMap,
-                                        LPVOID        lpBaseAddress)
+                                      DWORD         dwNumberOfBytesToMap,
+			              LPVOID        lpBaseAddress)
 {
   dprintf(("KERNEL32: HandleManager::DeviceHandler::MapViewOfFileEx(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh)\n",
@@ -1056,54 +1022,2 @@
   return(NULL);
 }
-
-
-/*****************************************************************************
- * Name      : DWORD HMDeviceHandler::UnmapViewOfFile
- * Purpose   : map memory mapped file
- * Parameters: PHMHANDLEDATA pHMHandleData
- *             LPVOID        lpBaseAddress
- * Variables :
- * Result    : address to memory mapped region
- * Remark    :
- * Status    :
- *
- * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
- *****************************************************************************/
-
-BOOL HMDeviceHandler::UnmapViewOfFile(PHMHANDLEDATA pHMHandleData,
-                                      LPVOID        lpBaseAddress)
-{
-  dprintf(("KERNEL32: HandleManager::DeviceHandler::UnmapViewOfFile(%08xh,%08xh)\n",
-           pHMHandleData->hHMHandle,
-           lpBaseAddress));
-
-  return(FALSE);
-}
-
-
-/*****************************************************************************
- * Name      : DWORD HMDeviceHandler::FlushViewOfFile
- * Purpose   : map memory mapped file
- * Parameters: PHMHANDLEDATA pHMHandleData
- *             LPVOID        lpBaseAddress
- *             DWORD         dwNumberOfBytesToFlush
- * Variables :
- * Result    : address to memory mapped region
- * Remark    :
- * Status    :
- *
- * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
- *****************************************************************************/
-
-BOOL HMDeviceHandler::FlushViewOfFile(PHMHANDLEDATA pHMHandleData,
-                                      LPVOID        lpBaseAddress,
-                                      DWORD         dwNumberOfBytesToFlush)
-{
-  dprintf(("KERNEL32: HandleManager::DeviceHandler::FlushViewOfFile(%08xh,%08xh,%08xh)\n",
-           pHMHandleData->hHMHandle,
-           lpBaseAddress,
-           dwNumberOfBytesToFlush));
-
-  return(FALSE);
-}
-
Index: trunk/src/kernel32/hmdevice.h
===================================================================
--- trunk/src/kernel32/hmdevice.h	(revision 677)
+++ trunk/src/kernel32/hmdevice.h	(revision 678)
@@ -1,3 +1,3 @@
-/* $Id: hmdevice.h,v 1.6 1999-08-25 08:55:18 phaller Exp $ */
+/* $Id: hmdevice.h,v 1.7 1999-08-25 10:28:40 sandervl Exp $ */
 
 /*
@@ -25,6 +25,6 @@
  *****************************************************************************/
 
-#define HMTYPE_UNKNOWN                   0
-#define HMTYPE_MEMMAP                    1
+#define HMTYPE_UNKNOWN	0
+#define HMTYPE_MEMMAP	1
 //.....
 
@@ -232,5 +232,5 @@
    ***************************************************************************/
 
-                  /* this is a handler method for calls to CreateSemaphore() */
+                     /* this is a handler method for calls to CreateSemaphore() */
   virtual DWORD CreateSemaphore (PHMHANDLEDATA         pHMHandleData,
                                  LPSECURITY_ATTRIBUTES lpsa,
@@ -239,10 +239,10 @@
                                  LPCSTR                lpszSemaphoreName);
 
-                    /* this is a handler method for calls to OpenSemaphore() */
+                       /* this is a handler method for calls to OpenSemaphore() */
   virtual DWORD OpenSemaphore   (PHMHANDLEDATA         pHMHandleData,
                                  BOOL                  fInheritHandle,
                                  LPCSTR                lpszSemaphoreName);
 
-                  /* this is a handle method for calls to ReleaseSemaphore() */
+                     /* this is a handle method for calls to ReleaseSemaphore() */
   virtual BOOL  ReleaseSemaphore(PHMHANDLEDATA pHMHandleData,
                                  LONG          cReleaseCount,
@@ -260,16 +260,9 @@
                   /* this is a handler method for calls to OpenFileMapping() */
   virtual DWORD OpenFileMapping     (PHMHANDLEDATA              pHMHandleData,
-                                     DWORD access,   /* [in] Access mode */
+		                     DWORD access,   /* [in] Access mode */
                                      BOOL                       fInherit,
                                      LPCSTR                     lpName);
 
-                    /* this is a handler method for calls to MapViewOfFile() */
-  virtual LPVOID MapViewOfFile      (PHMHANDLEDATA              pHMHandleData,
-                                     DWORD                      dwDesiredAccess,
-                                     DWORD                      dwFileOffsetHigh,
-                                     DWORD                      dwFileOffsetLow,
-                                     DWORD                      dwNumberOfBytesToMap);
-
-                  /* this is a handler method for calls to MapViewOfFileEx() */
+                    /* this is a handler method for calls to MapViewOfFileEx() */
   virtual LPVOID MapViewOfFileEx    (PHMHANDLEDATA              pHMHandleData,
                                      DWORD                      dwDesiredAccess,
@@ -277,14 +270,5 @@
                                      DWORD                      dwFileOffsetLow,
                                      DWORD                      dwNumberOfBytesToMap,
-                                     LPVOID                     lpBaseAddress);
-
-                  /* this is a handler method for calls to UnmapViewOfFile() */
-  virtual BOOL   UnmapViewOfFile    (PHMHANDLEDATA              pHMHandleData,
-                                     LPVOID                     lpBaseAddress);
-
-                  /* this is a handler method for calls to FlushViewOfFile() */
-  virtual BOOL   FlushViewOfFile    (PHMHANDLEDATA              pHMHandleData,
-                                     LPVOID                     lpBaseAddress,
-                                     DWORD                      dwNumberOfBytesToFlush);
+			             LPVOID                     lpBaseAddress);
 
 };
Index: trunk/src/kernel32/hmmmap.cpp
===================================================================
--- trunk/src/kernel32/hmmmap.cpp	(revision 677)
+++ trunk/src/kernel32/hmmmap.cpp	(revision 678)
@@ -1,3 +1,3 @@
-/* $Id: hmmmap.cpp,v 1.3 1999-08-25 10:23:34 phaller Exp $ */
+/* $Id: hmmmap.cpp,v 1.4 1999-08-25 10:28:40 sandervl Exp $ */
 
 /*
@@ -47,25 +47,18 @@
 //******************************************************************************
 DWORD HMDeviceMemMapClass::CreateFileMapping(PHMHANDLEDATA         pHMHandleData,
-			 		     HFILE hFile,
+			 		     HFILE hFile, 
                 	 		     SECURITY_ATTRIBUTES *sa, /* [in] Optional security attributes*/
                 	 		     DWORD protect,   /* [in] Protection for mapping object */
                 		   	     DWORD size_high, /* [in] High-order 32 bits of object size */
                 		   	     DWORD size_low,  /* [in] Low-order 32 bits of object size */
-                		   	     LPCSTR name)     /* [in] Name of file-mapping object */
+                		   	     LPCSTR name)     /* [in] Name of file-mapping object */ 
 {
-  Win32MemMap *map;
-
-  dprintf(("KERNEL32::HMDeviceMemMapClass::CreateFileMapping(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh,%s)\n",
-           pHMHandleData,
-           hFile,
-           sa,
-           protect,
-           size_high,
-           size_low,
-           name));
+ Win32MemMap *map;
 
   if((hFile == -1 && size_low == 0) || size_high ||
      protect & (PAGE_READONLY|PAGE_READWRITE|PAGE_WRITECOPY|SEC_COMMIT|SEC_IMAGE|SEC_RESERVE|SEC_NOCACHE) ||
-     ((protect & SEC_COMMIT) && (protect & SEC_RESERVE)))
+     (protect & (PAGE_READONLY|PAGE_READWRITE|PAGE_WRITECOPY)) == 0 ||
+     (hFile == -1 && (protect & SEC_COMMIT)) ||
+     ((protect & SEC_COMMIT) && (protect & SEC_RESERVE))) 
   {
 
@@ -79,5 +72,5 @@
 	dprintf(("CreateFileMappingA: can't create Win32MemMap object!"));
 	return ERROR_OUTOFMEMORY;
-  }
+  }  
 
   if(map->Init(pHMHandleData->hHMHandle) == FALSE) {
@@ -97,13 +90,6 @@
                 		           LPCSTR name )   /* [in] Name of file-mapping object */
 {
-  Win32MemMap *map;
-  DWORD        protflags;
-
-  dprintf(("KERNEL32::HMDeviceMemMapClass::OpenFileMapping(%08xh,%08xh,%08xh,%08xh\n",
-           pHMHandleData,
-           access,
-           inherit,
-           name));
-
+ Win32MemMap *map;
+ DWORD        protflags;
 
   if(name == NULL)
@@ -171,35 +157,11 @@
 //******************************************************************************
 //******************************************************************************
-LPVOID HMDeviceMemMapClass::MapViewOfFile(PHMHANDLEDATA pHMHandleData,
-                                      DWORD         dwDesiredAccess,
-                                      DWORD         dwFileOffsetHigh,
-                                      DWORD         dwFileOffsetLow,
-                                      DWORD         dwNumberOfBytesToMap)
-{
-  dprintf(("KERNEL32: HMDeviceMemMapClass::MapViewOfFile(%08xh,%08xh,%08xh,%08xh,%08xh)\n",
-           pHMHandleData->hHMHandle,
-           dwDesiredAccess,
-           dwFileOffsetHigh,
-           dwFileOffsetLow,
-           dwNumberOfBytesToMap));
-
-  return MapViewOfFileEx(pHMHandleData,
-                         dwDesiredAccess,
-                         dwFileOffsetHigh,
-                         dwFileOffsetLow,
-                         dwNumberOfBytesToMap,
-                         NULL);
-}
-
-//******************************************************************************
-//******************************************************************************
 DWORD HMDeviceMemMapClass::CloseHandle(PHMHANDLEDATA pHMHandleData)
 {
  Win32MemMap *map;
 
-  if(pHMHandleData->dwUserData == NULL || pHMHandleData->dwInternalType != HMTYPE_MEMMAP) 
-  {      
-    dprintf(("KERNEL32: HMDeviceMemMapClass:MapViewOfFileEx: invalid handle data!"));
-    return ERROR_INVALID_HANDLE;
+  if(pHMHandleData->dwUserData == NULL || pHMHandleData->dwInternalType != HMTYPE_MEMMAP) {
+	dprintf(("MapViewOfFileEx: invalid handle data!"));
+	return ERROR_INVALID_HANDLE;
   }
   map = (Win32MemMap *)pHMHandleData->dwUserData;
@@ -210,76 +172,2 @@
 //******************************************************************************
 //******************************************************************************
-
-
-/*****************************************************************************
- * Name      : DWORD HMDeviceHandler::findByBaseAddress
- * Purpose   : identify a memmap object by its base address
- * Parameters: LPVOID        lpBaseAddress
- * Variables :
- * Result    : PHMHANDLEDATA pHMHandleData
- * Remark    :
- * Status    :
- *
- * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
- *****************************************************************************/
-
-int HMDeviceMemMapClass::findByBaseAddress(LPVOID lpBaseAddress)
-{
-  dprintf(("KERNEL32: HMDeviceMemMapClass::findByBaseAddress(%08xh) not implemented\n",
-           lpBaseAddress));
-
-  return -1;
-}
-
-
-/*****************************************************************************
- * Name      : DWORD HMDeviceHandler::UnmapViewOfFile
- * Purpose   : map memory mapped file
- * Parameters: PHMHANDLEDATA pHMHandleData
- *             LPVOID        lpBaseAddress
- * Variables :
- * Result    : address to memory mapped region
- * Remark    :
- * Status    :
- *
- * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
- *****************************************************************************/
-
-BOOL HMDeviceMemMapClass::UnmapViewOfFile(PHMHANDLEDATA pHMHandleData,
-                                          LPVOID        lpBaseAddress)
-{
-  dprintf(("KERNEL32: HMDeviceMemMapClass::UnmapViewOfFile(%08xh,%08xh) not implemented\n",
-           pHMHandleData->hHMHandle,
-           lpBaseAddress));
-
-  return(FALSE);
-}
-
-
-/*****************************************************************************
- * Name      : DWORD HMDeviceHandler::FlushViewOfFile
- * Purpose   : map memory mapped file
- * Parameters: PHMHANDLEDATA pHMHandleData
- *             LPVOID        lpBaseAddress
- *             DWORD         dwNumberOfBytesToFlush
- * Variables :
- * Result    : address to memory mapped region
- * Remark    :
- * Status    :
- *
- * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
- *****************************************************************************/
-
-BOOL HMDeviceMemMapClass::FlushViewOfFile(PHMHANDLEDATA pHMHandleData,
-                                          LPVOID        lpBaseAddress,
-                                          DWORD         dwNumberOfBytesToFlush)
-{
-  dprintf(("KERNEL32: HMDeviceMemMapClass::FlushViewOfFile(%08xh,%08xh,%08xh) not implemented\n",
-           pHMHandleData->hHMHandle,
-           lpBaseAddress,
-           dwNumberOfBytesToFlush));
-
-  return(FALSE);
-}
-
-
Index: trunk/src/kernel32/hmmmap.h
===================================================================
--- trunk/src/kernel32/hmmmap.h	(revision 677)
+++ trunk/src/kernel32/hmmmap.h	(revision 678)
@@ -1,3 +1,3 @@
-/* $Id: hmmmap.h,v 1.2 1999-08-25 08:55:19 phaller Exp $ */
+/* $Id: hmmmap.h,v 1.3 1999-08-25 10:28:40 sandervl Exp $ */
 
 /*
@@ -34,8 +34,4 @@
   HMDeviceMemMapClass(LPCSTR lpDeviceName) : HMDeviceKernelObjectClass(lpDeviceName) {}
 
-  // identify a memmap object by its base address
-  static int findByBaseAddress(LPVOID lpBaseAddress);
-
-
   /* this is a handler method for calls to CreateFileMapping() */
   virtual DWORD CreateFileMapping   (PHMHANDLEDATA              pHMHandleData,
@@ -49,16 +45,9 @@
   /* this is a handler method for calls to OpenFileMapping() */
   virtual DWORD OpenFileMapping     (PHMHANDLEDATA              pHMHandleData,
-                                     DWORD access,   /* [in] Access mode */
+		                     DWORD access,   /* [in] Access mode */
                                      BOOL                       fInherit,
                                      LPCSTR                     lpName);
 
   /* this is a handler method for calls to MapViewOfFile() */
-  virtual LPVOID MapViewOfFile      (PHMHANDLEDATA              pHMHandleData,
-                                     DWORD                      dwDesiredAccess,
-                                     DWORD                      dwFileOffsetHigh,
-                                     DWORD                      dwFileOffsetLow,
-                                     DWORD                      dwNumberOfBytesToMap);
-
-  /* this is a handler method for calls to MapViewOfFileEx() */
   virtual LPVOID MapViewOfFileEx    (PHMHANDLEDATA              pHMHandleData,
                                      DWORD                      dwDesiredAccess,
@@ -66,17 +55,6 @@
                                      DWORD                      dwFileOffsetLow,
                                      DWORD                      dwNumberOfBytesToMap,
-                                     LPVOID                     lpBaseAddress);
+		                     LPVOID                     lpBaseAddress);
 
-                  /* this is a handler method for calls to UnmapViewOfFile() */
-  virtual BOOL   UnmapViewOfFile    (PHMHANDLEDATA              pHMHandleData,
-                                     LPVOID                     lpBaseAddress);
-
-                  /* this is a handler method for calls to FlushViewOfFile() */
-  virtual BOOL   FlushViewOfFile    (PHMHANDLEDATA              pHMHandleData,
-                                     LPVOID                     lpBaseAddress,
-                                     DWORD                      dwNumberOfBytesToFlush);
-
-
-                  /* this is a handler method for calls to CloseHandle() */
   virtual DWORD  CloseHandle(PHMHANDLEDATA pHMHandleData);
 };
Index: trunk/src/kernel32/makefile
===================================================================
--- trunk/src/kernel32/makefile	(revision 677)
+++ trunk/src/kernel32/makefile	(revision 678)
@@ -1,3 +1,3 @@
-# $Id: makefile,v 1.29 1999-08-24 18:46:39 sandervl Exp $
+# $Id: makefile,v 1.30 1999-08-25 10:28:40 sandervl Exp $
 
 #
@@ -121,4 +121,5 @@
 exceptions.OBJ: \
     .\exceptions.cpp \
+    mmap.h \
     $(PDWIN32_INCLUDE)\exceptions.h \
     exceptutil.h
@@ -148,4 +149,5 @@
     $(PDWIN32_INCLUDE)\wprocess.h \
     console2.h \
+    mmap.h \
     cio.h \
     os2util.h
Index: trunk/src/kernel32/mmap.cpp
===================================================================
--- trunk/src/kernel32/mmap.cpp	(revision 677)
+++ trunk/src/kernel32/mmap.cpp	(revision 678)
@@ -1,3 +1,3 @@
-/* $Id: mmap.cpp,v 1.8 1999-08-24 18:46:40 sandervl Exp $ */
+/* $Id: mmap.cpp,v 1.9 1999-08-25 10:28:40 sandervl Exp $ */
 
 /*
@@ -18,4 +18,5 @@
  *
  * TODO: Handles returned should be usable by all apis that accept file handles
+ * TODO: Sharing memory mapped files between multiple processes
  *
  * Project Odin Software License can be found in LICENSE.TXT
@@ -115,4 +116,65 @@
 //******************************************************************************
 //******************************************************************************
+BOOL Win32MemMap::hasReadAccess()
+{
+  return TRUE; //should have at least this
+}
+//******************************************************************************
+//******************************************************************************
+BOOL Win32MemMap::hasWriteAccess()
+{
+  return !(mProtFlags & PAGE_READONLY);
+}
+//******************************************************************************
+//Might want to add this feature for memory mapping executable & dll files in 
+//the loader (done in Win32 with the SEC_IMAGE flag?)
+//******************************************************************************
+BOOL Win32MemMap::hasExecuteAccess()
+{
+  return FALSE;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL Win32MemMap::commitPage(LPVOID lpPageFaultAddr, ULONG nrpages)
+{
+ DWORD pageAddr = (DWORD)lpPageFaultAddr & ~0xFFF;
+ DWORD oldProt, newProt, nrBytesRead, offset, size;
+ 
+//  mapMutex.enter();
+  newProt  = mProtFlags & (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY);
+  newProt |= MEM_COMMIT;
+
+  dprintf(("Win32MemMap::commitPage %x (faultaddr %x), nr of pages %d", pageAddr, lpPageFaultAddr, nrpages));
+  if(VirtualProtect((LPVOID)pageAddr, nrpages*PAGE_SIZE, newProt, &oldProt) == FALSE) {
+	goto fail;
+  }
+  if(hMemFile != -1) {
+	offset = pageAddr - (ULONG)pMapping;
+	size   = nrpages*PAGE_SIZE;
+	if(offset + size > mSize) {
+		size = mSize - offset;
+	}
+	if(SetFilePointer(hMemFile, offset, NULL, FILE_BEGIN) != offset) {
+		dprintf(("Win32MemMap::commitPage: SetFilePointer failed to set pos to %x", offset));
+		goto fail;
+	}
+	if(ReadFile(hMemFile, (LPSTR)pageAddr, size, &nrBytesRead, NULL) == FALSE) {
+		dprintf(("Win32MemMap::commitPage: ReadFile failed for %x", pageAddr));
+		goto fail;
+	}
+	if(nrBytesRead != size) {
+		dprintf(("Win32MemMap::commitPage: ReadFile didn't read all bytes for %x", pageAddr));
+		goto fail;
+	}
+  }
+
+//  mapMutex.leave();
+  return TRUE;
+fail:
+//  mapMutex.leave();
+  return FALSE;
+}
+//******************************************************************************
+//******************************************************************************
 BOOL Win32MemMap::unmapViewOfFile()
 {
@@ -145,9 +207,15 @@
   if(fdwAccess & FILE_MAP_COPY && !(mProtFlags & PAGE_WRITECOPY)) 
 	goto parmfail;
-  
+
+//TODO: If committed, read file into memory
+#if 0  
   if(mProtFlags & SEC_COMMIT)
 	fAlloc |= MEM_COMMIT;
+  else
   if(mProtFlags & SEC_RESERVE)
  	fAlloc |= MEM_RESERVE;
+#else
+  fAlloc = MEM_RESERVE;
+#endif
 
   if(fMapped == FALSE) {//if not mapped, reserve/commit entire view
@@ -179,8 +247,8 @@
 {
  MEMORY_BASIC_INFORMATION memInfo;
- ULONG nrpages, nrBytesWritten;
+ ULONG nrpages, nrBytesWritten, offset, size;
  int   i;
 
-  mapMutex.enter();
+//  mapMutex.enter();
   if(fMapped == FALSE)
 	goto parmfail;
@@ -204,9 +272,20 @@
            memInfo.AllocationProtect & (PAGE_READWRITE|PAGE_WRITECOPY|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY)) 
         {//committed and allowed for writing?
-		if(WriteFile(hMemFile, (LPSTR)lpvBase+i*PAGE_SIZE, PAGE_SIZE, &nrBytesWritten, NULL) == FALSE) {
+		offset = (ULONG)lpvBase+i*PAGE_SIZE - (ULONG)pMapping;
+		size   = PAGE_SIZE;
+		if(offset + size > mSize) {
+			size = mSize - offset;
+		}
+		dprintf(("Win32MemMap::flushView for offset %x, size %d", offset, size));
+
+		if(SetFilePointer(hMemFile, offset, NULL, FILE_BEGIN) != offset) {
+			dprintf(("Win32MemMap::flushView: SetFilePointer failed to set pos to %x", offset));
+			goto fail;
+		}
+		if(WriteFile(hMemFile, (LPSTR)lpvBase+i*PAGE_SIZE, size, &nrBytesWritten, NULL) == FALSE) {
 			dprintf(("Win32MemMap::flushView: WriteFile failed for %x", (ULONG)lpvBase+i*PAGE_SIZE));
 			goto fail;
 		}
-		if(nrBytesWritten != PAGE_SIZE) {
+		if(nrBytesWritten != size) {
 			dprintf(("Win32MemMap::flushView: WriteFile didn't write all bytes for %x", (ULONG)lpvBase+i*PAGE_SIZE));
 			goto fail;
@@ -214,12 +293,12 @@
 	}
   }
-  mapMutex.leave();
+//  mapMutex.leave();
   return TRUE;
 parmfail:
   SetLastError(ERROR_INVALID_PARAMETER);
-  mapMutex.leave();
+//  mapMutex.leave();
   return FALSE;
 fail:
-  mapMutex.leave();
+//  mapMutex.leave();
   return FALSE;
 }
@@ -264,3 +343,11 @@
 //******************************************************************************
 //******************************************************************************
+void Win32MemMap::deleteAll()
+{
+  while(memmaps) {
+	CloseHandle(memmaps->hMemMap);
+  }
+}
+//******************************************************************************
+//******************************************************************************
 Win32MemMap *Win32MemMap::memmaps = NULL;
Index: trunk/src/kernel32/mmap.h
===================================================================
--- trunk/src/kernel32/mmap.h	(revision 677)
+++ trunk/src/kernel32/mmap.h	(revision 678)
@@ -1,3 +1,3 @@
-/* $Id: mmap.h,v 1.6 1999-08-24 18:46:40 sandervl Exp $ */
+/* $Id: mmap.h,v 1.7 1999-08-25 10:28:41 sandervl Exp $ */
 
 /*
@@ -37,6 +37,15 @@
    void   Release()                      { if(--referenced == 0) delete this; };
 
+   BOOL   hasReadAccess();
+   BOOL   hasWriteAccess();
+   BOOL   hasExecuteAccess();
+ 
+   BOOL   commitPage(LPVOID lpPageFaultAddr, ULONG nrpages);
+
 static Win32MemMap *findMap(LPSTR lpszName);
 static Win32MemMap *findMap(ULONG address);
+
+//Should only be called in ExitProcess
+static void deleteAll();
 
 protected:
Index: trunk/src/kernel32/virtual.cpp
===================================================================
--- trunk/src/kernel32/virtual.cpp	(revision 677)
+++ trunk/src/kernel32/virtual.cpp	(revision 678)
@@ -1,3 +1,3 @@
-/* $Id: virtual.cpp,v 1.3 1999-08-25 08:55:19 phaller Exp $ */
+/* $Id: virtual.cpp,v 1.4 1999-08-25 10:28:41 sandervl Exp $ */
 
 /*
@@ -19,5 +19,4 @@
 #include <win\virtual.h>
 #include <heapstring.h>
-#include "mmap.h"
 #include <handlemanager.h>
 
@@ -39,5 +38,5 @@
                 LPCSTR name      /* [in] Name of file-mapping object */ )
 {
-  return HMCreateFileMapping(hFile, sa, protect, size_high, size_low, name);
+   return HMCreateFileMapping(hFile, sa, protect, size_high, size_low, name);
 }
 
@@ -47,6 +46,6 @@
  * See CreateFileMapping32A
  */
-HANDLE WINAPI CreateFileMappingW( HFILE hFile, LPSECURITY_ATTRIBUTES attr,
-                                      DWORD protect, DWORD size_high,
+HANDLE WINAPI CreateFileMappingW( HFILE hFile, LPSECURITY_ATTRIBUTES attr, 
+                                      DWORD protect, DWORD size_high,  
                                       DWORD size_low, LPCWSTR name )
 {
@@ -72,5 +71,6 @@
                 LPCSTR name )   /* [in] Name of file-mapping object */
 {
-  return (HMOpenFileMapping(access, inherit, name));
+    dprintf(("OpenFileMappingA: %x %d %s", access, inherit, name));
+    return HMOpenFileMapping(access, inherit, name);
 }
 
@@ -103,8 +103,8 @@
               DWORD offset_low,  /* [in] Low-order 32 bits of file offset */
               DWORD count        /* [in] Number of bytes to map */
-)
-{
-  return HMMapViewOfFile( mapping, access, offset_high,
-                          offset_low, count);
+) 
+{
+    return MapViewOfFileEx( mapping, access, offset_high,
+                            offset_low, count, NULL );
 }
 
@@ -125,8 +125,7 @@
               DWORD count,       /* [in] Number of bytes to map */
               LPVOID addr        /* [in] Suggested starting address for mapped view */
-)
-{
-  return HMMapViewOfFileEx( handle, access, offset_high,
-                            offset_low, count, addr);
+) 
+{
+  return HMMapViewOfFileEx(handle, access, offset_high, offset_low, count, addr);
 }
 
@@ -143,7 +142,8 @@
               LPCVOID base, /* [in] Start address of byte range to flush */
               DWORD cbFlush /* [in] Number of bytes in range */
-)
-{
-  return HMFlushViewOfFile( (LPVOID)base, cbFlush);
+) 
+{
+    dprintf(("FlushViewOfFile: NOT IMPLEMENTED"));
+    return TRUE;
 }
 
@@ -161,9 +161,13 @@
  */
 BOOL WINAPI UnmapViewOfFile(LPVOID addr /* [in] Address where mapped view begins */
-)
-{
-  return HMUnmapViewOfFile( addr );
-}
-
+) 
+{
+    if (!addr)
+    {
+        SetLastError( ERROR_INVALID_PARAMETER );
+        return FALSE;
+    }
+    return TRUE;
+}
 
 /***********************************************************************
@@ -171,5 +175,5 @@
  *
  * Helper function to map a file to memory:
- *  name			-	file name
+ *  name			-	file name 
  *  [RETURN] ptr		-	pointer to mapped file
  */
@@ -179,5 +183,5 @@
     LPVOID ptr = NULL;
 
-    hFile = CreateFileW( name, GENERIC_READ, FILE_SHARE_READ, NULL,
+    hFile = CreateFileW( name, GENERIC_READ, FILE_SHARE_READ, NULL, 
                            OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, 0);
     if (hFile != INVALID_HANDLE_VALUE)
@@ -198,5 +202,5 @@
  *
  * Helper function to map a file to memory:
- *  name			-	file name
+ *  name			-	file name 
  *  [RETURN] ptr		-	pointer to mapped file
  */
@@ -206,5 +210,5 @@
     LPVOID ptr = NULL;
 
-    hFile = CreateFileA(name, GENERIC_READ, FILE_SHARE_READ, NULL,
+    hFile = CreateFileA(name, GENERIC_READ, FILE_SHARE_READ, NULL, 
                         OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, 0);
     if (hFile != INVALID_HANDLE_VALUE)
@@ -220,3 +224,2 @@
     return ptr;
 }
-
Index: trunk/src/kernel32/wprocess.cpp
===================================================================
--- trunk/src/kernel32/wprocess.cpp	(revision 677)
+++ trunk/src/kernel32/wprocess.cpp	(revision 678)
@@ -1,3 +1,3 @@
-/* $Id: wprocess.cpp,v 1.27 1999-08-24 23:32:24 phaller Exp $ */
+/* $Id: wprocess.cpp,v 1.28 1999-08-25 10:28:41 sandervl Exp $ */
 
 /*
@@ -30,4 +30,5 @@
 #include "versionos2.h"    /*PLF Wed  98-03-18 02:36:51*/
 #include <wprocess.h>
+#include "mmap.h"
 
 BOOL      fExeStarted = FALSE;
@@ -331,4 +332,9 @@
   SetOS2ExceptionChain(-1);
 
+  //Flush and delete all open memory mapped files
+  Win32MemMap::deleteAll();
+
+  Win32DllExitList(0);
+
   //Restore original OS/2 TIB selector
   DestroyTIB();
@@ -340,6 +346,4 @@
   if (iConsoleIsActive())
     iConsoleWaitClose();
-
-  Win32DllExitList(0);
 
   O32_ExitProcess(exitcode);
@@ -605,5 +609,5 @@
 }
 //******************************************************************************
-//NOTE: GetModuleHandleA does NOT support files with multiple dots (i.e.
+//NOTE: GetModuleHandleA does NOT support files with multiple dots (i.e. 
 //      very.weird.exe)
 //******************************************************************************
@@ -626,5 +630,5 @@
 	else {
 		if(!strstr(szModule, ".")) {
-			//if there's no extension or trainling dot, we
+			//if there's no extension or trainling dot, we 
                         //assume it's a dll (see Win32 SDK docs)
 			fDllModule = TRUE;
