Changeset 1811 for trunk/src/kernel32/mmap.cpp
- Timestamp:
- Nov 22, 1999, 9:35:52 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/mmap.cpp
r1687 r1811 1 /* $Id: mmap.cpp,v 1.2 2 1999-11-10 14:16:01sandervl Exp $ */1 /* $Id: mmap.cpp,v 1.23 1999-11-22 20:35:50 sandervl Exp $ */ 2 2 3 3 /* … … 29 29 #include "mmap.h" 30 30 #include "oslibdos.h" 31 #include <winimagepeldr.h> 31 32 32 33 //Global DLL Data … … 42 43 //****************************************************************************** 43 44 Win32MemMap::Win32MemMap(HFILE hfile, ULONG size, ULONG fdwProtect, LPSTR lpszName) 44 : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0) 45 : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0), image(0) 45 46 { 46 47 globalmapMutex.enter(); … … 60 61 } 61 62 else lpszMapName = NULL; 63 } 64 //****************************************************************************** 65 //Map constructor used for executable image maps (only used internally) 66 //****************************************************************************** 67 Win32MemMap::Win32MemMap(Win32PeLdrImage *pImage, ULONG baseAddress, ULONG size) 68 : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0) 69 { 70 globalmapMutex.enter(); 71 next = memmaps; 72 memmaps = this; 73 globalmapMutex.leave(); 74 75 hMemFile = -1; 76 77 mSize = size; 78 mProtFlags = PAGE_READWRITE; 79 mProcessId = GetCurrentProcess(); 80 81 pMapping = (LPVOID)baseAddress; 82 83 image = pImage; 84 lpszMapName= NULL; 62 85 } 63 86 //****************************************************************************** … … 107 130 free(lpszMapName); 108 131 } 109 if(pMapping ) {132 if(pMapping && !image) { 110 133 if(lpszMapName) { 111 134 OSLibDosFreeMem(pMapping); … … 154 177 // mapMutex.enter(); 155 178 179 if(image) { 180 return image->commitPage(pageAddr, fWriteAccess); 181 } 156 182 newProt = mProtFlags & (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY); 157 183 … … 199 225 goto fail; 200 226 } 201 if(mProtFlags & PAGE_READONLY) {227 if(mProtFlags != PAGE_READWRITE) { 202 228 if(VirtualProtect((LPVOID)pageAddr, memInfo.RegionSize, newProt, &oldProt) == FALSE) { 203 229 goto fail; … … 211 237 goto fail; 212 238 } 213 if(VirtualAlloc((LPVOID)pageAddr, memInfo.RegionSize, MEM_COMMIT, newProt) == FALSE) { 214 goto fail; 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) 242 goto fail; 215 243 } 216 244 } … … 282 310 #endif 283 311 284 if(nrMappings == 0) {//if not mapped, reserve/commit entire view 312 //Memory has already been allocated for executable image maps (only used internally) 313 if(!pMapping && nrMappings == 0) {//if not mapped, reserve/commit entire view 285 314 //SvL: Always read/write access or else ReadFile will crash once we 286 315 // start committing pages. … … 332 361 ULONG nrBytesWritten, size; 333 362 int i; 363 364 if(image) //no flushing for image maps 365 return TRUE; 334 366 335 367 dprintf(("Win32MemMap::flushView: %x %x", lpvBase, cbFlush)); … … 447 479 nextmap = map->next; 448 480 if(map->getProcessId() == processId) { 449 CloseHandle(memmaps->hMemMap); 481 //Delete map directly for executable images (only used internally) 482 if(map->getImage()) { 483 delete map; 484 } 485 else CloseHandle(memmaps->hMemMap); 450 486 } 451 487 else { … … 492 528 } 493 529 494 if(OSLibDosAliasMem(viewaddr, size, &pMapView, accessAttr) != OSLIB_NOERROR) { 495 dprintf(("new OSLibDosAliasMem FAILED")); 496 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 497 errorState = 1; 498 return; 530 //view == memory mapping for executable images (only used internally) 531 if(map->getImage()) { 532 pMapView = map->getMappingAddr(); 533 } 534 else { 535 if(OSLibDosAliasMem(viewaddr, size, &pMapView, accessAttr) != OSLIB_NOERROR) { 536 dprintf(("new OSLibDosAliasMem FAILED")); 537 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 538 errorState = 1; 539 return; 540 } 499 541 } 500 542 … … 530 572 mParentMap->flushView(mOffset, mSize); 531 573 532 OSLibDosFreeMem(pMapView); 574 //Don't free memory for executable image map views (only used internally) 575 if(!mParentMap->getImage()) 576 OSLibDosFreeMem(pMapView); 533 577 534 578 globalviewMutex.enter();
Note:
See TracChangeset
for help on using the changeset viewer.