Changeset 9824 for trunk/src/kernel32/mmap.cpp
- Timestamp:
- Feb 18, 2003, 7:48:55 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.