Skip to content

Commit

Permalink
[NTOS:MM] Add PAGE_ROUND_UP_64 and PAGE_ROUND_DOWN_64 macros for alwa…
Browse files Browse the repository at this point in the history
…ys 64-bit values
  • Loading branch information
TAN-Gaming committed Jan 10, 2025
1 parent 1900ef7 commit 8253c0b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 8 additions & 0 deletions ntoskrnl/include/internal/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ 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 for always 64-bit values.
* For example: file offset */
#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
12 changes: 4 additions & 8 deletions ntoskrnl/mm/section.c
Original file line number Diff line number Diff line change
Expand Up @@ -4876,8 +4876,7 @@ MmPurgeSegment(
}

/* Find byte offset of the page to start */
PurgeStart.QuadPart >>= PAGE_SHIFT;
PurgeStart.QuadPart <<= PAGE_SHIFT;
PurgeStart.QuadPart = PAGE_ROUND_DOWN_64(PurgeStart.QuadPart);

while (PurgeStart.QuadPart < PurgeEnd.QuadPart)
{
Expand Down Expand Up @@ -4948,8 +4947,7 @@ MmIsDataSectionResident(
return FALSE;

/* Find byte offset of the page to start */
RangeStart.QuadPart >>= PAGE_SHIFT;
RangeStart.QuadPart <<= PAGE_SHIFT;
RangeStart.QuadPart = PAGE_ROUND_DOWN_64(RangeStart.QuadPart);

MmLockSectionSegment(Segment);

Expand Down Expand Up @@ -5012,8 +5010,7 @@ MmMakeSegmentDirty(
return STATUS_NOT_MAPPED_VIEW;

/* Find byte offset of the page to start */
RangeStart.QuadPart >>= PAGE_SHIFT;
RangeStart.QuadPart <<= PAGE_SHIFT;
RangeStart.QuadPart = PAGE_ROUND_DOWN_64(RangeStart.QuadPart);

MmLockSectionSegment(Segment);

Expand Down Expand Up @@ -5101,8 +5098,7 @@ MmFlushSegment(
}

/* Find byte offset of the page to start */
FlushStart.QuadPart >>= PAGE_SHIFT;
FlushStart.QuadPart <<= PAGE_SHIFT;
FlushStart.QuadPart = PAGE_ROUND_DOWN_64(FlushStart.QuadPart);

while (FlushStart.QuadPart < FlushEnd.QuadPart)
{
Expand Down

0 comments on commit 8253c0b

Please sign in to comment.