- Timestamp:
- Mar 6, 2003, 11:44:34 AM (22 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/HandleManager.cpp
r9748 r9911 1 /* $Id: HandleManager.cpp,v 1.9 4 2003-02-04 11:28:55sandervl Exp $ */1 /* $Id: HandleManager.cpp,v 1.95 2003-03-06 10:44:32 sandervl Exp $ */ 2 2 3 3 /* … … 899 899 DWORD fdwAccess, 900 900 BOOL fInherit, 901 DWORD fdwOptions, 902 DWORD fdwOdinOptions) 901 DWORD fdwOptions) 903 902 { 904 903 int iIndex; /* index into the handle table */ … … 925 924 /* initialize the complete HMHANDLEDATA structure */ 926 925 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 927 if (fdwOptions & DUPLICATE_SAME_ACCESS) 926 if (fdwOptions & DUPLICATE_SAME_ACCESS) 928 927 pHMHandleData->dwAccess = TabWin32Handles[srchandle].hmHandleData.dwAccess; 929 928 else 930 929 pHMHandleData->dwAccess = fdwAccess; 931 930 932 if((fdwOdinOptions & DUPLICATE_ACCESS_READWRITE) == DUPLICATE_ACCESS_READWRITE) { 933 pHMHandleData->dwAccess = GENERIC_READ | GENERIC_WRITE; 934 } 935 else 936 if(fdwOdinOptions & DUPLICATE_ACCESS_READ) { 937 pHMHandleData->dwAccess = GENERIC_READ; 938 } 939 940 if(fdwOdinOptions & DUPLICATE_SHARE_READ) { 941 pHMHandleData->dwShare = FILE_SHARE_READ; 942 } 943 else 944 if(fdwOdinOptions & DUPLICATE_SHARE_DENYNONE) { 945 pHMHandleData->dwShare = FILE_SHARE_READ | FILE_SHARE_WRITE; 946 } 947 else pHMHandleData->dwShare = TabWin32Handles[srchandle].hmHandleData.dwShare; 948 931 pHMHandleData->dwShare = TabWin32Handles[srchandle].hmHandleData.dwShare; 949 932 pHMHandleData->dwCreation = TabWin32Handles[srchandle].hmHandleData.dwCreation; 950 933 pHMHandleData->dwFlags = TabWin32Handles[srchandle].hmHandleData.dwFlags; … … 967 950 fdwAccess, 968 951 fInherit, 969 fdwOptions & ~DUPLICATE_CLOSE_SOURCE, 970 fdwOdinOptions); 952 fdwOptions & ~DUPLICATE_CLOSE_SOURCE, 0); 971 953 972 954 //Don't let Open32 close it for us, but do it manually (regardless of error; see SDK docs)) -
trunk/src/kernel32/hmdisk.cpp
r9824 r9911 1 /* $Id: hmdisk.cpp,v 1.6 1 2003-02-18 18:48:54sandervl Exp $ */1 /* $Id: hmdisk.cpp,v 1.62 2003-03-06 10:44:33 sandervl Exp $ */ 2 2 3 3 /* … … 1839 1839 if(map) { 1840 1840 lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset); 1841 DWORD nrpages = nNumberOfBytesToRead/4096; 1842 if(offset & 0xfff) 1843 nrpages++; 1844 if(nNumberOfBytesToRead & 0xfff) 1841 DWORD nrpages = (nNumberOfBytesToRead+offset)/4096; 1842 if((nNumberOfBytesToRead+offset) & 0xfff) 1845 1843 nrpages++; 1846 1844 1847 map->commit Page(offset & ~0xfff, TRUE, nrpages);1845 map->commitRange((ULONG)lpBuffer, offset & ~0xfff, TRUE, nrpages); 1848 1846 map->Release(); 1849 1847 } … … 2105 2103 if(map) { 2106 2104 lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset); 2107 DWORD nrpages = nNumberOfBytesToWrite/4096; 2108 if(offset & 0xfff) 2109 nrpages++; 2110 if(nNumberOfBytesToWrite & 0xfff) 2105 DWORD nrpages = (nNumberOfBytesToWrite+offset)/4096; 2106 if((nNumberOfBytesToWrite+offset) & 0xfff) 2111 2107 nrpages++; 2112 2108 2113 map->commit Page(offset & ~0xfff, TRUE, nrpages);2109 map->commitRange((ULONG)lpBuffer, offset & ~0xfff, TRUE, nrpages); 2114 2110 map->Release(); 2115 2111 } -
trunk/src/kernel32/hmfile.cpp
r9824 r9911 1 /* $Id: hmfile.cpp,v 1.4 0 2003-02-18 18:48:54sandervl Exp $ */1 /* $Id: hmfile.cpp,v 1.41 2003-03-06 10:44:33 sandervl Exp $ */ 2 2 3 3 /* … … 527 527 if(map) { 528 528 lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset); 529 DWORD nrpages = nNumberOfBytesToRead/4096;530 if( offset& 0xfff)529 DWORD nrpages = (nNumberOfBytesToRead+offset)/4096; 530 if((nNumberOfBytesToRead+offset) & 0xfff) 531 531 nrpages++; 532 if(nNumberOfBytesToRead & 0xfff) 533 nrpages++; 534 535 map->commitPage(offset & ~0xfff, TRUE, nrpages); 532 533 map->commitRange((ULONG)lpBuffer, offset & ~0xfff, TRUE, nrpages); 536 534 map->Release(); 537 535 } 538 536 else lpRealBuf = (LPVOID)lpBuffer; 537 538 //If this file is also used in a memory map somewhere, then we need 539 //to tell the map to flush all modified contents to disk right NOW 540 map = Win32MemMap::findMapByFile(pHMHandleData->hWin32Handle); 541 if(map) { 542 DWORD curpos = SetFilePointer(pHMHandleData, 0, NULL, FILE_CURRENT); 543 544 dprintf(("Flush memory maps to disk before reading!!")); 545 map->flushView(MMAP_FLUSHVIEW_ALL, curpos, nNumberOfBytesToRead); 546 } 539 547 540 548 if(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) { … … 615 623 if(map) { 616 624 lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset); 617 DWORD nrpages = nNumberOfBytesToWrite/4096; 618 if(offset & 0xfff) 619 nrpages++; 620 if(nNumberOfBytesToWrite & 0xfff) 625 DWORD nrpages = (nNumberOfBytesToWrite+offset)/4096; 626 if((nNumberOfBytesToWrite+offset) & 0xfff) 621 627 nrpages++; 622 628 623 map->commit Page(offset & ~0xfff, TRUE, nrpages);629 map->commitRange((ULONG)lpBuffer, offset & ~0xfff, TRUE, nrpages); 624 630 map->Release(); 625 631 } 626 632 else lpRealBuf = (LPVOID)lpBuffer; 633 634 //If this file is also used in a memory map somewhere, then we need 635 //to tell the map to flush all modified contents to disk right NOW 636 DWORD curfilepos; 637 map = Win32MemMap::findMapByFile(pHMHandleData->hWin32Handle); 638 if(map) { 639 curfilepos = SetFilePointer(pHMHandleData, 0, NULL, FILE_CURRENT); 640 641 dprintf(("Flush memory maps to disk before writing!!")); 642 map->flushView(MMAP_FLUSHVIEW_ALL, curfilepos, nNumberOfBytesToWrite); 643 } 627 644 628 645 if(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) { … … 635 652 lpNumberOfBytesWritten); 636 653 // } 654 655 if(map && bRC) { 656 dprintf(("Invalidate memory map after file writing!!")); 657 map->invalidatePages(curfilepos, *lpNumberOfBytesWritten); 658 } 637 659 638 660 dprintf(("KERNEL32: HMDeviceFileClass::WriteFile returned %08xh\n", -
trunk/src/kernel32/kernel32.mak
r9910 r9911 1 # $Id: kernel32.mak,v 1.4 1 2003-03-06 10:22:27sandervl Exp $1 # $Id: kernel32.mak,v 1.42 2003-03-06 10:44:33 sandervl Exp $ 2 2 3 3 # … … 100 100 $(OBJDIR)\time.obj \ 101 101 $(OBJDIR)\mmap.obj \ 102 $(OBJDIR)\mmapview.obj \103 $(OBJDIR)\mmapdup.obj \104 102 $(OBJDIR)\winimagepe2lx.obj \ 105 103 $(OBJDIR)\winimagepeldr.obj \ -
trunk/src/kernel32/mmap.cpp
r9826 r9911 1 /* $Id: mmap.cpp,v 1.6 2 2003-02-18 18:58:47sandervl Exp $ */1 /* $Id: mmap.cpp,v 1.63 2003-03-06 10:44:34 sandervl Exp $ */ 2 2 3 3 /* … … 126 126 &hMemFile, 0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE) 127 127 #else 128 DWORD dwOdinOptions; 129 130 if(!(mProtFlags & PAGE_READWRITE)) { 131 dwOdinOptions = DUPLICATE_ACCESS_READ | DUPLICATE_SHARE_DENYNONE; 132 } 133 else dwOdinOptions = DUPLICATE_ACCESS_READWRITE | DUPLICATE_SHARE_DENYNONE; 134 135 if(HMDuplicateHandleOdin(GetCurrentProcess(), hMemFile, GetCurrentProcess(), 136 &hMemFile, 0, FALSE, DUPLICATE_SAME_ACCESS, dwOdinOptions) == FALSE) 128 if(HMDuplicateHandle(GetCurrentProcess(), hMemFile, GetCurrentProcess(), 129 &hMemFile, 0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE) 137 130 #endif 138 131 { … … 265 258 } 266 259 //****************************************************************************** 267 //We determine whether a page has been modified by checking it's protection flags 268 //If the write flag is set, this means commitPage had to enable this due to a pagefault 269 //(all pages are readonly until the app tries to write to it) 270 //****************************************************************************** 271 BOOL Win32MemMap::commitPage(ULONG offset, BOOL fWriteAccess, int nrpages) 260 // Win32MemMap::commitRange 261 // 262 // Commit a range of pages 263 // 264 // Parameters: 265 // 266 // ULONG ulFaultAddr - exception address 267 // ULONG ulOffset - offset in memory map 268 // BOOL fWriteAccess - TRUE -> write exception 269 // FALSE -> read exception 270 // int nrpages - number of pages 271 // 272 // Returns: 273 // TRUE - success 274 // FALSE - failure 275 // 276 //****************************************************************************** 277 BOOL Win32MemMap::commitRange(ULONG ulFaultAddr, ULONG offset, BOOL fWriteAccess, int nrpages) 278 { 279 LPVOID lpPageFaultAddr = (LPVOID)((ULONG)pMapping + offset); 280 DWORD pageAddr = (DWORD)lpPageFaultAddr & ~0xFFF; 281 282 dprintf(("Win32MemMap::commitRange %x (faultaddr %x)", pageAddr, lpPageFaultAddr)); 283 284 if(fWriteAccess) 285 {//writes are handled on a per-page basis 286 for(int i=i;i<nrpages;i++) 287 { 288 if(commitPage(ulFaultAddr, offset, TRUE, 1) == FALSE) { 289 dprintf(("Win32MemMap::commit: commitPage failed!!")); 290 return FALSE; 291 } 292 ulFaultAddr += PAGE_SIZE; 293 offset += PAGE_SIZE; 294 } 295 return TRUE; 296 } 297 else return commitPage(ulFaultAddr, offset, FALSE, nrpages); 298 } 299 //****************************************************************************** 300 // Win32MemMap::commitPage 301 // 302 // Handle a pagefault for a memory map 303 // 304 // Parameters: 305 // 306 // ULONG ulFaultAddr - exception address 307 // ULONG ulOffset - offset in memory map 308 // BOOL fWriteAccess - TRUE -> write exception 309 // FALSE -> read exception 310 // int nrpages - number of pages 311 // 312 // Returns: 313 // TRUE - success 314 // FALSE - failure 315 // 316 // NOTE: 317 // We handle only one pages for write access! 318 // 319 // REMARKS: 320 // We determine whether a page has been modified by checking it's protection flags 321 // If the write flag is set, this means commitPage had to enable this due to a pagefault 322 // (all pages are readonly until the app tries to write to it) 323 //****************************************************************************** 324 BOOL Win32MemMap::commitPage(ULONG ulFaultAddr, ULONG offset, BOOL fWriteAccess, int nrpages) 272 325 { 273 326 MEMORY_BASIC_INFORMATION memInfo; … … 365 418 } 366 419 //****************************************************************************** 420 // Win32MemMap::commitGuardPage 421 // 422 // Handle a guard page exception for a copy-on-write view (one page only) 423 // 424 // Parameters: 425 // 426 // ULONG ulFaultAddr - exception address 427 // ULONG ulOffset - offset in memory map 428 // BOOL fWriteAccess - TRUE -> write exception 429 // FALSE -> read exception 430 // 431 // Returns: 432 // TRUE - success 433 // FALSE - failure 434 // 435 //****************************************************************************** 436 BOOL Win32MemMap::commitGuardPage(ULONG ulFaultAddr, ULONG ulOffset, BOOL fWriteAccess) 437 { 438 return FALSE; 439 } 440 //****************************************************************************** 441 // Win32MemMap::invalidatePages 442 // 443 // Invalidate map pages. (called by WriteFile) 444 // 445 // Parameters: 446 // 447 // ULONG offset - offset in memory map 448 // ULONG size - invalid range size 449 // 450 // Returns: 451 // TRUE - success 452 // FALSE - failure 453 // 454 //****************************************************************************** 455 BOOL Win32MemMap::invalidatePages(ULONG offset, ULONG size) 456 { 457 return FALSE; 458 } 459 //****************************************************************************** 367 460 // Win32MemMap::unmapViewOfFile 368 461 // … … 517 610 // I'm assuming they aren't for now. 518 611 //****************************************************************************** 519 BOOL Win32MemMap::flushView(ULONG offset, ULONG cbFlush)612 BOOL Win32MemMap::flushView(ULONG viewaddr, ULONG offset, ULONG cbFlush) 520 613 { 521 614 LPVOID lpvBase = (LPVOID)((ULONG)pMapping+offset); … … 767 860 768 861 if(mfAccess & MEMMAP_ACCESS_WRITE) 769 mParentMap->flushView( mOffset, mSize);862 mParentMap->flushView(MMAP_FLUSHVIEW_ALL, mOffset, mSize); 770 863 771 864 //Don't free memory for executable image map views (only used internally) -
trunk/src/kernel32/mmap.h
r9824 r9911 1 /* $Id: mmap.h,v 1.2 5 2003-02-18 18:48:55sandervl Exp $ */1 /* $Id: mmap.h,v 1.26 2003-03-06 10:44:34 sandervl Exp $ */ 2 2 3 3 /* … … 28 28 #define NRPAGES_TOCOMMIT 16 29 29 30 #define MEMMAP_ACCESS_READ 1 31 #define MEMMAP_ACCESS_WRITE 2 32 #define MEMMAP_ACCESS_EXECUTE 4 30 #define MEMMAP_ACCESS_INVALID 0 31 #define MEMMAP_ACCESS_READ 1 32 #define MEMMAP_ACCESS_WRITE 2 33 #define MEMMAP_ACCESS_EXECUTE 4 34 #define MEMMAP_ACCESS_COPYONWRITE 8 35 36 #define MMAP_FLUSHVIEW_ALL 0xFFFFFFFF 33 37 34 38 class Win32MemMapView; … … 45 49 ~Win32MemMap(); 46 50 47 48 BOOL flushView(ULONG offset, ULONG cbFlush);49 50 51 virtual BOOL Init(DWORD aMSize=0); 52 virtual BOOL flushView(ULONG viewaddr, ULONG offset, ULONG cbFlush); 53 virtual LPVOID mapViewOfFile(ULONG size, ULONG offset, ULONG fdwAccess); 54 virtual BOOL unmapViewOfFile(LPVOID addr); 51 55 52 56 HFILE getFileHandle() { return hMemFile; }; … … 63 67 void Release(); 64 68 65 BOOL commitPage(ULONG offset, BOOL fWriteAccess, int nrpages = NRPAGES_TOCOMMIT); 69 virtual BOOL invalidatePages(ULONG offset, ULONG size); 70 virtual BOOL commitPage(ULONG ulFaultAddr, ULONG offset, BOOL fWriteAccess, int nrpages = NRPAGES_TOCOMMIT); 71 virtual BOOL commitGuardPage(ULONG ulFaultAddr, ULONG offset, BOOL fWriteAccess); 72 BOOL commitRange(ULONG ulFaultAddr, ULONG offset, BOOL fWriteAccess, int nrpages); 66 73 67 74 static Win32MemMap *findMap(LPSTR lpszName); -
trunk/src/kernel32/oslibmem.cpp
r9292 r9911 1 /* $Id: oslibmem.cpp,v 1. 5 2002-09-24 15:15:27sandervl Exp $ */1 /* $Id: oslibmem.cpp,v 1.6 2003-03-06 10:44:34 sandervl Exp $ */ 2 2 /* 3 3 * Wrappers for OS/2 Dos* API … … 43 43 44 44 //****************************************************************************** 45 //TODO: Assumes entire memory range has the same protection flags!46 45 //TODO: Check if this works for code aliases... 47 46 //****************************************************************************** … … 55 54 cb+= PAGE_SIZE; 56 55 57 rc = DosQueryMem(pb, &size, &attr);58 if(rc) {59 dprintf(("!ERROR!: OSLibDosAliasMem: DosQueryMem %x %x return %d", pb, size, rc));60 return rc;61 }62 size = (size-1) & ~0xfff;63 size+= PAGE_SIZE;64 if(size != cb) {65 dprintf(("!WARNING!: OSLibDosAliasMem: size != cb (%x!=%x)!!!!!!!!", size, cb));66 //ignore this and continue return 5;67 attr = fl; //just use original protection flags (NOT CORRECT)68 }69 attr &= (PAG_READ|PAG_WRITE|PAG_EXECUTE|PAG_GUARD|PAG_DEFAULT);70 if(attr != fl) {71 rc = DosSetMem(pb, size, fl);72 if(rc) {73 dprintf(("!ERROR!: OSLibDosAliasMem: DosSetMem %x %x return %d", pb, size, rc));74 attr = fl;75 //just continue for now76 //return rc;77 }78 }79 56 rc = DosAliasMem(pb, cb, ppbAlias, 2); 80 57 if(rc) { … … 82 59 return rc; 83 60 } 84 if(attr != fl) { 85 rc = DosSetMem(pb, size, attr); 86 if(rc) { 87 dprintf(("!ERROR!: OSLibDosAliasMem: DosSetMem (2) %x %x return %d", pb, size, rc)); 61 //Now try to change the protection flags of all pages in the aliased range 62 DWORD pAlias = (DWORD)*ppbAlias; 63 64 while(pAlias < (DWORD)*ppbAlias + cb) 65 { 66 rc = DosQueryMem((PVOID)pAlias, &size, &attr); 67 if(rc != NO_ERROR) { 68 dprintf(("!ERROR!: OSLibDosAliasMem: DosQueryMem %x returned %d", pAlias, rc)); 69 DebugInt3(); 88 70 return rc; 89 71 } 72 //Don't bother if the pages are not committed. DosSetMem will return 73 //ERROR_ACCESS_DENIED. 74 if(attr & PAG_COMMIT) { 75 rc = DosSetMem((PVOID)pAlias, size, fl); 76 if(rc) { 77 dprintf(("!ERROR!: OSLibDosAliasMem: DosSetMem %x %x return %d", *ppbAlias, size, rc)); 78 DebugInt3(); 79 return rc; 80 } 81 } 82 pAlias += size; 90 83 } 91 84 return 0; -
trunk/src/kernel32/profile.h
r4752 r9911 1 /* $Id: profile.h,v 1. 8 2000-12-04 12:41:48 birdExp $ */1 /* $Id: profile.h,v 1.9 2003-03-06 10:44:34 sandervl Exp $ */ 2 2 /* 3 3 * Profile header for initterm … … 14 14 #define ODINININAME "ODIN.INI" 15 15 16 void WINAPI WriteOutProfiles(void);17 int WINAPI PROFILE_LoadOdinIni(void);18 19 #ifdef DEBUG20 21 INT ODIN_EXTERN(GetPrivateProfileStringA)(LPCSTR section, LPCSTR entry,22 LPCSTR def_val, LPSTR buffer,23 UINT len, LPCSTR filename);24 25 int ODIN_EXTERN(PROFILE_GetOdinIniString)(LPCSTR section, LPCSTR entry,26 LPCSTR def_val, LPSTR buffer,27 UINT len);28 29 int ODIN_EXTERN(PROFILE_SetOdinIniString)(LPCSTR section_name, LPCSTR key_name,30 LPCSTR value);31 32 int ODIN_EXTERN(PROFILE_GetOdinIniInt)(LPCSTR section_name, LPCSTR key_name,33 int value);34 35 int ODIN_EXTERN(PROFILE_GetOdinIniBool)(LPCSTR section, LPCSTR key_name,36 int def);37 38 UINT ODIN_EXTERN(GetPrivateProfileIntA)(LPCSTR, LPCSTR, INT, LPCSTR);39 UINT ODIN_EXTERN(GetPrivateProfileIntW)(LPCWSTR, LPCWSTR, INT, LPCWSTR);40 INT ODIN_EXTERN(GetPrivateProfileStringW)(LPCWSTR, LPCWSTR, LPCWSTR, LPWSTR, UINT, LPCWSTR);41 BOOL ODIN_EXTERN(WritePrivateProfileStringA)(LPCSTR, LPCSTR, LPCSTR, LPCSTR);42 BOOL ODIN_EXTERN(WritePrivateProfileStringW)(LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR);43 44 #endif45 46 16 #include <win\options.h> //for odin profile apis 47 17 -
trunk/src/kernel32/virtual.cpp
r9884 r9911 1 /* $Id: virtual.cpp,v 1.5 3 2003-03-03 16:30:44 sandervl Exp $ */1 /* $Id: virtual.cpp,v 1.54 2003-03-06 10:44:34 sandervl Exp $ */ 2 2 3 3 /* … … 180 180 return FALSE; 181 181 } 182 ret = map->flushView( offset, cbFlush);182 ret = map->flushView((ULONG)base, offset, cbFlush); 183 183 map->Release(); 184 184 return ret; … … 365 365 if(map) { 366 366 //TODO: We don't allow protection flag changes for mmaped files now 367 map->commitPage( offset, FALSE, nrpages);367 map->commitPage((ULONG)lpvAddress, offset, FALSE, nrpages); 368 368 map->Release(); 369 369 return lpvAddress;
Note:
See TracChangeset
for help on using the changeset viewer.