diff --git a/src/coreclr/vm/peimagelayout.cpp b/src/coreclr/vm/peimagelayout.cpp
index 792a3176eb129c..e5cba8b0c816ad 100644
--- a/src/coreclr/vm/peimagelayout.cpp
+++ b/src/coreclr/vm/peimagelayout.cpp
@@ -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();
@@ -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;
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
+
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;