Ignore:
Timestamp:
Dec 10, 1999, 3:06:12 PM (26 years ago)
Author:
sandervl
Message:

Memory map fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/mmap.cpp

    r2032 r2053  
    1 /* $Id: mmap.cpp,v 1.26 1999-12-09 00:52:21 sandervl Exp $ */
     1/* $Id: mmap.cpp,v 1.27 1999-12-10 14:06:12 sandervl Exp $ */
    22
    33/*
     
    174174 DWORD pageAddr         = (DWORD)lpPageFaultAddr & ~0xFFF;
    175175 DWORD oldProt, newProt, nrBytesRead, size;
     176 int i;
    176177
    177178//  mapMutex.enter();
     
    184185  dprintf(("Win32MemMap::commitPage %x (faultaddr %x)", pageAddr, lpPageFaultAddr));
    185186  if(hMemFile != -1) {
    186         if(VirtualQuery((LPSTR)pageAddr, &memInfo, nrpages*PAGE_SIZE) == 0) {
    187                 dprintf(("Win32MemMap::commitPage: VirtualQuery (%x,%x) failed for %x", pageAddr, nrpages*PAGE_SIZE));
    188                 goto fail;
    189         }
    190         //Only changes the state of the pages with the same attribute flags
    191         //(returned in memInfo.RegionSize)
    192         //If it's smaller than the mNrPages, it simply means one or more of the
    193         //other pages have already been committed
    194         if(memInfo.State & MEM_COMMIT)
    195         {//if it's already committed, then the app tried to write to it
    196                 if(!fWriteAccess) {
    197                         dprintf(("Win32MemMap::commitPage: Huh? Already committed and not trying to write (%x,%x) failed for %x", pageAddr, memInfo.RegionSize));
     187//      for(i=0;i<nrpages;i++) {
     188                if(VirtualQuery((LPSTR)pageAddr, &memInfo, nrpages*PAGE_SIZE) == 0) {
     189                        dprintf(("Win32MemMap::commitPage: VirtualQuery (%x,%x) failed for %x", pageAddr, nrpages*PAGE_SIZE));
    198190                        goto fail;
    199191                }
    200                 if(VirtualProtect((LPVOID)pageAddr, memInfo.RegionSize, newProt, &oldProt) == FALSE) {
    201                         dprintf(("Win32MemMap::commitPage: Failed to set write flag on page (%x,%x) failed for %x", pageAddr, memInfo.RegionSize));
    202                         goto fail;
    203                 }
    204         }
    205         else {
    206                 if(VirtualAlloc((LPVOID)pageAddr, memInfo.RegionSize, MEM_COMMIT, PAGE_READWRITE) == FALSE) {
    207                         goto fail;
    208                 }
    209                 offset = pageAddr - (ULONG)pMapping;
    210                 size   = memInfo.RegionSize;
    211                 if(offset + size > mSize) {
    212                         dprintf(("Adjusting size from %d to %d", size, mSize - offset));
    213                         size = mSize - offset;
    214                 }
    215                 if(SetFilePointer(hMemFile, offset, NULL, FILE_BEGIN) != offset) {
    216                         dprintf(("Win32MemMap::commitPage: SetFilePointer failed to set pos to %x", offset));
    217                         goto fail;
    218                 }
    219                 if(ReadFile(hMemFile, (LPSTR)pageAddr, size, &nrBytesRead, NULL) == FALSE) {
    220                         dprintf(("Win32MemMap::commitPage: ReadFile failed for %x", pageAddr));
    221                         goto fail;
    222                 }
    223                 if(nrBytesRead != size) {
    224                         dprintf(("Win32MemMap::commitPage: ReadFile didn't read all bytes for %x", pageAddr));
    225                         goto fail;
    226                 }
    227                 if(mProtFlags != PAGE_READWRITE) {
    228                         if(VirtualProtect((LPVOID)pageAddr, memInfo.RegionSize, newProt, &oldProt) == FALSE) {
     192                //Only changes the state of the pages with the same attribute flags
     193                //(returned in memInfo.RegionSize)
     194                //If it's smaller than the mNrPages, it simply means one or more of the
     195                //other pages have already been committed
     196                if(memInfo.State & MEM_COMMIT)
     197                {//if it's already committed, then the app tried to write to it
     198                        if(!fWriteAccess) {
     199                                dprintf(("Win32MemMap::commitPage: Huh? Already committed and not trying to write (%x,%x) failed for %x", pageAddr, memInfo.RegionSize));
    229200                                goto fail;
    230201                        }
    231                 }
    232         }
     202                        if(VirtualProtect((LPVOID)pageAddr, memInfo.RegionSize, newProt, &oldProt) == FALSE) {
     203                                dprintf(("Win32MemMap::commitPage: Failed to set write flag on page (%x,%x) failed for %x", pageAddr, memInfo.RegionSize));
     204                                goto fail;
     205                        }
     206                }
     207                else {
     208                        if(VirtualAlloc((LPVOID)pageAddr, memInfo.RegionSize, MEM_COMMIT, PAGE_READWRITE) == FALSE) {
     209                                goto fail;
     210                        }
     211                        offset = pageAddr - (ULONG)pMapping;
     212                        size   = memInfo.RegionSize;
     213                        if(offset + size > mSize) {
     214                                dprintf(("Adjusting size from %d to %d", size, mSize - offset));
     215                                size = mSize - offset;
     216                        }
     217                        if(SetFilePointer(hMemFile, offset, NULL, FILE_BEGIN) != offset) {
     218                                dprintf(("Win32MemMap::commitPage: SetFilePointer failed to set pos to %x", offset));
     219                                goto fail;
     220                        }
     221                        if(ReadFile(hMemFile, (LPSTR)pageAddr, size, &nrBytesRead, NULL) == FALSE) {
     222                                dprintf(("Win32MemMap::commitPage: ReadFile failed for %x", pageAddr));
     223                                goto fail;
     224                        }
     225                        if(nrBytesRead != size) {
     226                                dprintf(("Win32MemMap::commitPage: ReadFile didn't read all bytes for %x", pageAddr));
     227                                goto fail;
     228                        }
     229                        if(mProtFlags != PAGE_READWRITE) {
     230                                if(VirtualProtect((LPVOID)pageAddr, memInfo.RegionSize, newProt, &oldProt) == FALSE) {
     231                                        goto fail;
     232                                }
     233                        }
     234                }
     235//              pageAddr += PAGE_SIZE;
     236//      }
    233237  }
    234238  else {
    235         if(VirtualQuery((LPSTR)pageAddr, &memInfo, nrpages*PAGE_SIZE) == 0) {
    236                 dprintf(("Win32MemMap::commitPage: VirtualQuery (%x,%x) failed for %x", pageAddr, nrpages*PAGE_SIZE));
    237                 goto fail;
    238         }
    239         if(!(memInfo.State & MEM_COMMIT))
    240         {//if it's already committed, then the app tried to write to it
    241                 if(VirtualAlloc((LPVOID)pageAddr, memInfo.RegionSize, MEM_COMMIT, newProt) == FALSE)
     239        for(i=0;i<nrpages;i++) {
     240                if(VirtualQuery((LPSTR)pageAddr, &memInfo, PAGE_SIZE) == 0) {
     241                        dprintf(("Win32MemMap::commitPage: VirtualQuery (%x,%x) failed for %x", pageAddr, PAGE_SIZE));
    242242                        goto fail;
    243         }
     243                }
     244                if(!(memInfo.State & MEM_COMMIT))
     245                {//if it's already committed, then the app tried to write to it
     246                        if(VirtualAlloc((LPVOID)pageAddr, memInfo.RegionSize, MEM_COMMIT, newProt) == FALSE)
     247                                goto fail;
     248                }
     249                pageAddr += PAGE_SIZE;
     250        }
    244251  }
    245252
Note: See TracChangeset for help on using the changeset viewer.