- Timestamp:
- Feb 18, 2003, 7:48:55 PM (23 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/exceptions.cpp
r9315 r9824 1 /* $Id: exceptions.cpp,v 1.6 6 2002-10-01 11:37:19sandervl Exp $ */1 /* $Id: exceptions.cpp,v 1.67 2003-02-18 18:48:53 sandervl Exp $ */ 2 2 3 3 /* … … 1240 1240 map = Win32MemMapView::findMapByView(pERepRec->ExceptionInfo[1], &offset, accessflag); 1241 1241 if(map == NULL) { 1242 goto continueFail; 1243 } 1244 if(map->commitPage(offset, fWriteAccess) == TRUE) 1245 goto continueexecution; 1242 goto continueFail; 1243 } 1244 BOOL ret = map->commitPage(offset, fWriteAccess); 1245 map->Release(); 1246 if(ret == TRUE); 1247 goto continueexecution; 1246 1248 1247 1249 //no break; -
trunk/src/kernel32/hmdisk.cpp
r9663 r9824 1 /* $Id: hmdisk.cpp,v 1.6 0 2003-01-12 16:19:37sandervl Exp $ */1 /* $Id: hmdisk.cpp,v 1.61 2003-02-18 18:48:54 sandervl Exp $ */ 2 2 3 3 /* … … 1846 1846 1847 1847 map->commitPage(offset & ~0xfff, TRUE, nrpages); 1848 map->Release(); 1848 1849 } 1849 1850 else lpRealBuf = (LPVOID)lpBuffer; … … 2111 2112 2112 2113 map->commitPage(offset & ~0xfff, TRUE, nrpages); 2114 map->Release(); 2113 2115 } 2114 2116 else lpRealBuf = (LPVOID)lpBuffer; -
trunk/src/kernel32/hmfile.cpp
r9748 r9824 1 /* $Id: hmfile.cpp,v 1. 39 2003-02-04 11:28:57sandervl Exp $ */1 /* $Id: hmfile.cpp,v 1.40 2003-02-18 18:48:54 sandervl Exp $ */ 2 2 3 3 /* … … 534 534 535 535 map->commitPage(offset & ~0xfff, TRUE, nrpages); 536 map->Release(); 536 537 } 537 538 else lpRealBuf = (LPVOID)lpBuffer; … … 621 622 622 623 map->commitPage(offset & ~0xfff, TRUE, nrpages); 624 map->Release(); 623 625 } 624 626 else lpRealBuf = (LPVOID)lpBuffer; -
trunk/src/kernel32/hmmmap.cpp
r8456 r9824 1 /* $Id: hmmmap.cpp,v 1.2 0 2002-05-20 13:47:58sandervl Exp $ */1 /* $Id: hmmmap.cpp,v 1.21 2003-02-18 18:48:54 sandervl Exp $ */ 2 2 3 3 /* … … 74 74 map = Win32MemMap::findMap((LPSTR)name); 75 75 if(map != NULL) { 76 76 dprintf(("CreateFileMappingA: duplicating map %s!", name)); 77 77 78 78 DWORD protflags = map->getProtFlags(); … … 94 94 //Is it allowed to open an existing view with different flags? 95 95 //(i.e. write access to readonly object) 96 dprintf(("CreateFileMapping: duplicate handle of existing file mapping %s", name)); 96 // -> for the same file handle, yes 97 97 98 98 //if map already exists, we must create a new handle to the existing 99 99 //map object and return ERROR_ALREADY_EXISTS 100 map->AddRef();101 100 pHMHandleData->dwUserData = (ULONG)map; 102 101 pHMHandleData->dwInternalType = HMTYPE_MEMMAP; 102 103 //findMap already incremented the reference count, so we simply don't 104 //release it here 103 105 return ERROR_ALREADY_EXISTS; 104 106 } 107 108 #if 0 109 //We reuse the original memory map object if another one is created for 110 //the same file handle 111 //TODO: different file handles can exist for the same file (DuplicateHandle) 112 map = Win32MemMap::findMapByFile(hFile); 113 if(map) { 114 dprintf(("CreateFileMappingA: duplicating map with file %x!", hFile)); 115 116 //if map already exists, we must create a new handle to the existing 117 //map object 118 pHMHandleData->dwUserData = (ULONG)map; 119 pHMHandleData->dwInternalType = HMTYPE_MEMMAP; 120 121 //findMap already incremented the reference count, so we simply don't 122 //release it here 123 return ERROR_SUCCESS; 124 } 125 #endif 105 126 else { 106 127 map = new Win32MemMap(hFile, size_low, protect, (LPSTR)name); … … 131 152 Win32MemMap *map; 132 153 DWORD protflags; 154 DWORD ret; 133 155 134 156 if(name == NULL) … … 144 166 case FILE_MAP_WRITE: 145 167 case FILE_MAP_ALL_ACCESS: 146 if(!(protflags & (PAGE_WRITECOPY|PAGE_READWRITE))) 147 return ERROR_INVALID_PARAMETER; 168 if(!(protflags & (PAGE_WRITECOPY|PAGE_READWRITE))) { 169 ret = ERROR_INVALID_PARAMETER; 170 goto fail; 171 } 148 172 break; 149 173 case FILE_MAP_READ: 150 if(!(protflags & (PAGE_READWRITE | PAGE_READONLY))) 151 return ERROR_INVALID_PARAMETER; 174 if(!(protflags & (PAGE_READWRITE | PAGE_READONLY))) { 175 ret = ERROR_INVALID_PARAMETER; 176 goto fail; 177 } 152 178 break; 153 179 case FILE_MAP_COPY: 154 if(!(protflags & PAGE_WRITECOPY)) 155 return ERROR_INVALID_PARAMETER; 180 if(!(protflags & PAGE_WRITECOPY)) { 181 ret = ERROR_INVALID_PARAMETER; 182 goto fail; 183 } 156 184 break; 157 185 } 158 map->AddRef(); 186 //findMap already incremented the reference count, so we simply don't 187 //release it here 159 188 pHMHandleData->dwUserData = (ULONG)map; 160 189 pHMHandleData->dwInternalType = HMTYPE_MEMMAP; 161 190 return NO_ERROR; 191 192 fail: 193 map->Release(); 194 return ret; 162 195 } 163 196 //****************************************************************************** -
trunk/src/kernel32/mmap.cpp
r9489 r9824 1 /* $Id: mmap.cpp,v 1.6 0 2002-12-12 12:33:08sandervl Exp $ */1 /* $Id: mmap.cpp,v 1.61 2003-02-18 18:48:55 sandervl Exp $ */ 2 2 3 3 /* … … 70 70 } 71 71 //****************************************************************************** 72 //TODO: sharing between processes73 72 //****************************************************************************** 74 73 Win32MemMap::Win32MemMap(HFILE hfile, ULONG size, ULONG fdwProtect, LPSTR lpszName) … … 80 79 DosLeaveCriticalSection(&globalmapcritsect); 81 80 82 hMemFile 81 hMemFile = hOrgMemFile = hfile; 83 82 84 83 mSize = size; … … 103 102 DosLeaveCriticalSection(&globalmapcritsect); 104 103 105 hMemFile 104 hMemFile = hOrgMemFile = -1; 106 105 107 106 mSize = size; … … 216 215 } 217 216 DosLeaveCriticalSection(&globalmapcritsect); 217 } 218 //****************************************************************************** 219 // Win32MemMap::setProtFlags 220 // 221 // Change the protection flags of this memory map if required 222 // This is currently only used when creating a mapping for a file which already 223 // has an existing mapping. 224 // 225 // 226 // Parameters: 227 // 228 // DWORD dwNewProtect - new protection flags 229 // 230 // Returns: 231 // TRUE - success 232 // FALSE - failure 233 // 234 // NOTE: 235 // We're ignoring the SEC_* flags for now 236 // 237 //****************************************************************************** 238 BOOL Win32MemMap::setProtFlags(DWORD dwNewProtect) 239 { 240 if(!(dwNewProtect & (PAGE_READWRITE|PAGE_WRITECOPY))) return TRUE; //no need for changes 241 242 if(!(mProtFlags & PAGE_READWRITE)) 243 {//ok, current mapping is readonly; need to change it to readwrite 244 mProtFlags &= ~PAGE_READONLY; 245 mProtFlags |= PAGE_READWRITE; 246 247 //that's all we need to do for now; memory mappings are readwrite by 248 //default (see mapViewOfFile) 249 } 250 return TRUE; 218 251 } 219 252 //****************************************************************************** … … 330 363 } 331 364 //****************************************************************************** 332 //****************************************************************************** 333 BOOL Win32MemMap::unmapViewOfFile(Win32MemMapView *view) 334 { 335 dprintf(("Win32MemMap::unmapViewOfFile %x (nrmaps=%d)", view, nrMappings)); 365 // Win32MemMap::unmapViewOfFile 366 // 367 // Unmap the view identified by addr 368 // 369 // Parameters: 370 // 371 // LPVOID addr - view address; doesn't need to be the address 372 // returned by MapViewOfFile(Ex) (as MSDN clearly says); 373 // can be any address within the view range 374 // 375 // Returns: 376 // TRUE - success 377 // FALSE - failure 378 // 379 //****************************************************************************** 380 BOOL Win32MemMap::unmapViewOfFile(LPVOID addr) 381 { 382 Win32MemMapView *view; 383 384 dprintf(("Win32MemMap::unmapViewOfFile %x (nrmaps=%d)", addr, nrMappings)); 336 385 mapMutex.enter(); 337 386 338 387 if(nrMappings == 0) 388 goto fail; 389 390 view = Win32MemMapView::findView((ULONG)addr); 391 if(view == NULL) 339 392 goto fail; 340 393 … … 355 408 fail: 356 409 mapMutex.leave(); 357 if(nrMappings == 0 && referenced == 0) {358 delete this;359 }360 410 return FALSE; 361 411 } … … 405 455 406 456 //Memory has already been allocated for executable image maps (only used internally) 407 if(!pMapping && nrMappings == 0) {//if not mapped, reserve/commit entire view 457 if(!pMapping && nrMappings == 0) 458 {//if not mapped, reserve/commit entire view 408 459 //SvL: Always read/write access or else ReadFile will crash once we 409 460 // start committing pages. … … 411 462 // when allocating memory with the PAG_ANY bit set. (without this 412 463 // flag it will also crash) 464 //NOTE: If this is ever changed, then we must update setProtFlags!!!! 465 413 466 //All named file mappings are shared (files & memory only) 414 467 if(lpszMapName) { … … 550 603 } 551 604 } 605 if(map) map->AddRef(); 606 552 607 DosLeaveCriticalSection(&globalmapcritsect); 553 608 if(!map) dprintf(("Win32MemMap::findMap: couldn't find map %s", lpszName)); 609 return map; 610 } 611 //****************************************************************************** 612 //****************************************************************************** 613 Win32MemMap *Win32MemMap::findMapByFile(HANDLE hFile) 614 { 615 if(hFile == -1) 616 return NULL; 617 618 DosEnterCriticalSection(&globalmapcritsect); 619 Win32MemMap *map = memmaps; 620 621 if(map != NULL) 622 { 623 while(map) { 624 if(map->hOrgMemFile == hFile) 625 break; 626 map = map->next; 627 } 628 } 629 if(map) map->AddRef(); 630 DosLeaveCriticalSection(&globalmapcritsect); 631 if(!map) dprintf(("Win32MemMap::findMapByFile: couldn't find map with file handle %x", hFile)); 554 632 return map; 555 633 } … … 571 649 } 572 650 } 651 if(map) map->AddRef(); 573 652 DosLeaveCriticalSection(&globalmapcritsect); 574 653 return map; … … 738 817 //****************************************************************************** 739 818 //****************************************************************************** 819 // Win32MemMap::findMapByView 820 // 821 // Find the map of the view that contains the specified starting address 822 // and has the specified access type 823 // 824 // Parameters: 825 // 826 // ULONG address - view address 827 // ULONG *offset - address of ULONG that receives the offset 828 // in the returned memory map 829 // ULONG accessType - access type: 830 // MEMMAP_ACCESS_READ 831 // MEMMAP_ACCESS_WRITE 832 // MEMMAP_ACCESS_EXECUTE 833 // 834 // Returns: 835 // <> NULL - success, address of parent map object 836 // NULL - failure 837 // 838 //****************************************************************************** 839 //****************************************************************************** 740 840 Win32MemMap *Win32MemMapView::findMapByView(ULONG address, 741 841 ULONG *offset, 742 ULONG accessType, 743 Win32MemMapView **pView) 744 { 842 ULONG accessType) 843 { 844 Win32MemMap *map = NULL; 845 ULONG ulOffset; 846 745 847 if(mapviews == NULL) return NULL; 746 848 … … 748 850 Win32MemMapView *view = mapviews; 749 851 ULONG ulViewAddr; 852 853 if(!offset) offset = &ulOffset; 750 854 751 855 *offset = 0; … … 782 886 view = NULL; 783 887 } 784 785 888 success: 786 889 #ifdef DEBUG … … 793 896 #endif 794 897 898 if(view) { 899 map = view->getParentMap(); 900 if(map) map->AddRef(); 901 } 902 795 903 DosLeaveCriticalSection(&globalmapcritsect); 796 904 797 if(pView) 798 *pView = view; 799 800 return (view) ? view->getParentMap() : NULL; 801 } 802 //****************************************************************************** 803 //****************************************************************************** 804 Win32MemMapView *Win32MemMapView::findView(LPVOID address) 805 { 905 return map; 906 } 907 //****************************************************************************** 908 // Win32MemMap::findView 909 // 910 // Find the view that contains the specified starting address 911 // 912 // Parameters: 913 // 914 // LPVOID address - view address 915 // 916 // Returns: 917 // <> NULL - success, address view object 918 // NULL - failure 919 // 920 //****************************************************************************** 921 Win32MemMapView *Win32MemMapView::findView(ULONG address) 922 { 923 ULONG ulViewAddr; 924 925 DosEnterCriticalSection(&globalmapcritsect); 806 926 Win32MemMapView *view = mapviews; 807 927 808 DosEnterCriticalSection(&globalmapcritsect);809 928 if(view != NULL) { 810 929 while(view) { 811 if(view->getViewAddr() == address) 930 ulViewAddr = (ULONG)view->getViewAddr(); 931 if(ulViewAddr <= address && ulViewAddr + view->getSize() > address) 812 932 { 813 933 break; … … 821 941 //****************************************************************************** 822 942 //****************************************************************************** 823 -
trunk/src/kernel32/mmap.h
r8913 r9824 1 /* $Id: mmap.h,v 1.2 4 2002-07-23 13:51:48sandervl Exp $ */1 /* $Id: mmap.h,v 1.25 2003-02-18 18:48:55 sandervl Exp $ */ 2 2 3 3 /* … … 26 26 27 27 //commit 4 pages at once when the app accesses it 28 #define NRPAGES_TOCOMMIT 1628 #define NRPAGES_TOCOMMIT 16 29 29 30 #define MEMMAP_ACCESS_READ 131 #define MEMMAP_ACCESS_WRITE 230 #define MEMMAP_ACCESS_READ 1 31 #define MEMMAP_ACCESS_WRITE 2 32 32 #define MEMMAP_ACCESS_EXECUTE 4 33 33 … … 48 48 BOOL flushView(ULONG offset, ULONG cbFlush); 49 49 LPVOID mapViewOfFile(ULONG size, ULONG offset, ULONG fdwAccess); 50 BOOL unmapViewOfFile( Win32MemMapView *view);50 BOOL unmapViewOfFile(LPVOID addr); 51 51 52 52 HFILE getFileHandle() { return hMemFile; }; 53 53 LPSTR getMemName() { return lpszMapName; }; 54 54 DWORD getProtFlags() { return mProtFlags; }; 55 BOOL setProtFlags(DWORD dwNewProtect); 55 56 LPVOID getMappingAddr() { return pMapping; }; 56 57 DWORD getProcessId() { return mProcessId;}; … … 65 66 66 67 static Win32MemMap *findMap(LPSTR lpszName); 68 static Win32MemMap *findMapByFile(HANDLE hFile); 67 69 static Win32MemMap *findMap(ULONG address); 68 70 … … 92 94 protected: 93 95 HFILE hMemFile; 96 HFILE hOrgMemFile; 94 97 ULONG mSize; 95 98 ULONG mProtFlags; … … 131 134 132 135 static void deleteViews(Win32MemMap *map); 133 static Win32MemMap *findMapByView(ULONG address, ULONG *offset, ULONG accessType, Win32MemMapView **pView=NULL); 134 static Win32MemMapView *findView(LPVOID address); 136 static Win32MemMap *findMapByView(ULONG address, ULONG *offset = NULL, 137 ULONG accessType = MEMMAP_ACCESS_READ); 138 static Win32MemMapView *findView(ULONG address); 135 139 136 140 #ifdef __DEBUG_ALLOC__ -
trunk/src/kernel32/virtual.cpp
r9546 r9824 1 /* $Id: virtual.cpp,v 1. 49 2002-12-27 15:25:40sandervl Exp $ */1 /* $Id: virtual.cpp,v 1.50 2003-02-18 18:48:55 sandervl Exp $ */ 2 2 3 3 /* … … 167 167 Win32MemMap *map; 168 168 DWORD offset; 169 BOOL ret; 169 170 170 171 if (!base) … … 178 179 return FALSE; 179 180 } 180 return map->flushView(offset, cbFlush); 181 ret = map->flushView(offset, cbFlush); 182 map->Release(); 183 return ret; 181 184 } 182 185 … … 196 199 ) 197 200 { 198 Win32MemMap *map; 199 Win32MemMapView *view; 200 201 DWORD offset; 201 Win32MemMap *map; 202 BOOL ret; 202 203 203 204 if (!addr) … … 206 207 return FALSE; 207 208 } 208 map = Win32MemMapView::findMapByView((ULONG)addr , &offset, MEMMAP_ACCESS_READ, &view);209 map = Win32MemMapView::findMapByView((ULONG)addr); 209 210 if(map == NULL) { 210 211 SetLastError( ERROR_FILE_NOT_FOUND ); 211 212 return FALSE; 212 213 } 213 return map->unmapViewOfFile(view); 214 ret = map->unmapViewOfFile(addr); 215 map->Release(); 216 return ret; 214 217 } 215 218 … … 350 353 //TODO: We don't allow protection flag changes for mmaped files now 351 354 map->commitPage(offset, FALSE, nrpages); 355 map->Release(); 352 356 return lpvAddress; 353 357 }
Note:
See TracChangeset
for help on using the changeset viewer.