Skip to content

coreclr: default EnableWriteXorExecute to 0 on OpenHarmony - #136131

Merged
jkotas merged 1 commit into
dotnet:mainfrom
springmin:pr/ohos-wx-default
Oct 20, 2026
Merged

jkotas merged 1 commit into
dotnet:mainfrom
springmin:pr/ohos-wx-default

Conversation

@springmin

Copy link
Copy Markdown
Contributor

Summary

The CoreCLR W^X allocator keeps code in a double mapping: a read-write view and a
read-execute view of the same memfd-backed pages. On OpenHarmony the sandbox denies
PROT_EXEC for those file-backed mappings, so the executable view cannot be created
and JIT-compiled code cannot run there; anonymous executable memory is allowed.

Default EnableWriteXorExecute to 0 on TARGET_OPENHARMONY, extending the condition
that already selects the RWX allocator for RISC-V, so OpenHarmony builds JIT out of the
box. The knob is otherwise unchanged: DOTNET_EnableWriteXorExecute=1 still requests
W^X.

Changes

  • src/coreclr/inc/clrconfigvalues.h: change the #ifdef TARGET_RISCV64 guard around
    EXTERNAL_EnableWriteXorExecute to
    #if defined(TARGET_RISCV64) || defined(TARGET_OPENHARMONY), so the default is 0 on
    both targets. Two comment lines record the sandbox reason; the trailing #endif
    comment follows.

Impact

  • OpenHarmony only. TARGET_OPENHARMONY is defined by the platform build support in
    Add OpenHarmony/HarmonyOS build infrastructure #132953; every other target, RISC-V included, takes the same branch as before and
    keeps the default of 1.
  • One file, 4 insertions and 2 deletions. No managed API, build, or test changes.
  • W^X stays available as an opt-in through DOTNET_EnableWriteXorExecute=1 for sandbox
    configurations that permit file-backed executable mappings.

Validation

  • On an OpenHarmony arm64 device, with DOTNET_EnableWriteXorExecute unset, a
    framework-dependent console app (DOTNET_ReadyToRun=0) runs to completion; the
    executable allocator reports no EACCES failures.
  • Negative control on the same build: DOTNET_EnableWriteXorExecute=1 fails when the
    allocator makes the double-mapped file executable, which is the failure this default
    avoids.
  • Direct probe behind the comment: on this device a memfd mapping cannot be given
    PROT_EXEC (mprotect returns EACCES), while an anonymous mapping can be flipped
    from RW to RX and executed.

Test

  1. Build CoreCLR for openharmony-arm64 with the OpenHarmony platform support from
    Add OpenHarmony/HarmonyOS build infrastructure #132953 (this defines TARGET_OPENHARMONY).
  2. On the device, run a framework-dependent console app with DOTNET_ReadyToRun=0 and
    no DOTNET_EnableWriteXorExecute set; it should complete normally.
  3. As a negative control, run the same app with DOTNET_EnableWriteXorExecute=1; it is
    expected to fail when code memory is made executable.
  4. Check that the diff against upstream/main is limited to the
    src/coreclr/inc/clrconfigvalues.h guard.

Note

This PR was authored with AI assistance (agent tooling) under the author's direction.

Ported from the OpenHarmony runtime integration branch.
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 20, 2026
springmin added a commit to springmin/runtime-ohos that referenced this pull request Oct 20, 2026
N5's squash is the current main tip; N9 was rebased onto it (5f93c6e,
1 file 4+/2-) and opened. In flight: N3/N4/N8/N9.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

@jkotas

jkotas commented Oct 20, 2026

Copy link
Copy Markdown
Member

/ba-g non-essential leg failed due to flaky network

@jkotas
jkotas merged commit d260b5c into dotnet:main Oct 20, 2026
109 of 112 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-VM-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants