Changeset 2658 for trunk/src/kernel32/mmap.cpp
- Timestamp:
- Feb 5, 2000, 3:09:32 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/mmap.cpp
r2264 r2658 1 /* $Id: mmap.cpp,v 1.3 1 1999-12-30 11:19:53sandervl Exp $ */1 /* $Id: mmap.cpp,v 1.32 2000-02-05 14:09:31 sandervl Exp $ */ 2 2 3 3 /* … … 16 16 * TODO: Handles returned should be usable by all apis that accept file handles 17 17 * TODO: Sharing memory mapped files between multiple processes 18 * TODO: Memory mapped files with views that extend the file (not 100% correct now) 18 19 * 19 20 * Project Odin Software License can be found in LICENSE.TXT … … 103 104 } 104 105 //SvL: Temporary limitation of size (Warp Server Advanced doesn't allow 105 // one to reserve more than 450 MB of continuous memory; (Warp 4106 // m uch 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)) 107 108 if(mSize > 64*1024*1024) { 108 109 mSize = 64*1024*1024; … … 209 210 goto fail; 210 211 } 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 } 228 231 } 229 232 if(mProtFlags != PAGE_READWRITE) { 230 233 if(VirtualProtect((LPVOID)pageAddr, memInfo.RegionSize, newProt, &oldProt) == FALSE) { 231 234 goto fail; 232 235 } … … 306 309 goto parmfail; 307 310 308 if(offset+size > mSize )311 if(offset+size > mSize && (!(fdwAccess & FILE_MAP_WRITE) || !hMemFile)) 309 312 goto parmfail; 313 314 //SvL: TODO: Doesn't work for multiple views 315 if(offset+size > mSize) { 316 mSize = offset+size; 317 } 310 318 311 319 //TODO: If committed, read file into memory … … 327 335 // when allocating memory with the PAG_ANY bit set. (without this 328 336 // flag it will also crash) 329 if( lpszMapName) {337 if(!hMemFile && lpszMapName) { 330 338 pMapping = VirtualAllocShared(mSize, fAlloc, PAGE_READWRITE, lpszMapName); 331 339 } … … 536 544 case FILE_MAP_ALL_ACCESS: 537 545 case FILE_MAP_WRITE: 546 case FILE_MAP_WRITE|FILE_MAP_READ: 538 547 case FILE_MAP_COPY: 539 548 accessAttr = (PAG_READ|PAG_WRITE); … … 541 550 break; 542 551 } 543 if(map->getMemName() != NULL ) {552 if(map->getMemName() != NULL && !map->getFileHandle()) { 544 553 //shared memory map, so map it into our address space 545 554 if(OSLibDosGetNamedSharedMem((LPVOID *)&viewaddr, map->getMemName()) != OSLIB_NOERROR) {
Note:
See TracChangeset
for help on using the changeset viewer.