Skip to content

Commit

Permalink
[NTOS:MM] Do not use PAGE_ROUND_DOWN for LONGLONG values (reactos#7603)
Browse files Browse the repository at this point in the history
PAGE_ROUND_DOWN macro seems to not work correctly with LONGLONG values. It creates some random freezes in the 1st-stage setup after commit 69bf140.
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 <[email protected]>
  • Loading branch information
Vince1171 and TAN-Gaming authored Jan 16, 2025
1 parent 190f710 commit 6ada597
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions ntoskrnl/include/internal/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 | \
Expand Down
8 changes: 4 additions & 4 deletions ntoskrnl/mm/section.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 6ada597

Please sign in to comment.