Skip to content
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

[release/7.0] Fixing compressed singlefile scenario on osx-arm64 #80283

Merged
merged 5 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/coreclr/vm/peimagelayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,10 +775,18 @@ void* FlatImageLayout::LoadImageByCopyingParts(SIZE_T* m_imageParts) const
}
#endif // FEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION

DWORD allocationType = MEM_RESERVE | MEM_COMMIT;
#ifdef HOST_UNIX
// Tell PAL to use the executable memory allocator to satisfy this request for virtual memory.
// This is required on MacOS and otherwise will allow us to place native R2R code close to the
// coreclr library and thus improve performance by avoiding jump stubs in managed code.
allocationType |= MEM_RESERVE_EXECUTABLE;
#endif

COUNT_T allocSize = ALIGN_UP(this->GetVirtualSize(), g_SystemInfo.dwAllocationGranularity);
LPVOID base = ClrVirtualAlloc(preferredBase, allocSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
LPVOID base = ClrVirtualAlloc(preferredBase, allocSize, allocationType, PAGE_READWRITE);
if (base == NULL && preferredBase != NULL)
base = ClrVirtualAlloc(NULL, allocSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
base = ClrVirtualAlloc(NULL, allocSize, allocationType, PAGE_READWRITE);

if (base == NULL)
ThrowLastError();
Expand Down Expand Up @@ -819,9 +827,13 @@ void* FlatImageLayout::LoadImageByCopyingParts(SIZE_T* m_imageParts) const
// Finally, apply proper protection to copied sections
for (section = sectionStart; section < sectionEnd; section++)
{
DWORD executableProtection = PAGE_EXECUTE_READ;
#if defined(__APPLE__) && defined(HOST_ARM64)
executableProtection = PAGE_EXECUTE_READWRITE;
#endif
// Add appropriate page protection.
DWORD newProtection = section->Characteristics & IMAGE_SCN_MEM_EXECUTE ?
PAGE_EXECUTE_READ :
executableProtection :
section->Characteristics & IMAGE_SCN_MEM_WRITE ?
PAGE_READWRITE :
PAGE_READONLY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@
<OutputType>Exe</OutputType>
<RuntimeIdentifier>$(TestTargetRid)</RuntimeIdentifier>
</PropertyGroup>

<!--
Change for 6.0 for osx-arm64 as that is the earliest supported tfm.
Otherwise the test assets will fail to restore.
-->
<PropertyGroup Condition="'$(RuntimeIdentifier)' == 'osx-arm64'">
<TargetFrameworks>net6.0</TargetFrameworks>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Microsoft.NET.HostModel.Tests
{
[SkipOnPlatform(TestPlatforms.OSX, "Not supported on OSX.")]
public class BundleLegacy : IClassFixture<BundleLegacy.SharedTestState>
{
private SharedTestState sharedTestState;
Expand Down