Index: trunk/src/kernel32/disk.cpp
===================================================================
--- trunk/src/kernel32/disk.cpp	(revision 4794)
+++ trunk/src/kernel32/disk.cpp	(revision 4796)
@@ -1,3 +1,3 @@
-/* $Id: disk.cpp,v 1.23 2000-12-07 12:00:23 sandervl Exp $ */
+/* $Id: disk.cpp,v 1.24 2000-12-12 23:57:15 sandervl Exp $ */
 
 /*
@@ -304,5 +304,5 @@
         }
     }
-    if(lpFileSystemNameBuffer || lpMaximumComponentLength) {
+    if(lpFileSystemNameBuffer || lpMaximumComponentLength || lpFileSystemFlags) {
         if(!lpFileSystemNameBuffer) {
             lpFileSystemNameBuffer = tmpstring;
Index: trunk/src/kernel32/mmap.cpp
===================================================================
--- trunk/src/kernel32/mmap.cpp	(revision 4794)
+++ trunk/src/kernel32/mmap.cpp	(revision 4796)
@@ -1,3 +1,3 @@
-/* $Id: mmap.cpp,v 1.45 2000-10-18 17:09:33 sandervl Exp $ */
+/* $Id: mmap.cpp,v 1.46 2000-12-12 23:57:16 sandervl Exp $ */
 
 /*
@@ -57,20 +57,20 @@
                  fClosed(FALSE)
 {
-  globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
-  next    = memmaps;
-  memmaps = this;
-  globalmapMutex.leave(&hGlobalMapMutex);
-
-  hMemFile   = hfile;
-
-  mSize      = size;
-  mProtFlags = fdwProtect;
-  mProcessId  = GetCurrentProcess();
-
-  if(lpszName) {
-    lpszMapName = (char *)_smalloc(strlen(lpszName)+1);
-    strcpy(lpszMapName, lpszName);
-  }
-  else  lpszMapName = NULL;
+    globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
+    next    = memmaps;
+    memmaps = this;
+    globalmapMutex.leave(&hGlobalMapMutex);
+
+    hMemFile   = hfile;
+
+    mSize      = size;
+    mProtFlags = fdwProtect;
+    mProcessId  = GetCurrentProcess();
+
+    if(lpszName) {
+        lpszMapName = (char *)_smalloc(strlen(lpszName)+1);
+        strcpy(lpszMapName, lpszName);
+    }
+    else  lpszMapName = NULL;
 }
 //******************************************************************************
@@ -81,19 +81,19 @@
                  fClosed(FALSE)
 {
-  globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
-  next    = memmaps;
-  memmaps = this;
-  globalmapMutex.leave(&hGlobalMapMutex);
-
-  hMemFile   = -1;
-
-  mSize      = size;
-  mProtFlags = PAGE_READWRITE;
-  mProcessId = GetCurrentProcess();
-
-  pMapping   = (LPVOID)baseAddress;
-
-  image      = pImage;
-  lpszMapName= NULL;
+    globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
+    next    = memmaps;
+    memmaps = this;
+    globalmapMutex.leave(&hGlobalMapMutex);
+
+    hMemFile   = -1;
+
+    mSize      = size;
+    mProtFlags = PAGE_READWRITE;
+    mProcessId = GetCurrentProcess();
+
+    pMapping   = (LPVOID)baseAddress;
+
+    image      = pImage;
+    lpszMapName= NULL;
 }
 //******************************************************************************
@@ -101,17 +101,17 @@
 BOOL Win32MemMap::Init(HANDLE hMemMap)
 {
-  mapMutex.enter();
-  if(hMemFile != -1)
-  {
+    mapMutex.enter();
+    if(hMemFile != -1)
+    {
 #if 0
         if(DuplicateHandle(mProcessId, hMemFile, GetCurrentProcess(),
                            &hMemFile, 0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE)
 #else
-    DWORD dwOdinOptions;
-
-    if(!(mProtFlags & PAGE_READWRITE)) {
-        dwOdinOptions = DUPLICATE_ACCESS_READ | DUPLICATE_SHARE_DENYNONE;
-    }
-    else    dwOdinOptions = DUPLICATE_ACCESS_READWRITE | DUPLICATE_SHARE_DENYNONE;
+        DWORD dwOdinOptions;
+
+        if(!(mProtFlags & PAGE_READWRITE)) {
+                dwOdinOptions = DUPLICATE_ACCESS_READ | DUPLICATE_SHARE_DENYNONE;
+        }
+        else    dwOdinOptions = DUPLICATE_ACCESS_READWRITE | DUPLICATE_SHARE_DENYNONE;
 
         if(HMDuplicateHandleOdin(mProcessId, hMemFile, GetCurrentProcess(),
@@ -119,28 +119,28 @@
 #endif
         {
-        dprintf(("Win32MemMap::Init: DuplicateHandle failed!"));
-        goto fail;
-        }
-    mSize = SetFilePointer(hMemFile, 0, NULL, FILE_BEGIN);
-    mSize = SetFilePointer(hMemFile, 0, NULL, FILE_END);
-    if(mSize == -1) {
-        dprintf(("Win32MemMap::init: SetFilePointer failed to set pos end"));
-        goto fail;
-    }
-    //SvL: Temporary limitation of size (Warp Server Advanced doesn't allow
+            dprintf(("Win32MemMap::Init: DuplicateHandle failed!"));
+            goto fail;
+        }
+        mSize = SetFilePointer(hMemFile, 0, NULL, FILE_BEGIN);
+        mSize = SetFilePointer(hMemFile, 0, NULL, FILE_END);
+        if(mSize == -1) {
+            dprintf(("Win32MemMap::init: SetFilePointer failed to set pos end"));
+            goto fail;
+        }
+        //SvL: Temporary limitation of size (Warp Server Advanced doesn't allow
         //     one to reserve more than 450 MB (unless you override the virtual
         //     memory max limit) of continuous memory; (Warp 4 much less))
-    if(mSize > 64*1024*1024) {
-        mSize = 64*1024*1024;
-    }
-  }
-
-  dprintf(("CreateFileMappingA for file %x, prot %x size %d, name %s", hMemFile, mProtFlags, mSize, lpszMapName));
-  this->hMemMap = hMemMap;
-  mapMutex.leave();
-  return TRUE;
+        if(mSize > 64*1024*1024) {
+            mSize = 64*1024*1024;
+        }
+    }
+
+    dprintf(("CreateFileMappingA for file %x, prot %x size %d, name %s", hMemFile, mProtFlags, mSize, lpszMapName));
+    this->hMemMap = hMemMap;
+    mapMutex.leave();
+    return TRUE;
 fail:
-  mapMutex.leave();
-  return FALSE;
+    mapMutex.leave();
+    return FALSE;
 }
 //******************************************************************************
@@ -148,45 +148,45 @@
 Win32MemMap::~Win32MemMap()
 {
-  Win32MemMapView::deleteViews(this); //delete all views of our memory mapped file
-
-  dprintf(("Win32MemMap dtor: deleting view %x %x", pMapping, mSize));
-
-  mapMutex.enter();
-  if(lpszMapName) {
-    free(lpszMapName);
-  }
-  if(pMapping && !image) {
+    Win32MemMapView::deleteViews(this); //delete all views of our memory mapped file
+
+    dprintf(("Win32MemMap dtor: deleting view %x %x", pMapping, mSize));
+
+    mapMutex.enter();
     if(lpszMapName) {
-        OSLibDosFreeMem(pMapping);
-    }
-    else    VirtualFree(pMapping, mSize, MEM_RELEASE);
-
-    pMapping = NULL;
-  }
-  if(hMemFile != -1) {
-    dprintf(("Win32MemMap dtor: closing memory file %x", hMemFile));
-    CloseHandle(hMemFile);
-    hMemFile = -1;
-  }
-  mapMutex.leave();
-
-  globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
-  Win32MemMap *map = memmaps;
-
-  if(map == this) {
-    memmaps = next;
-  }
-  else {
-    while(map->next) {
-        if(map->next == this)
-            break;
-        map = map->next;
-    }
-    if(map->next) {
-         map->next = next;
-    }
-    else dprintf(("Win32MemMap::~Win32MemMap: map not found!! (%x)", this));
-  }
-  globalmapMutex.leave(&hGlobalMapMutex);
+        free(lpszMapName);
+    }
+    if(pMapping && !image) {
+        if(lpszMapName) {
+                OSLibDosFreeMem(pMapping);
+        }
+        else    VirtualFree(pMapping, 0, MEM_RELEASE);
+
+        pMapping = NULL;
+    }
+    if(hMemFile != -1) {
+        dprintf(("Win32MemMap dtor: closing memory file %x", hMemFile));
+        CloseHandle(hMemFile);
+        hMemFile = -1;
+    }
+    mapMutex.leave();
+
+    globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
+    Win32MemMap *map = memmaps;
+
+    if(map == this) {
+        memmaps = next;
+    }
+    else {
+        while(map->next) {
+            if(map->next == this)
+                break;
+            map = map->next;
+        }
+        if(map->next) {
+            map->next = next;
+        }
+        else dprintf(("Win32MemMap::~Win32MemMap: map not found!! (%x)", this));
+    }
+    globalmapMutex.leave(&hGlobalMapMutex);
 }
 //******************************************************************************
@@ -196,8 +196,11 @@
 void Win32MemMap::close()
 {
-  fClosed = TRUE;
-  if(nrMappings == 0) {
+#ifdef DEBUG
+    dprintf(("Win32MemMap::close %s", lpszMapName));
+#endif
+    fClosed = TRUE;
+    if(nrMappings == 0) {
         delete this;
-  }
+    }
 }
 //******************************************************************************
@@ -307,30 +310,30 @@
 BOOL Win32MemMap::unmapViewOfFile(Win32MemMapView *view)
 {
-  dprintf(("Win32MemMap::unmapViewOfFile %x (nrmaps=%d)", view, nrMappings));
-  mapMutex.enter();
-
-  if(nrMappings == 0)
-    goto fail;
-
-  delete view;
-
-  if(--nrMappings == 0) {
-    VirtualFree(pMapping, mSize, MEM_RELEASE);
-    pMapping = NULL;
-  }
-  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;
+    dprintf(("Win32MemMap::unmapViewOfFile %x (nrmaps=%d)", view, nrMappings));
+    mapMutex.enter();
+
+    if(nrMappings == 0)
+        goto fail;
+
+    delete view;
+
+    if(--nrMappings == 0) {
+        VirtualFree(pMapping, 0, MEM_RELEASE);
+        pMapping = NULL;
+    }
+    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:
-  mapMutex.leave();
-  if(nrMappings == 0 && fClosed) {
-    delete this;
-  }
-  return FALSE;
+    mapMutex.leave();
+    if(nrMappings == 0 && fClosed) {
+        delete this;
+    }
+    return FALSE;
 }
 //******************************************************************************
@@ -340,90 +343,90 @@
  DWORD processId = GetCurrentProcess();
 
-  mapMutex.enter();
-  ULONG memFlags = (mProtFlags & (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY));
-  ULONG fAlloc   = 0;
-  Win32MemMapView *mapview;
-
-  //@@@PH: if(fdwAccess & ~(FILE_MAP_WRITE|FILE_MAP_READ|FILE_MAP_COPY))
-  // Docs say FILE_MAP_ALL_ACCESS is same as FILE_MAP_WRITE. Doesn't match reality though.
-  if(fdwAccess & ~FILE_MAP_ALL_ACCESS)
-    goto parmfail;
-  if((fdwAccess & FILE_MAP_WRITE) && !(mProtFlags & PAGE_READWRITE))
-    goto parmfail;
-  if((fdwAccess & FILE_MAP_READ) && !(mProtFlags & (PAGE_READWRITE|PAGE_READONLY)))
-    goto parmfail;
-
-  //@@@PH
-  if (fdwAccess != FILE_MAP_ALL_ACCESS)
-    if((fdwAccess & FILE_MAP_COPY) && !(mProtFlags & PAGE_WRITECOPY))
-      goto parmfail;
-
-  if(offset+size > mSize && (!(fdwAccess & FILE_MAP_WRITE) || hMemFile == -1))
-    goto parmfail;
-
-  //SvL: TODO: Doesn't work for multiple views
-  if(offset+size > mSize) {
-    mSize = offset+size;
-  }
+    mapMutex.enter();
+    ULONG memFlags = (mProtFlags & (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY));
+    ULONG fAlloc   = 0;
+    Win32MemMapView *mapview;
+
+    //@@@PH: if(fdwAccess & ~(FILE_MAP_WRITE|FILE_MAP_READ|FILE_MAP_COPY))
+    // Docs say FILE_MAP_ALL_ACCESS is same as FILE_MAP_WRITE. Doesn't match reality though.
+    if(fdwAccess & ~FILE_MAP_ALL_ACCESS)
+        goto parmfail;
+    if((fdwAccess & FILE_MAP_WRITE) && !(mProtFlags & PAGE_READWRITE))
+        goto parmfail;
+    if((fdwAccess & FILE_MAP_READ) && !(mProtFlags & (PAGE_READWRITE|PAGE_READONLY)))
+        goto parmfail;
+
+    //@@@PH
+    if (fdwAccess != FILE_MAP_ALL_ACCESS)
+        if((fdwAccess & FILE_MAP_COPY) && !(mProtFlags & PAGE_WRITECOPY))
+        goto parmfail;
+
+    if(offset+size > mSize && (!(fdwAccess & FILE_MAP_WRITE) || hMemFile == -1))
+        goto parmfail;
+
+    //SvL: TODO: Doesn't work for multiple views
+    if(offset+size > mSize) {
+        mSize = offset+size;
+    }
 
 //TODO: If committed, read file into memory
 #if 0
-  if(mProtFlags & SEC_COMMIT)
-    fAlloc |= MEM_COMMIT;
-  else
-  if(mProtFlags & SEC_RESERVE)
-    fAlloc |= MEM_RESERVE;
+    if(mProtFlags & SEC_COMMIT)
+        fAlloc |= MEM_COMMIT;
+    else
+    if(mProtFlags & SEC_RESERVE)
+        fAlloc |= MEM_RESERVE;
 #else
-  fAlloc = MEM_RESERVE;
+    fAlloc = MEM_RESERVE;
 #endif
 
-  //Memory has already been allocated for executable image maps (only used internally)
-  if(!pMapping && nrMappings == 0) {//if not mapped, reserve/commit entire view
-    //SvL: Always read/write access or else ReadFile will crash once we
-    //     start committing pages.
-    //     This is most likely an OS/2 bug and doesn't happen in Aurora
+    //Memory has already been allocated for executable image maps (only used internally)
+    if(!pMapping && nrMappings == 0) {//if not mapped, reserve/commit entire view
+        //SvL: Always read/write access or else ReadFile will crash once we
+        //     start committing pages.
+        //     This is most likely an OS/2 bug and doesn't happen in Aurora
         //     when allocating memory with the PAG_ANY bit set. (without this
         //     flag it will also crash)
-    if(hMemFile == -1 && 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));
+        if(hMemFile == -1 && 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));
+            goto fail;
+        }
+        //Windows NT seems to commit memory for memory maps, regardsless of the SEC_COMMIT flag
+        if((hMemFile == -1 && !image)) {//commit memory
+            VirtualAlloc(pMapping, mSize, MEM_COMMIT, PAGE_READWRITE);
+        }
+        if(hMemFile != -1 && (mProtFlags & SEC_COMMIT)) {
+            DWORD nrPages = mSize >> PAGE_SHIFT;
+            if(mSize & 0xFFF)
+                nrPages++;
+
+            commitPage(0, FALSE, nrPages);
+        }
+    }
+    mapview = new Win32MemMapView(this, offset, (size == 0) ? mSize : size, fdwAccess);
+    if(mapview == NULL) {
         goto fail;
     }
-    //Windows NT seems to commit memory for memory maps, regardsless of the SEC_COMMIT flag
-    if((hMemFile == -1 && !image)) {//commit memory
-        VirtualAlloc(pMapping, mSize, MEM_COMMIT, PAGE_READWRITE);
-    }
-    if(hMemFile != -1 && (mProtFlags & SEC_COMMIT)) {
-        DWORD nrPages = mSize >> PAGE_SHIFT;
-        if(mSize & 0xFFF)
-            nrPages++;
-
-        commitPage(0, FALSE, nrPages);
-    }
-  }
-  mapview = new Win32MemMapView(this, offset, (size == 0) ? mSize : size, fdwAccess);
-  if(mapview == NULL) {
-    goto fail;
-  }
-  if(mapview->everythingOk() == FALSE) {
-    dprintf(("Win32MemMap::mapFileView: !mapview->everythingOk"));
-    delete mapview;
-    goto fail;
-  }
-  nrMappings++;
-  mapMutex.leave();
-  return mapview->getViewAddr();
+    if(mapview->everythingOk() == FALSE) {
+        dprintf(("Win32MemMap::mapFileView: !mapview->everythingOk"));
+        delete mapview;
+        goto fail;
+    }
+    nrMappings++;
+    mapMutex.leave();
+    return mapview->getViewAddr();
 
 parmfail:
-  dprintf(("Win32MemMap::mapFileView: ERROR_INVALID_PARAMETER"));
-  SetLastError(ERROR_INVALID_PARAMETER);
+    dprintf(("Win32MemMap::mapFileView: ERROR_INVALID_PARAMETER"));
+    SetLastError(ERROR_INVALID_PARAMETER);
 fail:
-  mapMutex.leave();
-  return 0;
+    mapMutex.leave();
+    return 0;
 }
 //******************************************************************************
@@ -586,99 +589,104 @@
  Win32MemMapView *tmpview  = mapviews;
 
-  errorState = 0;
-  mParentMap = map;
-  mSize    = size;
-  mOffset  = offset;
-  mProcessId = GetCurrentProcess();
-
-  switch(fdwAccess) {
-  case FILE_MAP_READ:
-    accessAttr = PAG_READ;
-    mfAccess   = MEMMAP_ACCESS_READ;
-    break;
-  case FILE_MAP_ALL_ACCESS:
-  case FILE_MAP_WRITE:
-  case FILE_MAP_WRITE|FILE_MAP_READ:
-  case FILE_MAP_COPY:
-    accessAttr = (PAG_READ|PAG_WRITE);
-    mfAccess   = MEMMAP_ACCESS_READ | MEMMAP_ACCESS_WRITE;
-    break;
-  }
-  if(map->getMemName() != NULL && map->getFileHandle() == -1) {
-    //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;
+    errorState = 0;
+    mParentMap = map;
+    mSize    = size;
+    mOffset  = offset;
+    mProcessId = GetCurrentProcess();
+    pShareViewAddr = NULL;
+
+    switch(fdwAccess) {
+    case FILE_MAP_READ:
+        accessAttr = PAG_READ;
+        mfAccess   = MEMMAP_ACCESS_READ;
+        break;
+    case FILE_MAP_ALL_ACCESS:
+    case FILE_MAP_WRITE:
+    case FILE_MAP_WRITE|FILE_MAP_READ:
+    case FILE_MAP_COPY:
+        accessAttr = (PAG_READ|PAG_WRITE);
+        mfAccess   = MEMMAP_ACCESS_READ | MEMMAP_ACCESS_WRITE;
+        break;
+    }
+    if(map->getMemName() != NULL && map->getFileHandle() == -1) {
+        //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;
+        }
+        pShareViewAddr = viewaddr;
+    }
+
+    //view == memory mapping for executable images (only used internally)
+    if(map->getImage()) {
+        pMapView = map->getMappingAddr();
+    }
+    else {
+        if(OSLibDosAliasMem(viewaddr, size, &pMapView, accessAttr) != OSLIB_NOERROR) {
+            dprintf(("new OSLibDosAliasMem FAILED"));
+            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+            errorState = 1;
+            return;
+        }
+    }
+    dprintf(("Win32MemMapView::Win32MemMapView: created %x (alias for %x), size %d", pMapView, viewaddr, size));
+
+    globalviewMutex.enter();
+    if(tmpview == NULL || tmpview->getViewAddr() > pMapView) {
+        next     = mapviews;
+        mapviews = this;
+    }
+    else {
+        while(tmpview->next) {
+            if(tmpview->next->getViewAddr() > pMapView) {
+                break;
+            }
+            tmpview = tmpview->next;
+        }
+        next          = tmpview->next;
+        tmpview->next = this;
+    }
+    globalviewMutex.leave();
+}
+//******************************************************************************
+//******************************************************************************
+Win32MemMapView::~Win32MemMapView()
+{
+    if(errorState != 0)
         return;
-    }
-  }
-
-  //view == memory mapping for executable images (only used internally)
-  if(map->getImage()) {
-    pMapView = map->getMappingAddr();
-  }
-  else {
-    if(OSLibDosAliasMem(viewaddr, size, &pMapView, accessAttr) != OSLIB_NOERROR) {
-        dprintf(("new OSLibDosAliasMem FAILED"));
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        errorState = 1;
-        return;
-    }
-  }
-
-  dprintf(("Win32MemMapView::Win32MemMapView: created %x (alias for %x), size %d", pMapView, viewaddr, size));
-
-  globalviewMutex.enter();
-  if(tmpview == NULL || tmpview->getViewAddr() > pMapView) {
-    next     = mapviews;
-    mapviews = this;
-  }
-  else {
-    while(tmpview->next) {
-        if(tmpview->next->getViewAddr() > pMapView) {
-            break;
-        }
-        tmpview = tmpview->next;
-    }
-    next          = tmpview->next;
-    tmpview->next = this;
-  }
-  globalviewMutex.leave();
-}
-//******************************************************************************
-//******************************************************************************
-Win32MemMapView::~Win32MemMapView()
-{
-  if(errorState != 0)
-    return;
-
-  dprintf(("Win32MemMapView dtor: deleting view %x %x", mOffset, mSize));
-
-  if(mfAccess & MEMMAP_ACCESS_WRITE)
-    mParentMap->flushView(mOffset, mSize);
-
-  //Don't free memory for executable image map views (only used internally)
-  if(!mParentMap->getImage())
-    OSLibDosFreeMem(pMapView);
-
-  globalviewMutex.enter();
-  Win32MemMapView *view = mapviews;
-
-  if(view == this) {
-    mapviews = next;
-  }
-  else {
-    while(view->next) {
-        if(view->next == this)
-            break;
-        view = view->next;
-    }
-    if(view->next) {
-        view->next = next;
-    }
-    else    dprintf(("Win32MemMapView::~Win32MemMapView: map not found!! (%x)", this));
-  }
-  globalviewMutex.leave();
+
+    dprintf(("Win32MemMapView dtor: deleting view %x %x", mOffset, mSize));
+
+    if(mfAccess & MEMMAP_ACCESS_WRITE)
+        mParentMap->flushView(mOffset, mSize);
+
+    //Don't free memory for executable image map views (only used internally)
+    if(!mParentMap->getImage())
+        OSLibDosFreeMem(pMapView);
+
+    if(pShareViewAddr) {
+        OSLibDosFreeMem(pShareViewAddr);
+    }
+
+    globalviewMutex.enter();
+    Win32MemMapView *view = mapviews;
+
+    if(view == this) {
+        mapviews = next;
+    }
+    else {
+        while(view->next) {
+            if(view->next == this)
+                break;
+            view = view->next;
+        }
+        if(view->next) {
+                view->next = next;
+        }
+        else    dprintf(("Win32MemMapView::~Win32MemMapView: map not found!! (%x)", this));
+    }
+    globalviewMutex.leave();
 }
 //******************************************************************************
Index: trunk/src/kernel32/mmap.h
===================================================================
--- trunk/src/kernel32/mmap.h	(revision 4794)
+++ trunk/src/kernel32/mmap.h	(revision 4796)
@@ -1,3 +1,3 @@
-/* $Id: mmap.h,v 1.17 2000-10-18 17:09:33 sandervl Exp $ */
+/* $Id: mmap.h,v 1.18 2000-12-12 23:57:16 sandervl Exp $ */
 
 /*
@@ -17,16 +17,16 @@
 
 #ifndef PAGE_SIZE
-#define PAGE_SIZE   	4096
+#define PAGE_SIZE       4096
 #endif
 #ifndef PAGE_SHIFT
-#define PAGE_SHIFT	12
+#define PAGE_SHIFT  12
 #endif
 
 //commit 4 pages at once when the app accesses it
-#define NRPAGES_TOCOMMIT	16
+#define NRPAGES_TOCOMMIT    16
 
-#define MEMMAP_ACCESS_READ	1
-#define MEMMAP_ACCESS_WRITE	2
-#define MEMMAP_ACCESS_EXECUTE	4
+#define MEMMAP_ACCESS_READ  1
+#define MEMMAP_ACCESS_WRITE 2
+#define MEMMAP_ACCESS_EXECUTE   4
 
 class Win32MemMapView;
@@ -73,21 +73,21 @@
 
 #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);
-	}
+    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);
-	}
+    void *operator new(size_t size)
+    {
+        return _umalloc(sharedHeap, size);
+    }
+    void operator delete(void *location)
+    {
+        free(location);
+    }
 #endif
 
@@ -112,5 +112,5 @@
 private:
    static Win32MemMap *memmaps;
-	  Win32MemMap *next;
+      Win32MemMap *next;
 };
 //******************************************************************************
@@ -138,21 +138,21 @@
 
 #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);
-	}
+    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);
-	}
+    void *operator new(size_t size)
+    {
+        return _umalloc(sharedHeap, size);
+    }
+    void operator delete(void *location)
+    {
+        free(location);
+    }
 #endif
 
@@ -161,5 +161,5 @@
    ULONG  mProcessId;
    ULONG  mfAccess, mOffset;
-   void  *pMapView;
+   void  *pMapView, *pShareViewAddr;
 
    Win32MemMap *mParentMap;
Index: trunk/src/kernel32/virtual.cpp
===================================================================
--- trunk/src/kernel32/virtual.cpp	(revision 4794)
+++ trunk/src/kernel32/virtual.cpp	(revision 4796)
@@ -1,3 +1,3 @@
-/* $Id: virtual.cpp,v 1.37 2000-11-14 21:16:26 sandervl Exp $ */
+/* $Id: virtual.cpp,v 1.38 2000-12-12 23:57:16 sandervl Exp $ */
 
 /*
@@ -453,4 +453,5 @@
   if ( (FreeType & MEM_RELEASE) && (cbSize   != 0) )
   {
+    dprintf(("WARNING: VirtualFree: invalid parameter!!"));
     SetLastError(ERROR_INVALID_PARAMETER);
     return(FALSE);
@@ -460,4 +461,5 @@
        (FreeType & MEM_RELEASE) )
   {
+    dprintf(("WARNING: VirtualFree: invalid parameter!!"));
     SetLastError(ERROR_INVALID_PARAMETER);
     return(FALSE);
Index: trunk/src/kernel32/wintls.cpp
===================================================================
--- trunk/src/kernel32/wintls.cpp	(revision 4794)
+++ trunk/src/kernel32/wintls.cpp	(revision 4796)
@@ -1,3 +1,3 @@
-/* $Id: wintls.cpp,v 1.16 2000-11-21 11:35:09 sandervl Exp $ */
+/* $Id: wintls.cpp,v 1.17 2000-12-12 23:57:16 sandervl Exp $ */
 /*
  * Win32 TLS API functions
@@ -128,5 +128,5 @@
    tlsmem = TlsGetValue(tlsIndex);
    if(tlsmem) {
-        VirtualFree(tlsmem, tlsTotalSize, MEM_RELEASE);
+        VirtualFree(tlsmem, 0, MEM_RELEASE);
    }
    else {
