-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix loading of R2R assemblies from byte arrays/streams #74118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1ea552a
enable test
VSadov 21a4bdb
flat layout is ok if it is not a file
VSadov 17cbdf6
do not convert non-file layouts on OSX
VSadov c2061d9
run some code when loading from byte array
VSadov 4be4117
use flat layout on all platforms
VSadov c5dc71e
Suggestion from PR feedback
VSadov 680b317
typo
VSadov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I am not sure I understand this comment. Why would allocating executable memory not work on OSX?
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.
I think it would work if correct APIs are used. It is probably not as simple as just passing MAP_JIT to VirtualAlloc or just replacing VirtualAlloc with another call.
I want to backport this to 7.0, so I'd like to not do a lot of changes to how we convert layouts, which would carry extra risk to scenarios that are not being fixed.
The goal is to make sure that assemblies can be loaded from byte arrays even if they contain R2R code.
Whether the R2R is actually enabled is of less importance. It is a relatively rare case and a reflection scenario with unclear benefits from R2R.
Linux part was just tweaking the assert, but for OSX enabling R2R needs more changes. I think it is ok to do those changes in 8.0
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.
I agree that the change is fine as is.
Just FYI though, the
VirtualAllocsetsMAP_JITautomatically for executable memory allocations. Either it gets memory from theg_executableMemoryAllocator.AllocateMemoryor it sets the special flag that results inMAP_JITaddition during memory reservation:runtime/src/coreclr/pal/src/map/virtual.cpp
Lines 923 to 927 in 6f69dde
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.
Does it mean that I could just pass
PAGE_EXECUTE_READWRITEto VirtualAlloc on OSX?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.
Yes
Uh oh!
There was an error while loading. Please reload this page.
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.
I tried going that path (setting
PAGE_EXECUTE_READWRITE), but I think I also need to togglePAL_JitWriteProtectwhen copying sections and then the change started making me worried about the complexity and possible bugs.I think I will leave that for after-7.0, we do not have to do this now.
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.
Right (for both)
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.
I've logged #74203 to follow up with enabling R2R on OSX