Ignore:
Timestamp:
Feb 5, 2000, 3:09:32 PM (26 years ago)
Author:
sandervl
Message:

memory map fixes

File:
1 edited

Legend:

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

    r2264 r2658  
    1 /* $Id: mmap.cpp,v 1.31 1999-12-30 11:19:53 sandervl Exp $ */
     1/* $Id: mmap.cpp,v 1.32 2000-02-05 14:09:31 sandervl Exp $ */
    22
    33/*
     
    1616 * TODO: Handles returned should be usable by all apis that accept file handles
    1717 * TODO: Sharing memory mapped files between multiple processes
     18 * TODO: Memory mapped files with views that extend the file (not 100% correct now)
    1819 *
    1920 * Project Odin Software License can be found in LICENSE.TXT
     
    103104        }
    104105        //SvL: Temporary limitation of size (Warp Server Advanced doesn't allow
    105         //     one to reserve more than 450 MB of continuous memory; (Warp 4
    106         //     much less))
     106        //     one to reserve more than 450 MB (unless you override the virtual
     107        //     memory max limit) of continuous memory; (Warp 4 much less))
    107108        if(mSize > 64*1024*1024) {
    108109                mSize = 64*1024*1024;
     
    209210                                goto fail;
    210211                        }
    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;
     212                        if(!fWriteAccess) {
     213                                offset = pageAddr - (ULONG)pMapping;
     214                                size   = memInfo.RegionSize;
     215                                if(offset + size > mSize) {
     216                                        dprintf(("Adjusting size from %d to %d", size, mSize - offset));
     217                                        size = mSize - offset;
     218                                }
     219                                if(SetFilePointer(hMemFile, offset, NULL, FILE_BEGIN) != offset) {
     220                                        dprintf(("Win32MemMap::commitPage: SetFilePointer failed to set pos to %x", offset));
     221                                        goto fail;
     222                                }
     223                                if(ReadFile(hMemFile, (LPSTR)pageAddr, size, &nrBytesRead, NULL) == FALSE) {
     224                                        dprintf(("Win32MemMap::commitPage: ReadFile failed for %x", pageAddr));
     225                                        goto fail;
     226                                }
     227                                if(nrBytesRead != size) {
     228                                        dprintf(("Win32MemMap::commitPage: ReadFile didn't read all bytes for %x", pageAddr));
     229                                        goto fail;
     230                                }
    228231                        }
    229232                        if(mProtFlags != PAGE_READWRITE) {
    230                                 if(VirtualProtect((LPVOID)pageAddr, memInfo.RegionSize, newProt, &oldProt) == FALSE) {
     233                                if(VirtualProtect((LPVOID)pageAddr, memInfo.RegionSize, newProt, &oldProt) == FALSE) {
    231234                                        goto fail;
    232235                                }
     
    306309      goto parmfail;
    307310
    308   if(offset+size > mSize)
     311  if(offset+size > mSize && (!(fdwAccess & FILE_MAP_WRITE) || !hMemFile))
    309312        goto parmfail;
     313
     314  //SvL: TODO: Doesn't work for multiple views
     315  if(offset+size > mSize) {
     316        mSize = offset+size;
     317  }
    310318
    311319//TODO: If committed, read file into memory
     
    327335        //     when allocating memory with the PAG_ANY bit set. (without this
    328336        //     flag it will also crash)
    329         if(lpszMapName) {
     337        if(!hMemFile && lpszMapName) {
    330338                pMapping = VirtualAllocShared(mSize, fAlloc, PAGE_READWRITE, lpszMapName);
    331339        }
     
    536544  case FILE_MAP_ALL_ACCESS:
    537545  case FILE_MAP_WRITE:
     546  case FILE_MAP_WRITE|FILE_MAP_READ:
    538547  case FILE_MAP_COPY:
    539548        accessAttr = (PAG_READ|PAG_WRITE);
     
    541550        break;
    542551  }
    543   if(map->getMemName() != NULL) {
     552  if(map->getMemName() != NULL && !map->getFileHandle()) {
    544553        //shared memory map, so map it into our address space
    545554        if(OSLibDosGetNamedSharedMem((LPVOID *)&viewaddr, map->getMemName()) != OSLIB_NOERROR) {
Note: See TracChangeset for help on using the changeset viewer.