[NTOS:MM] Do not use PAGE_ROUND_DOWN for LONGLONG values (#7603)

PAGE_ROUND_DOWN macro seems to not work correctly with LONGLONG values. It creates some random freezes in the 1st-stage setup after commit 69bf140506.
It's fixed by creating PAGE_ROUND_UP_64 and PAGE_ROUND_DOWN_64 macros for 64-bit only data types.

---------

Co-authored-by: Thamatip Chitpong <thamatip.chitpong@reactos.org>
This commit is contained in:
Vincent Franchomme 2025-01-16 04:30:38 +01:00 committed by GitHub
parent 190f710942
commit 6ada5978d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View file

@ -131,6 +131,13 @@ typedef ULONG_PTR SWAPENTRY;
#define MM_ROUND_DOWN(x,s) \
((PVOID)(((ULONG_PTR)(x)) & ~((ULONG_PTR)(s)-1)))
/* PAGE_ROUND_UP and PAGE_ROUND_DOWN equivalent, with support for 64-bit-only data types */
#define PAGE_ROUND_UP_64(x) \
(((x) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
#define PAGE_ROUND_DOWN_64(x) \
((x) & ~(PAGE_SIZE - 1))
#define PAGE_FLAGS_VALID_FOR_SECTION \
(PAGE_READONLY | \
PAGE_READWRITE | \

View file

@ -4876,7 +4876,7 @@ MmPurgeSegment(
}
/* Find byte offset of the page to start */
PurgeStart.QuadPart = PAGE_ROUND_DOWN(PurgeStart.QuadPart);
PurgeStart.QuadPart = PAGE_ROUND_DOWN_64(PurgeStart.QuadPart);
while (PurgeStart.QuadPart < PurgeEnd.QuadPart)
{
@ -4947,7 +4947,7 @@ MmIsDataSectionResident(
return FALSE;
/* Find byte offset of the page to start */
RangeStart.QuadPart = PAGE_ROUND_DOWN(RangeStart.QuadPart);
RangeStart.QuadPart = PAGE_ROUND_DOWN_64(RangeStart.QuadPart);
MmLockSectionSegment(Segment);
@ -5010,7 +5010,7 @@ MmMakeSegmentDirty(
return STATUS_NOT_MAPPED_VIEW;
/* Find byte offset of the page to start */
RangeStart.QuadPart = PAGE_ROUND_DOWN(RangeStart.QuadPart);
RangeStart.QuadPart = PAGE_ROUND_DOWN_64(RangeStart.QuadPart);
MmLockSectionSegment(Segment);
@ -5098,7 +5098,7 @@ MmFlushSegment(
}
/* Find byte offset of the page to start */
FlushStart.QuadPart = PAGE_ROUND_DOWN(FlushStart.QuadPart);
FlushStart.QuadPart = PAGE_ROUND_DOWN_64(FlushStart.QuadPart);
while (FlushStart.QuadPart < FlushEnd.QuadPart)
{