Author: ion
Date: Mon Jan 30 09:42:47 2012
New Revision: 55320
URL: http://svn.reactos.org/svn/reactos?rev=55320&view=rev
Log:
[NTOSKRNL]: One of my favorite bugfixes to date: While working on SMSS2, I
notice that Win32->NT path conversion is failing and %SystemRoot% is not being
translated. Yet, this is supposed to be part of the core environment that the
kernel sends to SMSS! I analyze the old SMSS, and in there, it works. Puzzled,
I DPRINT1 out the environment only to see that it is empty. I do the same in
the kernel -- empty! The old SMSS is currently manually regenerating its
critical environment, as if the kernel never sent it (which perfectly hid the
bug that our kernel...actually did never send it!). But why were we sending no
environment? It turns out our environment string was 0x10000 bytes, just one
byte longer than MAX_USHORT and overflowing back to zero -- hence our Appends
were all silently failing. But why was our environment string 0x10000, when we
allocate 0x1000 bytes only? And here comes the Mm bug. When you allocate
virtual memory in Windows you are forced to use 64K alignment, and Windows
internally will align the VAD on a 64K boundary. In ReactOS however, we
actually allocate, map, and reserve a full 64K memory area, as well as actually
modify the region size that the caller has sent, returning the caller a
64K-aligned size no matter what (whereas Windows would return the original 4KB
size). I've thus added a simple hack which still allocates a full 64K memory
area (who knows what would break if not), but only aligns the region size to a
page size -- less swap pages are reserved, and the caller only receives a
page-aligned region, instead of 64K. This now fixes ExpLoadInitialProcess and
anyone else that was requesting a 4KB page and getting 64KB in exchange...
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=55320&r1=55319&r2=55320&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/anonmem.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/anonmem.c [iso-8859-1] Mon Jan 30 09:42:47 2012
@@ -874,9 +874,15 @@
return(Status);
}
+#if 0
MemoryAreaLength = (ULONG_PTR)MemoryArea->EndingAddress -
(ULONG_PTR)MemoryArea->StartingAddress;
-
+#else
+ ULONG_PTR EndingAddress;
+ EndingAddress = ((ULONG_PTR)MemoryArea->StartingAddress + RegionSize - 1)
| (PAGE_SIZE - 1);
+ MemoryAreaLength = (ULONG_PTR)EndingAddress -
(ULONG_PTR)MemoryArea->StartingAddress + 1;
+#endif
+
MmInitializeRegion(&MemoryArea->Data.VirtualMemoryData.RegionListHead,
MemoryAreaLength, Type, Protect);