-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
PE loader/image cleanups. No-copy mapping of R2R PEs on Windows. #61938
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
515a1b3
removed IMAGE_MAPPED
VSadov 0178294
removed RawImageLayout
VSadov 49c759f
delete MappedImageLayout
VSadov 519fe5c
use mem-mapping on Windows
VSadov 00ae715
tweaks and touchups
VSadov 230e9ef
a few cleanups
VSadov 3e2c617
comments
VSadov 23945fb
move EnsureLoaded into Assemby::Init
VSadov be5f1fe
A fix for IsDynamic() case.
VSadov 2bf609d
fix for preferred base, if used.
VSadov 1e0a933
disable failing scenario
VSadov 5cc040e
PR feedback
VSadov 30be65f
Typo (CENTINEL --> SENTINEL)
VSadov 473f734
added a bug link to a disabled test scenario + couple comment tweaks
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 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 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 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 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 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,11 +189,17 @@ void Assembly::Init(AllocMemTracker *pamTracker, LoaderAllocator *pLoaderAllocat | |
m_pClassLoader = new ClassLoader(this); | ||
m_pClassLoader->Init(pamTracker); | ||
|
||
if (GetManifestFile()->IsDynamic()) | ||
PEAssembly* pPEAssembly = GetManifestFile(); | ||
|
||
// "Module::Create" will initialize R2R support, if there is an R2R header. | ||
// make sure the PE is loaded or R2R will be disabled. | ||
pPEAssembly->EnsureLoaded(); | ||
|
||
if (pPEAssembly->IsDynamic()) | ||
// manifest modules of dynamic assemblies are always transient | ||
m_pManifest = ReflectionModule::Create(this, GetManifestFile(), pamTracker, REFEMIT_MANIFEST_MODULE_NAME); | ||
m_pManifest = ReflectionModule::Create(this, pPEAssembly, pamTracker, REFEMIT_MANIFEST_MODULE_NAME); | ||
else | ||
m_pManifest = Module::Create(this, mdFileNil, GetManifestFile(), pamTracker); | ||
m_pManifest = Module::Create(this, mdFileNil, pPEAssembly, pamTracker); | ||
|
||
FastInterlockIncrement((LONG*)&g_cAssemblies); | ||
|
||
|
@@ -208,15 +214,16 @@ void Assembly::Init(AllocMemTracker *pamTracker, LoaderAllocator *pLoaderAllocat | |
// loading it entirely. | ||
//CacheFriendAssemblyInfo(); | ||
|
||
if (IsCollectible()) | ||
if (IsCollectible() && !pPEAssembly->IsDynamic()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are dynamic assemblies excluded here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dynamic assemblies do not have PE layouts. The |
||
{ | ||
COUNT_T size; | ||
BYTE *start = (BYTE*)m_pManifest->GetPEAssembly()->GetLoadedImageContents(&size); | ||
if (start != NULL) | ||
{ | ||
GCX_COOP(); | ||
LoaderAllocator::AssociateMemoryWithLoaderAllocator(start, start + size, m_pLoaderAllocator); | ||
} | ||
BYTE* start = (BYTE*)pPEAssembly->GetLoadedImageContents(&size); | ||
|
||
// We should have the content loaded at this time. There will be no other attempt to associate memory. | ||
_ASSERTE(start != NULL); | ||
|
||
GCX_COOP(); | ||
LoaderAllocator::AssociateMemoryWithLoaderAllocator(start, start + size, m_pLoaderAllocator); | ||
} | ||
|
||
{ | ||
|
This file contains 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 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 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 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 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
Oops, something went wrong.
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'm just curious - why was this change necessary?
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.
Without this change if
prot
is executable, theprot | PROT_WRITE
becomes WX.mprotect
will accept that, butpread
will fail and we would bail from this method. This would always happen in an R2R PE, since.text
is executable.We then would go on the path of doing layout via copying, which would work, but often end up not in the desired location and later fail when applying relocations, where we had similar WX issue. Failed relocations would result in R2R disabled. The code would still run - in pure IL/JIT mode.
Ultimately we would have R2R enabled on OSX only when we are very lucky.