Skip to content

Conversation

@kotlarmilos
Copy link
Member

Description

This change prevents the runtime from emitting native machine code at execution time through StubLinkerCPU on platforms where dynamic code generation is not allowed due to W^X and code-signing restrictions. Currently, unboxing and generic instantiating stubs still generate arm64 code via CPUSTUBLINKER that works as a lightweight JIT, because FEATURE_PORTABLE_SHUFFLE_THUNKS is enabled on all non-x86 targets.

Changes

This PR renames FEATURE_PORTABLE_SHUFFLE_THUNKS to FEATURE_SHUFFLE_THUNKS and only enables it when FEATURE_JIT is available. This instructs Apple mobile to use IL-based unboxing and instantiating stubs instead of emitting code at runtime, avoiding invalid memory execution.

Copilot AI review requested due to automatic review settings October 27, 2025 15:02
@kotlarmilos kotlarmilos self-assigned this Oct 27, 2025
@kotlarmilos kotlarmilos added this to the 11.0.0 milestone Oct 27, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses a critical runtime issue on iOS and other Apple mobile platforms where dynamic code generation is prohibited due to W^X (write XOR execute) memory protection and code-signing restrictions. The change prevents the runtime from attempting to emit native ARM64 machine code at execution time for unboxing and instantiating stubs.

Key Changes:

  • Renamed FEATURE_PORTABLE_SHUFFLE_THUNKS to FEATURE_SHUFFLE_THUNKS and made it conditional on FEATURE_JIT availability
  • Extended ARM64 platforms to use IL-based stubs instead of runtime code generation when JIT is unavailable
  • Updated conditional compilation directives across multiple files to respect the new feature flag semantics

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/coreclr/inc/switches.h Modified feature flag definition to only enable shuffle thunks when JIT is available
src/coreclr/vm/prestub.cpp Updated conditional compilation to use renamed feature flag for stub selection logic
src/coreclr/vm/i386/stublinkerx86.h Changed guard condition for EmitUnboxMethodStub declaration from TARGET_X86 to feature-based check
src/coreclr/vm/i386/stublinkerx86.cpp Updated conditional compilation for EmitUnboxMethodStub implementation
src/coreclr/vm/comdelegate.cpp Reorganized shuffle array generation logic to use feature flag instead of platform-specific checks
src/coreclr/vm/arm64/stubs.cpp Added ARM64 implementation of EmitUnboxMethodStub for non-JIT scenarios
src/coreclr/vm/arm64/cgencpu.h Added EmitUnboxMethodStub method declaration guarded by feature flag

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @BrzVlad, @janvorli, @kg
See info in area-owners.md if you want to be subscribed.

@jkotas
Copy link
Member

jkotas commented Oct 29, 2025

@kotlarmilos Could you please check whether it is still fixing the problem that it was meant to fix?

@kotlarmilos
Copy link
Member Author

kotlarmilos commented Oct 29, 2025

Thanks Jan, this was educational :) I confirm it fixes dynamic code generation for MakeUnboxingStubWorker and MakeInstantiatingStubWorker.

@kotlarmilos kotlarmilos requested a review from jkotas October 29, 2025 10:39
@jkotas
Copy link
Member

jkotas commented Oct 29, 2025

/ba-g infrastructure timeouts

@jkotas jkotas merged commit 5219f86 into dotnet:main Oct 29, 2025
94 of 98 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants