-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Load R2R images on osx-arm64 according to Apple's guidelines #67118
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9167c0f
Load R2R images on osx-arm64 according to Apple's guidelines
jgiannuzzi 5e17dac
Address review comments
jgiannuzzi 0767101
Use PAL_JitWriteProtect once per relocation
jgiannuzzi a3508ef
Flush instruction cache during relocation on Apple Silicon
jgiannuzzi 9f62457
Fix typo in comment
jgiannuzzi 2c0f671
Use PAL_JitWriteProtect in the same spots where protection is toggled
jgiannuzzi a1d528d
Revert the change for Intel to avoid any regression
jgiannuzzi 5d8b591
Always unmap the file to avoid leaks + log errors
jgiannuzzi 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,10 +229,18 @@ void PEImageLayout::ApplyBaseRelocations(bool relocationMustWriteCopy) | |
// Restore the protection | ||
if (dwOldProtection != 0) | ||
{ | ||
#if defined(__APPLE__) && defined(HOST_ARM64) | ||
BOOL bExecRegion = (dwOldProtection & (PAGE_EXECUTE | PAGE_EXECUTE_READ | | ||
PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)) != 0; | ||
|
||
// Disable writing on Apple Silicon | ||
if (bExecRegion) | ||
PAL_JitWriteProtect(false); | ||
#else | ||
if (!ClrVirtualProtect(pWriteableRegion, cbWriteableRegion, | ||
dwOldProtection, &dwOldProtection)) | ||
ThrowLastError(); | ||
|
||
#endif // __APPLE__ && HOST_ARM64 | ||
dwOldProtection = 0; | ||
} | ||
|
||
|
@@ -251,18 +259,21 @@ void PEImageLayout::ApplyBaseRelocations(bool relocationMustWriteCopy) | |
#if defined(TARGET_UNIX) | ||
if (((pSection->Characteristics & VAL32(IMAGE_SCN_MEM_EXECUTE)) != 0)) | ||
{ | ||
#ifdef __APPLE__ | ||
dwNewProtection = PAGE_READWRITE; | ||
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. |
||
#if defined(__APPLE__) && defined(HOST_ARM64) | ||
// Enable writing on Apple Silicon | ||
PAL_JitWriteProtect(true); | ||
#else | ||
// On SELinux, we cannot change protection that doesn't have execute access rights | ||
// to one that has it, so we need to set the protection to RWX instead of RW | ||
dwNewProtection = PAGE_EXECUTE_READWRITE; | ||
#endif | ||
} | ||
#endif // TARGET_UNIX | ||
#if !(defined(__APPLE__) && defined(HOST_ARM64)) | ||
if (!ClrVirtualProtect(pWriteableRegion, cbWriteableRegion, | ||
dwNewProtection, &dwOldProtection)) | ||
ThrowLastError(); | ||
#endif // __APPLE__ && HOST_ARM64 | ||
#ifdef TARGET_UNIX | ||
dwOldProtection = SectionCharacteristicsToPageProtection(pSection->Characteristics); | ||
#endif // TARGET_UNIX | ||
|
@@ -323,13 +334,19 @@ void PEImageLayout::ApplyBaseRelocations(bool relocationMustWriteCopy) | |
|
||
if (dwOldProtection != 0) | ||
{ | ||
#if defined(__APPLE__) && defined(HOST_ARM64) | ||
BOOL bExecRegion = (dwOldProtection & (PAGE_EXECUTE | PAGE_EXECUTE_READ | | ||
PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)) != 0; | ||
|
||
// Disable writing on Apple Silicon | ||
if (bExecRegion) | ||
PAL_JitWriteProtect(false); | ||
#else | ||
// Restore the protection | ||
if (!ClrVirtualProtect(pWriteableRegion, cbWriteableRegion, | ||
dwOldProtection, &dwOldProtection)) | ||
ThrowLastError(); | ||
#endif // __APPLE__ && HOST_ARM64 | ||
} | ||
#ifdef TARGET_UNIX | ||
PAL_LOADMarkSectionAsNotNeeded((void*)dir); | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.