[0.4.8][NTOS:MM] Fix Regression, "Precision" demo executable doesn't load CORE-12400 (#503), + follow-up (#5002)

This fixes the "Farbrausch - Precision" demo
https://files.scene.org/view/parties/2006/assembly06/in64/fr-048_precision_by_farbrausch.zip
from not loading any longer.
It broke by SVN r72989 == git 63bbaff803

The fix is a combined backport of 2 commits:
1.)
0.4.10-dev-136-g c7eb46d9fd (#503)
where Mark Jansen aimed to fix loading executables treated with the binary packer "mPress".
This is what fixed the "Farbrausch - Precision" demo as well.
Marks commit back then referenced CORE-12582 and CORE-14556 although it never was enough to solve any of the 2 tickets entirely.
I do just reference them here again to preserve that ancient (questionable) linkage.

2.)
Since Marks commit back then introduced a very severe regression as well, I do have to port back also the following commit:
0.4.15-dev-5589-g 0d4a8d0ea6 (#5002)
to prevent me to introduce into older releases the bug
CORE-18797 "SizeOfRawData of BSS section should not be processed"
(which had many duplicates, e.g. Doom95, compiled with Watcom-C-compilers would not longer work without that)

-------------

I felt the need to underline that I have tested that porting back the following commit
0.4.10-dev-474-g dfff8ed0d8
is *NOT* needed in the older branches to prevent
CORE14838 "Antivir 6 deadlocks RtlpWaitForCriticalSection when 'scanning the process list'"
although the JIRA-tickets referenced the same unhiding commit 0.4.10-dev-136-g c7eb46d9fd for the master branch.
I consider that as being a temporary workaround that has been applied to master, which seems to be not needed in the older branches,
and it may be possible that we may get rid of that on master too at some point in the future.

------------

NTOSKRNL binary size unchanged:
releases/0.4.9 RosBEWin2.1.6 GCC4.7.2dbg  4.311.552 -> 4.311.552
releases/0.4.8 RosBEWin2.1.6 GCC4.7.2dbg  4.296.704 -> 4.296.704
releases/0.4.7 RosBEWin2.1.6 GCC4.7.2dbg  4.231.168 -> 4.231.168
This commit is contained in:
Joachim Henze 2023-12-18 15:03:52 +01:00
parent 2c140c1c10
commit 8183b67782

View file

@ -684,7 +684,7 @@ l_ReadHeaderFromFile:
pssSegments[0].Length.QuadPart = nPrevVirtualEndOfSegment;
pssSegments[0].RawLength.QuadPart = nFileSizeOfHeaders;
pssSegments[0].Image.VirtualAddress = 0;
pssSegments[0].Image.Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA;
pssSegments[0].Image.Characteristics = 0;
pssSegments[0].WriteCopy = TRUE;
/* skip the headers segment */
@ -706,7 +706,7 @@ l_ReadHeaderFromFile:
DIE(("Memory gap between section %u and the previous\n", i));
/* ignore explicit BSS sections */
if(pishSectionHeaders[i].SizeOfRawData != 0)
if(pishSectionHeaders[i].PointerToRawData != 0 && pishSectionHeaders[i].SizeOfRawData != 0)
{
/* validate the alignment */
#if 0
@ -1341,9 +1341,7 @@ MmAlterViewAttributes(PMMSUPPORT AddressSpace,
Page = MmGetPfnForProcess(Process, Address);
Protect = PAGE_READONLY;
if (Segment->Image.Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA ||
IS_SWAP_FROM_SSE(Entry) ||
PFN_FROM_SSE(Entry) != Page)
if (IS_SWAP_FROM_SSE(Entry) || PFN_FROM_SSE(Entry) != Page)
{
Protect = NewProtect;
}
@ -1473,7 +1471,7 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
HasSwapEntry = MmIsPageSwapEntry(Process, Address);
/* See if we should use a private page */
if ((HasSwapEntry) || (Segment->Image.Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA))
if (HasSwapEntry)
{
SWAPENTRY DummyEntry;
@ -2064,9 +2062,7 @@ MmPageOutSectionView(PMMSUPPORT AddressSpace,
*/
MmUnlockSectionSegment(Context.Segment);
Context.WasDirty = FALSE;
if (Context.Segment->Image.Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA ||
IS_SWAP_FROM_SSE(Entry) ||
PFN_FROM_SSE(Entry) != Page)
if (IS_SWAP_FROM_SSE(Entry) || PFN_FROM_SSE(Entry) != Page)
{
Context.Private = TRUE;
}
@ -2454,9 +2450,7 @@ MmWritePageSectionView(PMMSUPPORT AddressSpace,
/*
* Check for a private (COWed) page.
*/
if (Segment->Image.Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA ||
IS_SWAP_FROM_SSE(Entry) ||
PFN_FROM_SSE(Entry) != Page)
if (IS_SWAP_FROM_SSE(Entry) || PFN_FROM_SSE(Entry) != Page)
{
Private = TRUE;
}