Fix SegmentInitialize for OS_PAGE_SIZE > 4k #20280
Fix SegmentInitialize for OS_PAGE_SIZE > 4k #20280
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Jan!
@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test please |
@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test please |
src/gc/handletablecore.cpp
Outdated
// Round down to the dwPageSize | ||
dwCommit &= ~(OS_PAGE_SIZE - 1); | ||
// Round up to the OS_PAGE_SIZE | ||
dwCommit = (dwCommit + OS_PAGE_SIZE - 1) & ~(OS_PAGE_SIZE - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use ALIGN_UP
: size_t dwCommit = ALIGN_UP(HANDLE_HEADER_SIZE, OS_PAGE_SIZE);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I have thought we have that macro in PAL only. Obviously I was wrong.
The function was incorrectly rounding the dwCommit down instead of up to OS_PAGE_SIZE. It accidentally works for OSes where page size is 4096 bytes, because the dwCommit is 4096. But for ARM64 Linux distros where the page size is 64kB, this was committing zero bytes and so the runtime initialization was crashing a bit later when it tried to access the memory it was supposed to be commited. This problem was introduced in dotnet#17769.
372c022
to
b1fa226
Compare
@dotnet-bot test Windows_NT arm Cross Checked Innerloop Build and Test |
The function was incorrectly rounding the dwCommit down instead of up to OS_PAGE_SIZE. It accidentally works for OSes where page size is 4096 bytes, because the dwCommit is 4096. But for ARM64 Linux distros where the page size is 64kB, this was committing zero bytes and so the runtime initialization was crashing a bit later when it tried to access the memory it was supposed to be commited. This problem was introduced in dotnet#17769.
The function was incorrectly rounding the dwCommit down instead of up
to OS_PAGE_SIZE. It accidentally works for OSes where page size is 4096
bytes, because the dwCommit is 4096. But for ARM64 Linux distros where
the page size is 64kB, this was committing zero bytes and so the runtime
initialization was crashing a bit later when it tried to access the
memory it was supposed to be commited.
This problem was introduced in #17769.