Skip to content

Commit

Permalink
[release/7.0] Fixing compressed singlefile scenario on osx-arm64 (#80283
Browse files Browse the repository at this point in the history
)

* 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>
  • Loading branch information
github-actions[bot] and VSadov authored Jan 11, 2023
1 parent 49b1255 commit ed6eab9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
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

0 comments on commit ed6eab9

Please sign in to comment.