Skip to content

Commit ed6eab9

Browse files
[release/7.0] Fixing compressed singlefile scenario on osx-arm64 (#80283)
* force 6.0 instead of 3.0 on osx-arm64 * disable legacy test on osx-arm64 * fix osx-arm64 case * undo unnecessary change * use MEM_RESERVE_EXECUTABLE on HOST_UNIX Co-authored-by: vsadov <8218165+VSadov@users.noreply.github.com>
1 parent 49b1255 commit ed6eab9

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/coreclr/vm/peimagelayout.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,18 @@ void* FlatImageLayout::LoadImageByCopyingParts(SIZE_T* m_imageParts) const
775775
}
776776
#endif // FEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION
777777

778+
DWORD allocationType = MEM_RESERVE | MEM_COMMIT;
779+
#ifdef HOST_UNIX
780+
// Tell PAL to use the executable memory allocator to satisfy this request for virtual memory.
781+
// This is required on MacOS and otherwise will allow us to place native R2R code close to the
782+
// coreclr library and thus improve performance by avoiding jump stubs in managed code.
783+
allocationType |= MEM_RESERVE_EXECUTABLE;
784+
#endif
785+
778786
COUNT_T allocSize = ALIGN_UP(this->GetVirtualSize(), g_SystemInfo.dwAllocationGranularity);
779-
LPVOID base = ClrVirtualAlloc(preferredBase, allocSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
787+
LPVOID base = ClrVirtualAlloc(preferredBase, allocSize, allocationType, PAGE_READWRITE);
780788
if (base == NULL && preferredBase != NULL)
781-
base = ClrVirtualAlloc(NULL, allocSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
789+
base = ClrVirtualAlloc(NULL, allocSize, allocationType, PAGE_READWRITE);
782790

783791
if (base == NULL)
784792
ThrowLastError();
@@ -819,9 +827,13 @@ void* FlatImageLayout::LoadImageByCopyingParts(SIZE_T* m_imageParts) const
819827
// Finally, apply proper protection to copied sections
820828
for (section = sectionStart; section < sectionEnd; section++)
821829
{
830+
DWORD executableProtection = PAGE_EXECUTE_READ;
831+
#if defined(__APPLE__) && defined(HOST_ARM64)
832+
executableProtection = PAGE_EXECUTE_READWRITE;
833+
#endif
822834
// Add appropriate page protection.
823835
DWORD newProtection = section->Characteristics & IMAGE_SCN_MEM_EXECUTE ?
824-
PAGE_EXECUTE_READ :
836+
executableProtection :
825837
section->Characteristics & IMAGE_SCN_MEM_WRITE ?
826838
PAGE_READWRITE :
827839
PAGE_READONLY;

src/installer/tests/Assets/TestProjects/StandaloneApp3x/StandaloneApp3x.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@
55
<OutputType>Exe</OutputType>
66
<RuntimeIdentifier>$(TestTargetRid)</RuntimeIdentifier>
77
</PropertyGroup>
8+
9+
<!--
10+
Change for 6.0 for osx-arm64 as that is the earliest supported tfm.
11+
Otherwise the test assets will fail to restore.
12+
-->
13+
<PropertyGroup Condition="'$(RuntimeIdentifier)' == 'osx-arm64'">
14+
<TargetFrameworks>net6.0</TargetFrameworks>
15+
</PropertyGroup>
816
</Project>

src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundleLegacy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Microsoft.NET.HostModel.Tests
1212
{
13+
[SkipOnPlatform(TestPlatforms.OSX, "Not supported on OSX.")]
1314
public class BundleLegacy : IClassFixture<BundleLegacy.SharedTestState>
1415
{
1516
private SharedTestState sharedTestState;

0 commit comments

Comments
 (0)