Changeset 8457 for trunk/src/kernel32/virtual.cpp
- Timestamp:
- May 20, 2002, 3:48:51 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/virtual.cpp
r7849 r8457 1 /* $Id: virtual.cpp,v 1.4 3 2002-02-09 12:45:14sandervl Exp $ */1 /* $Id: virtual.cpp,v 1.44 2002-05-20 13:48:50 sandervl Exp $ */ 2 2 3 3 /* … … 592 592 DWORD cbLength) 593 593 { 594 ULONG cbRangeSize, 595 dAttr; 596 DWORD rc; 597 LPVOID lpBase; 598 599 SetLastError(ERROR_SUCCESS); 600 601 if(pmbiBuffer == NULL || cbLength != sizeof(MEMORY_BASIC_INFORMATION)) // check parameters 602 { 603 dprintf(("WARNING: invalid parameter")); 604 SetLastError(ERROR_INVALID_PARAMETER); 594 ULONG cbRangeSize, dAttr; 595 DWORD rc; 596 LPVOID lpBase; 597 598 SetLastError(ERROR_SUCCESS); 599 600 if(pmbiBuffer == NULL || cbLength != sizeof(MEMORY_BASIC_INFORMATION)) // check parameters 601 { 602 dprintf(("WARNING: invalid parameter")); 603 SetLastError(ERROR_INVALID_PARAMETER); 605 604 return 0; // nothing to return 606 } 607 608 // determine exact page range 609 lpBase = (LPVOID)((ULONG)lpvAddress & 0xFFFFF000); 610 cbRangeSize = -1; 611 612 rc = OSLibDosQueryMem(lpBase, 613 &cbRangeSize, 614 &dAttr); 615 if(rc) 616 { 605 } 606 607 // determine exact page range 608 lpBase = (LPVOID)((ULONG)lpvAddress & 0xFFFFF000); 609 cbRangeSize = -1; 610 611 rc = OSLibDosQueryMem(lpBase, &cbRangeSize, &dAttr); 612 if(rc) 613 { 617 614 dprintf(("VirtualQuery - OSLibDosQueryMem %x %x returned %d\n", 618 615 lpBase, cbLength, rc)); 619 616 SetLastError(ERROR_INVALID_PARAMETER); 620 617 return 0; 621 } 622 623 memset(pmbiBuffer, 624 0, 625 sizeof(MEMORY_BASIC_INFORMATION)); 626 627 pmbiBuffer->BaseAddress = lpBase; 628 //round to next page boundary 629 pmbiBuffer->RegionSize = (cbRangeSize + 0xFFF) & 0xFFFFF000; 630 631 if(dAttr & PAG_READ && !(dAttr & PAG_WRITE)) 632 pmbiBuffer->Protect |= PAGE_READONLY; 633 634 if(dAttr & PAG_WRITE) 635 pmbiBuffer->Protect |= PAGE_READWRITE; 636 637 if((dAttr & (PAG_WRITE | PAG_EXECUTE)) == (PAG_WRITE | PAG_EXECUTE)) 638 pmbiBuffer->Protect |= PAGE_EXECUTE_READWRITE; 639 else 618 } 619 620 memset(pmbiBuffer, 0, sizeof(MEMORY_BASIC_INFORMATION)); 621 622 pmbiBuffer->BaseAddress = lpBase; 623 //round to next page boundary 624 pmbiBuffer->RegionSize = (cbRangeSize + 0xFFF) & 0xFFFFF000; 625 626 if(dAttr & PAG_READ && !(dAttr & PAG_WRITE)) 627 pmbiBuffer->Protect |= PAGE_READONLY; 628 629 if(dAttr & PAG_WRITE) 630 pmbiBuffer->Protect |= PAGE_READWRITE; 631 632 if((dAttr & (PAG_WRITE | PAG_EXECUTE)) == (PAG_WRITE | PAG_EXECUTE)) 633 pmbiBuffer->Protect |= PAGE_EXECUTE_READWRITE; 634 else 640 635 if(dAttr & PAG_EXECUTE) 641 pmbiBuffer->Protect |= PAGE_EXECUTE_READ;642 643 if(dAttr & PAG_GUARD)644 pmbiBuffer->Protect |= PAGE_GUARD;645 646 if(dAttr & PAG_FREE)647 pmbiBuffer->State = MEM_FREE;648 else636 pmbiBuffer->Protect |= PAGE_EXECUTE_READ; 637 638 if(dAttr & PAG_GUARD) 639 pmbiBuffer->Protect |= PAGE_GUARD; 640 641 if(dAttr & PAG_FREE) 642 pmbiBuffer->State = MEM_FREE; 643 else 649 644 if(dAttr & PAG_COMMIT) 650 pmbiBuffer->State = MEM_COMMIT;645 pmbiBuffer->State = MEM_COMMIT; 651 646 else 652 pmbiBuffer->State = MEM_RESERVE;653 654 //TODO: MEM_MAPPED & MEM_IMAGE (==SEC_IMAGE)655 if(!(dAttr & PAG_SHARED))647 pmbiBuffer->State = MEM_RESERVE; 648 649 //TODO: MEM_MAPPED & MEM_IMAGE (==SEC_IMAGE) 650 if(!(dAttr & PAG_SHARED)) 656 651 pmbiBuffer->Type = MEM_PRIVATE; 657 652 658 // Pages can be committed but not necessarily accessible!!659 if (!(dAttr & (PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_GUARD)))660 pmbiBuffer->Protect = PAGE_NOACCESS;661 662 //TODO: This is not correct: AllocationProtect should contain the protection663 // flags used in the initial call to VirtualAlloc664 pmbiBuffer->AllocationProtect = pmbiBuffer->Protect;665 if(dAttr & PAG_BASE) {653 // Pages can be committed but not necessarily accessible!! 654 if (!(dAttr & (PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_GUARD))) 655 pmbiBuffer->Protect = PAGE_NOACCESS; 656 657 //TODO: This is not correct: AllocationProtect should contain the protection 658 // flags used in the initial call to VirtualAlloc 659 pmbiBuffer->AllocationProtect = pmbiBuffer->Protect; 660 if(dAttr & PAG_BASE) { 666 661 pmbiBuffer->AllocationBase = lpBase; 667 }668 else669 {662 } 663 else 664 { 670 665 while(lpBase > 0) 671 666 { … … 681 676 } 682 677 lpBase = (LPVOID)((ULONG)lpBase - PAGE_SIZE); 683 } 684 } 685 return sizeof(MEMORY_BASIC_INFORMATION); 678 } 679 } 680 dprintf(("Memory region alloc base 0x%08x", pmbiBuffer->AllocationBase)); 681 dprintf(("Memory region alloc protect flags %x", pmbiBuffer->AllocationProtect)); 682 dprintf(("Memory region base 0x%08x", pmbiBuffer->BaseAddress)); 683 dprintf(("Memory region protect flags %x", pmbiBuffer->Protect)); 684 dprintf(("Memory region region size 0x%08x", pmbiBuffer->RegionSize)); 685 dprintf(("Memory region state 0x%08x", pmbiBuffer->State)); 686 dprintf(("Memory region type 0x%08x", pmbiBuffer->Type)); 687 return sizeof(MEMORY_BASIC_INFORMATION); 686 688 } 687 689 //****************************************************************************** … … 689 691 BOOL WIN32API VirtualLock(LPVOID lpAddress, DWORD dwSize) 690 692 { 691 dprintf(("VirtualLock at %d; %d bytes - stub (TRUE)\n", (int)lpAddress, dwSize));692 SetLastError(ERROR_SUCCESS);693 return TRUE;693 dprintf(("VirtualLock at %d; %d bytes - stub (TRUE)\n", (int)lpAddress, dwSize)); 694 SetLastError(ERROR_SUCCESS); 695 return TRUE; 694 696 } 695 697 … … 697 699 BOOL WIN32API VirtualUnlock(LPVOID lpAddress, DWORD dwSize) 698 700 { 699 dprintf(("VirtualUnlock at %d; %d bytes - stub (TRUE)\n", (int)lpAddress, dwSize));700 SetLastError(ERROR_SUCCESS);701 return TRUE;701 dprintf(("VirtualUnlock at %d; %d bytes - stub (TRUE)\n", (int)lpAddress, dwSize)); 702 SetLastError(ERROR_SUCCESS); 703 return TRUE; 702 704 } 703 705
Note:
See TracChangeset
for help on using the changeset viewer.