Author: ion
Date: Mon Feb 27 17:17:31 2012
New Revision: 55886
URL: http://svn.reactos.org/svn/reactos?rev=55886&view=rev
Log:
[NTOSKRNL]: Don't assert if there's no VAD found in NtFreeVirtualMemory... perhaps a wrong address was used on purpose (such as during a Winetest). Simply do what ROS does when a MAREA is not found and return failure. However if a VAD *was* found, keep all the other ASSERTs...
Modified:
trunk/reactos/ntoskrnl/mm/anonmem.c
Modified: trunk/reactos/ntoskrnl/mm/anonmem.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/anonmem.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/anonmem.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/anonmem.c [iso-8859-1] Mon Feb 27 17:17:31 2012
@@ -1149,6 +1149,12 @@
StartingAddress = (ULONG_PTR)PAGE_ALIGN(PBaseAddress);
EndingAddress = ((ULONG_PTR)PBaseAddress + PRegionSize - 1) | (PAGE_SIZE - 1);
Vad = MiLocateAddress((PVOID)StartingAddress);
+ if (!Vad)
+ {
+ DPRINT1("Unable to VAD for address 0x%p\n", BaseAddress);
+ Status = STATUS_UNABLE_TO_FREE_VM;
+ goto unlock_deref_and_return;
+ }
/* This is the kind of VAD we expect right now */
ASSERT(Vad);
Author: sir_richard
Date: Mon Feb 27 17:10:44 2012
New Revision: 55885
URL: http://svn.reactos.org/svn/reactos?rev=55885&view=rev
Log:
[NTOS]: Continued preparations for VAD-based Virtual Memory. ASSERT in NtAllocateVirtualMemory any functionality that will not be supported by the VAD-based system (and is not really supported right now either). Make NtFreeVirtualMemory ASSERT that a correct VAD has been found when freeing memory -- which we always expect at this point. Also ASSERT that the VAD has a valid range and flags.
[NTOS]: Do a more stringent check to refuse COPY_ON_WRITE flag sent through NtAllocateVirtualMemory.
[NTOS]: For VM-based Memory Areas, acquire and then release the process working set lock while inserting the VAD, to simulate what the VAD-based Virtual Memory behavior will look like.
[NTOS]: Disable paging for VM-based Memory Areas since this will not be supported with VADs.
[KERNEL32]: CopyLoop was requesting 2 zero bits when calling NtAllocateVirtualMemory. Not sure if this was really the intent or not, but both the new as well as the old NtAllocateVirtualMemory do not support this (the new one will ASSERT). Since this functionality never worked, request 0 bits instead to avoid hitting the ASSERT.
Any problems with what the VAD system will introduce should be revealed by now. From this build until the one which will have the VAD-based system in place, no further VM-related issues should crop up.
Modified:
trunk/reactos/dll/win32/kernel32/client/file/copy.c
trunk/reactos/ntoskrnl/mm/anonmem.c
trunk/reactos/ntoskrnl/mm/marea.c
trunk/reactos/ntoskrnl/mm/rmap.c
Modified: trunk/reactos/dll/win32/kernel32/client/file/copy.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/file/copy.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/file/copy.c [iso-8859-1] Mon Feb 27 17:10:44 2012
@@ -46,7 +46,7 @@
*KeepDest = FALSE;
errCode = NtAllocateVirtualMemory(NtCurrentProcess(),
(PVOID *)&lpBuffer,
- 2,
+ 0,
&RegionSize,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
Modified: trunk/reactos/ntoskrnl/mm/anonmem.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/anonmem.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/anonmem.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/anonmem.c [iso-8859-1] Mon Feb 27 17:10:44 2012
@@ -750,23 +750,27 @@
}
}
+ /* Now it's for real... assert on the things we don't yet support */
+ ASSERT(ZeroBits == 0);
+ ASSERT((AllocationType & MEM_LARGE_PAGES) == 0);
+ ASSERT((AllocationType & MEM_PHYSICAL) == 0);
+ ASSERT((AllocationType & MEM_WRITE_WATCH) == 0);
+ ASSERT((AllocationType & MEM_TOP_DOWN) == 0);
+ ASSERT((AllocationType & MEM_RESET) == 0);
+ ASSERT(Process->VmTopDown == 0);
+
+ /* Do not allow COPY_ON_WRITE through this API */
+ if ((Protect & PAGE_WRITECOPY) || (Protect & PAGE_EXECUTE_WRITECOPY))
+ {
+ DPRINT1("Illegal use of CopyOnWrite\n");
+ if (Attached) KeUnstackDetachProcess(&ApcState);
+ if (ProcessHandle != NtCurrentProcess()) ObDereferenceObject(Process);
+ return STATUS_INVALID_PAGE_PROTECTION;
+ }
+
BaseAddress = (PVOID)PAGE_ROUND_DOWN(PBaseAddress);
RegionSize = PAGE_ROUND_UP((ULONG_PTR)PBaseAddress + PRegionSize) -
PAGE_ROUND_DOWN(PBaseAddress);
-
-
- /*
- * Copy on Write is reserved for system use. This case is a certain failure
- * but there may be other cases...needs more testing
- */
- if ((!BaseAddress || (AllocationType & MEM_RESERVE)) &&
- (Protect & (PAGE_WRITECOPY | PAGE_EXECUTE_WRITECOPY)))
- {
- DPRINT1("Copy on write is not supported by VirtualAlloc\n");
- if (Attached) KeUnstackDetachProcess(&ApcState);
- if (ProcessHandle != NtCurrentProcess()) ObDereferenceObject(Process);
- return STATUS_INVALID_PAGE_PROTECTION;
- }
Type = (AllocationType & MEM_COMMIT) ? MEM_COMMIT : MEM_RESERVE;
DPRINT("Type %x\n", Type);
@@ -1053,6 +1057,8 @@
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
KAPC_STATE ApcState;
BOOLEAN Attached = FALSE;
+ ULONG_PTR StartingAddress, EndingAddress;
+ PMMVAD Vad;
PAGED_CODE();
/* Only two flags are supported */
@@ -1134,9 +1140,23 @@
BaseAddress = (PVOID)PAGE_ROUND_DOWN((PBaseAddress));
- AddressSpace = &Process->Vm;
-
+ /* Lock address space */
+ AddressSpace = MmGetCurrentAddressSpace();
MmLockAddressSpace(AddressSpace);
+ ASSERT(Process->VmDeleted == 0);
+
+ /* Compute start and end addresses, and locate the VAD */
+ StartingAddress = (ULONG_PTR)PAGE_ALIGN(PBaseAddress);
+ EndingAddress = ((ULONG_PTR)PBaseAddress + PRegionSize - 1) | (PAGE_SIZE - 1);
+ Vad = MiLocateAddress((PVOID)StartingAddress);
+
+ /* This is the kind of VAD we expect right now */
+ ASSERT(Vad);
+ ASSERT(Vad->EndingVpn >= (EndingAddress >> PAGE_SHIFT));
+ ASSERT(Vad->u.VadFlags.PrivateMemory == 1);
+ ASSERT(Vad->u.VadFlags.NoChange == 0);
+ ASSERT(Vad->u.VadFlags.VadType == VadNone);
+
MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, BaseAddress);
if (MemoryArea == NULL)
{
Modified: trunk/reactos/ntoskrnl/mm/marea.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/marea.c?rev=55…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/marea.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/marea.c [iso-8859-1] Mon Feb 27 17:10:44 2012
@@ -373,6 +373,8 @@
PMEMORY_AREA Node;
PMEMORY_AREA PreviousNode;
ULONG Depth = 0;
+ PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace);
+ PETHREAD CurrentThread = PsGetCurrentThread();
/* Build a lame VAD if this is a user-space allocation */
if ((marea->EndingAddress < MmSystemRangeStart) && (marea->Type != MEMORY_AREA_OWNED_BY_ARM3))
@@ -400,8 +402,16 @@
Vad->u.VadFlags.Spare = 1;
Vad->u.VadFlags.PrivateMemory = 1;
Vad->u.VadFlags.Protection = MiMakeProtectionMask(marea->Protect);
- MiInsertVad(Vad, MmGetAddressSpaceOwner(AddressSpace));
+
+ /* Pretend as if we own the working set */
+ if (marea->Type == MEMORY_AREA_VIRTUAL_MEMORY) MiLockProcessWorkingSet(Process, CurrentThread);
+
+ /* Insert the VAD */
+ MiInsertVad(Vad, Process);
marea->Vad = Vad;
+
+ /* Release the working set */
+ if (marea->Type == MEMORY_AREA_VIRTUAL_MEMORY) MiUnlockProcessWorkingSet(Process, CurrentThread);
}
else
{
Modified: trunk/reactos/ntoskrnl/mm/rmap.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/rmap.c?rev=558…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/rmap.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/rmap.c [iso-8859-1] Mon Feb 27 17:10:44 2012
@@ -159,29 +159,8 @@
}
else if (Type == MEMORY_AREA_VIRTUAL_MEMORY)
{
- PageOp = MmGetPageOp(MemoryArea, Address < MmSystemRangeStart ? Process->UniqueProcessId : NULL,
- Address, NULL, 0, MM_PAGEOP_PAGEOUT, TRUE);
- if (PageOp == NULL)
- {
- MmUnlockAddressSpace(AddressSpace);
- if (Address < MmSystemRangeStart)
- {
- ExReleaseRundownProtection(&Process->RundownProtect);
- ObDereferenceObject(Process);
- }
- return(STATUS_UNSUCCESSFUL);
- }
-
- /*
- * Release locks now we have a page op.
- */
- MmUnlockAddressSpace(AddressSpace);
-
- /*
- * Do the actual page out work.
- */
- Status = MmPageOutVirtualMemory(AddressSpace, MemoryArea,
- Address, PageOp);
+ /* Do not page out virtual memory during ARM3 transition */
+ Status = STATUS_SUCCESS;
}
else
{
Author: sir_richard
Date: Mon Feb 27 16:12:11 2012
New Revision: 55883
URL: http://svn.reactos.org/svn/reactos?rev=55883&view=rev
Log:
[NTOS]: Preparations for the VAD-based Virtual Memory system begin. Disable changing protection on Virtual Memory pages, and make all pages PAGE_EXECUTE_READWRITE for now. In theory, this should not cause any real problems, and sets the stage for the initial functionality regressions that the VAD-based system will introduce. I will eventually plan on fixing them.
Modified:
trunk/reactos/ntoskrnl/mm/anonmem.c
Modified: trunk/reactos/ntoskrnl/mm/anonmem.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/anonmem.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/anonmem.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/anonmem.c [iso-8859-1] Mon Feb 27 16:12:11 2012
@@ -527,9 +527,7 @@
if (MemoryArea->Type == MEMORY_AREA_VIRTUAL_MEMORY)
{
- Status = MmProtectAnonMem(AddressSpace, MemoryArea, *BaseAddress,
- *NumberOfBytesToProtect, NewAccessProtection,
- OldAccessProtection);
+ Status = STATUS_SUCCESS;
}
else if (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW)
{
@@ -775,6 +773,11 @@
AddressSpace = &Process->Vm;
MmLockAddressSpace(AddressSpace);
+
+ //
+ // Force PAGE_EXECUTE_READWRITE for everything, for now
+ //
+ Protect = PAGE_EXECUTE_READWRITE;
if (PBaseAddress != 0)
{
@@ -1249,84 +1252,4 @@
return(Status);
}
-NTSTATUS
-NTAPI
-MmProtectAnonMem(PMMSUPPORT AddressSpace,
- PMEMORY_AREA MemoryArea,
- PVOID BaseAddress,
- SIZE_T Length,
- ULONG Protect,
- PULONG OldProtect)
-{
- PMM_REGION Region;
- NTSTATUS Status = STATUS_SUCCESS;
- ULONG_PTR LengthCount = 0;
-
- /* Search all Regions in MemoryArea up to Length */
- /* Every Region up to Length must be committed for success */
- for (;;)
- {
- Region = MmFindRegion(MemoryArea->StartingAddress,
- &MemoryArea->Data.VirtualMemoryData.RegionListHead,
- (PVOID)((ULONG_PTR)BaseAddress + LengthCount), NULL);
-
- /* If a Region was found and it is committed */
- if ((Region) && (Region->Type == MEM_COMMIT))
- {
- LengthCount += Region->Length;
- if (Length <= LengthCount) break;
- continue;
- }
- /* If Region was found and it is not commited */
- else if (Region)
- {
- Status = STATUS_NOT_COMMITTED;
- break;
- }
- /* If no Region was found at all */
- else if (LengthCount == 0)
- {
- Status = STATUS_INVALID_ADDRESS;
- break;
- }
- }
-
- if (NT_SUCCESS(Status))
- {
- *OldProtect = Region->Protect;
- Status = MmAlterRegion(AddressSpace, MemoryArea->StartingAddress,
- &MemoryArea->Data.VirtualMemoryData.RegionListHead,
- BaseAddress, Length, Region->Type, Protect,
- MmModifyAttributes);
- }
-
- return (Status);
-}
-
-NTSTATUS NTAPI
-MmQueryAnonMem(PMEMORY_AREA MemoryArea,
- PVOID Address,
- PMEMORY_BASIC_INFORMATION Info,
- PSIZE_T ResultLength)
-{
- PMM_REGION Region;
- PVOID RegionBase = NULL;
-
- Info->BaseAddress = (PVOID)PAGE_ROUND_DOWN(Address);
-
- Region = MmFindRegion(MemoryArea->StartingAddress,
- &MemoryArea->Data.VirtualMemoryData.RegionListHead,
- Address, &RegionBase);
- Info->BaseAddress = RegionBase;
- Info->AllocationBase = MemoryArea->StartingAddress;
- Info->AllocationProtect = MemoryArea->Protect;
- Info->RegionSize = Region->Length;
- Info->State = Region->Type;
- Info->Protect = Region->Protect;
- Info->Type = MEM_PRIVATE;
-
- *ResultLength = sizeof(MEMORY_BASIC_INFORMATION);
- return(STATUS_SUCCESS);
-}
-
/* EOF */
Author: ion
Date: Mon Feb 27 15:28:06 2012
New Revision: 55880
URL: http://svn.reactos.org/svn/reactos?rev=55880&view=rev
Log:
[CMLIB]: Great job -- crashing trunk on a pool tag just so people can be forced to know what it is. Change the registry pool tag from "th" (wtf?) to "CM25" which is a bit closer to Windows. In reality all of TAG_CM should be broken out in many more pieces. Fixes boot breakpoint.
Modified:
trunk/reactos/lib/cmlib/cmlib.h
Modified: trunk/reactos/lib/cmlib/cmlib.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/cmlib.h?rev=5588…
==============================================================================
--- trunk/reactos/lib/cmlib/cmlib.h [iso-8859-1] (original)
+++ trunk/reactos/lib/cmlib/cmlib.h [iso-8859-1] Mon Feb 27 15:28:06 2012
@@ -113,7 +113,7 @@
#endif
#endif
-#define TAG_CM 0x68742020
+#define TAG_CM 'CM25'
#define CMAPI NTAPI