From 2be05450835564dfede4b58457e32fc40ec68568 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 06b429ead4e00..fce865205b633 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 c4d62b9512ec8..ea18e57851418 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 6109187d5eba0e659cfcd2f0e7f649d74b223a4e 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 10cf437ccb3a4..71720994744c3 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 3ce137955a9f13cc9806efab3cd24ddee46e7bc8 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 792a3176eb129..dc937272d5ad1 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 57c5c8af4a1fe361dca659fbf25035a3dd864976 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 fce865205b633..06b429ead4e00 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 b9ae5c6560aa87226f46bc7839e492eb697aa783 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 dc937272d5ad1..e5cba8b0c816a 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