Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Fix SegmentInitialize for OS_PAGE_SIZE > 4k #20280

Merged
merged 1 commit into from Oct 8, 2018

Conversation

janvorli
Copy link
Member

@janvorli janvorli commented Oct 5, 2018

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.

@janvorli janvorli added this to the 3.0 milestone Oct 5, 2018
@janvorli janvorli self-assigned this Oct 5, 2018
@janvorli janvorli requested a review from davmason October 5, 2018 10:50
@janvorli
Copy link
Member Author

janvorli commented Oct 5, 2018

cc: @Maoni0, @sdmaclea

Copy link
Member

@Maoni0 Maoni0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link

@sdmaclea sdmaclea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@davmason davmason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jan!

@janvorli
Copy link
Member Author

janvorli commented Oct 6, 2018

@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test please

@janvorli
Copy link
Member Author

janvorli commented Oct 6, 2018

@dotnet-bot test OSX10.12 x64 Checked Innerloop Build and Test please

// 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);
Copy link
Member

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);

Copy link
Member Author

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.
@janvorli janvorli force-pushed the fix-segmentinitialize-arm64-unix branch from 372c022 to b1fa226 Compare October 6, 2018 23:24
@jkotas
Copy link
Member

jkotas commented Oct 8, 2018

@dotnet-bot test Windows_NT arm Cross Checked Innerloop Build and Test
@dotnet-bot test Windows_NT arm64 Cross Checked Innerloop Build and Test

@jkotas jkotas merged commit 340b570 into dotnet:master Oct 8, 2018
@janvorli janvorli deleted the fix-segmentinitialize-arm64-unix branch October 9, 2018 04:52
A-And pushed a commit to A-And/coreclr that referenced this pull request Nov 20, 2018
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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
5 participants