Repository navigation
coreclr: default EnableWriteXorExecute to 0 on OpenHarmony - #136131
Merged
Merged
Conversation
Ported from the OpenHarmony runtime integration branch.
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: 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. |
Contributor
|
Tagging subscribers to this area: @agocke |
jkotas
approved these changes
Oct 20, 2026
Member
|
/ba-g non-essential leg failed due to flaky network |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_EXECfor those file-backed mappings, so the executable view cannot be createdand JIT-compiled code cannot run there; anonymous executable memory is allowed.
Default
EnableWriteXorExecuteto 0 onTARGET_OPENHARMONY, extending the conditionthat already selects the RWX allocator for RISC-V, so OpenHarmony builds JIT out of the
box. The knob is otherwise unchanged:
DOTNET_EnableWriteXorExecute=1still requestsW^X.
Changes
src/coreclr/inc/clrconfigvalues.h: change the#ifdef TARGET_RISCV64guard aroundEXTERNAL_EnableWriteXorExecuteto#if defined(TARGET_RISCV64) || defined(TARGET_OPENHARMONY), so the default is 0 onboth targets. Two comment lines record the sandbox reason; the trailing
#endifcomment follows.
Impact
TARGET_OPENHARMONYis defined by the platform build support inAdd OpenHarmony/HarmonyOS build infrastructure #132953; every other target, RISC-V included, takes the same branch as before and
keeps the default of 1.
DOTNET_EnableWriteXorExecute=1for sandboxconfigurations that permit file-backed executable mappings.
Validation
DOTNET_EnableWriteXorExecuteunset, aframework-dependent console app (
DOTNET_ReadyToRun=0) runs to completion; theexecutable allocator reports no
EACCESfailures.DOTNET_EnableWriteXorExecute=1fails when theallocator makes the double-mapped file executable, which is the failure this default
avoids.
PROT_EXEC(mprotectreturnsEACCES), while an anonymous mapping can be flippedfrom RW to RX and executed.
Test
openharmony-arm64with the OpenHarmony platform support fromAdd OpenHarmony/HarmonyOS build infrastructure #132953 (this defines
TARGET_OPENHARMONY).DOTNET_ReadyToRun=0andno
DOTNET_EnableWriteXorExecuteset; it should complete normally.DOTNET_EnableWriteXorExecute=1; it isexpected to fail when code memory is made executable.
upstream/mainis limited to thesrc/coreclr/inc/clrconfigvalues.hguard.Note
This PR was authored with AI assistance (agent tooling) under the author's direction.