From 30e47bf82b0f58179fe2e5b865e3cb897e2e78a0 Mon Sep 17 00:00:00 2001 From: vsadov <8218165+VSadov@users.noreply.github.com> Date: Tue, 13 Dec 2022 14:55:36 -0800 Subject: [PATCH 1/5] force 6.0 instead of 3.0 on osx-arm64 --- .../tests/Assets/TestProjects/Directory.Build.props | 4 ++++ .../TestProjects/StandaloneApp3x/StandaloneApp3x.csproj | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/installer/tests/Assets/TestProjects/Directory.Build.props b/src/installer/tests/Assets/TestProjects/Directory.Build.props index 06b429ead4e00a..fce865205b633c 100644 --- a/src/installer/tests/Assets/TestProjects/Directory.Build.props +++ b/src/installer/tests/Assets/TestProjects/Directory.Build.props @@ -6,4 +6,8 @@ true + + + + diff --git a/src/installer/tests/Assets/TestProjects/StandaloneApp3x/StandaloneApp3x.csproj b/src/installer/tests/Assets/TestProjects/StandaloneApp3x/StandaloneApp3x.csproj index c4d62b9512ec81..ea18e578514187 100644 --- a/src/installer/tests/Assets/TestProjects/StandaloneApp3x/StandaloneApp3x.csproj +++ b/src/installer/tests/Assets/TestProjects/StandaloneApp3x/StandaloneApp3x.csproj @@ -5,4 +5,12 @@ Exe $(TestTargetRid) + + + + net6.0 + From 2c3840fe2d1a59003cc80d3b6073177bf447b8bd Mon Sep 17 00:00:00 2001 From: vsadov <8218165+VSadov@users.noreply.github.com> Date: Tue, 13 Dec 2022 16:41:42 -0800 Subject: [PATCH 2/5] disable legacy test on osx-arm64 --- .../Microsoft.NET.HostModel.Bundle.Tests/BundleLegacy.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundleLegacy.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundleLegacy.cs index 10cf437ccb3a48..71720994744c31 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundleLegacy.cs +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundleLegacy.cs @@ -10,6 +10,7 @@ namespace Microsoft.NET.HostModel.Tests { + [SkipOnPlatform(TestPlatforms.OSX, "Not supported on OSX.")] public class BundleLegacy : IClassFixture { private SharedTestState sharedTestState; From 8fa04e5407eba84a2e93350d8da6b5970fc1fa8f Mon Sep 17 00:00:00 2001 From: vsadov <8218165+VSadov@users.noreply.github.com> Date: Wed, 21 Dec 2022 14:34:27 -0800 Subject: [PATCH 3/5] fix osx-arm64 case --- src/coreclr/vm/peimagelayout.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/coreclr/vm/peimagelayout.cpp b/src/coreclr/vm/peimagelayout.cpp index 792a3176eb129c..dc937272d5ad17 100644 --- a/src/coreclr/vm/peimagelayout.cpp +++ b/src/coreclr/vm/peimagelayout.cpp @@ -775,10 +775,15 @@ void* FlatImageLayout::LoadImageByCopyingParts(SIZE_T* m_imageParts) const } #endif // FEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION + DWORD allocationType = MEM_RESERVE | MEM_COMMIT; +#if defined(__APPLE__) && defined(HOST_ARM64) + 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(); @@ -819,9 +824,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; From 8939561097413fa541e824a830f3d08eaf529c5c Mon Sep 17 00:00:00 2001 From: vsadov <8218165+VSadov@users.noreply.github.com> Date: Wed, 21 Dec 2022 15:53:08 -0800 Subject: [PATCH 4/5] undo unnecessary change --- src/installer/tests/Assets/TestProjects/Directory.Build.props | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/installer/tests/Assets/TestProjects/Directory.Build.props b/src/installer/tests/Assets/TestProjects/Directory.Build.props index fce865205b633c..06b429ead4e00a 100644 --- a/src/installer/tests/Assets/TestProjects/Directory.Build.props +++ b/src/installer/tests/Assets/TestProjects/Directory.Build.props @@ -6,8 +6,4 @@ true - - - - From 3910401baec3a692f44f400be28be4c045f8f24e Mon Sep 17 00:00:00 2001 From: vsadov <8218165+VSadov@users.noreply.github.com> Date: Wed, 21 Dec 2022 16:57:59 -0800 Subject: [PATCH 5/5] use MEM_RESERVE_EXECUTABLE on HOST_UNIX --- src/coreclr/vm/peimagelayout.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/peimagelayout.cpp b/src/coreclr/vm/peimagelayout.cpp index dc937272d5ad17..e5cba8b0c816ad 100644 --- a/src/coreclr/vm/peimagelayout.cpp +++ b/src/coreclr/vm/peimagelayout.cpp @@ -776,7 +776,10 @@ void* FlatImageLayout::LoadImageByCopyingParts(SIZE_T* m_imageParts) const #endif // FEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION DWORD allocationType = MEM_RESERVE | MEM_COMMIT; -#if defined(__APPLE__) && defined(HOST_ARM64) +#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