镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Move environment APIs into shared minipal - #137144

Open
am11 wants to merge 24 commits into
dotnet:mainfrom
am11:chore/minipal-environ
Open

am11 wants to merge 24 commits into
dotnet:mainfrom
am11:chore/minipal-environ

Conversation

@am11

@am11 am11 commented Nov 7, 2026

Copy link
Copy Markdown
Member

and delete coreclr-pal layer and tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
@am11
am11 requested a review from jkotas November 7, 2026 22:28
@github-actions github-actions Bot added the area-PAL-coreclr only for closed issues label Nov 7, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
11 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 dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 7, 2026
Comment thread src/native/minipal/environ.c Resolved
@am11
am11 force-pushed the chore/minipal-environ branch from a3a0a9f to 7ca2c4b Compare November 8, 2026 00:00
setenv is not safe while other threads read the environment, so the runtime's
native setters (diagnostics server, profiler) now update a private copy, as the
PAL did. corerun goes back to libc setenv since it runs before the runtime
starts, and child processes are launched with the copy.

Co-authored-by: Cursor <cursoragent@cursor.com>
am11 and others added 2 commits November 8, 2026 13:52
On CoreCLR and NativeAOT, Environment.Get/SetEnvironmentVariable and
GetEnvironmentVariables now use QCalls backed by the minipal environment
copy, so changes made by ICorProfilerInfo11::SetEnvironmentVariable or the
diagnostic server are visible to managed code and vice versa.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread src/native/minipal/environ.c Resolved
am11 and others added 4 commits November 8, 2026 22:25
minipal environment APIs are now stateless. The lock-protected copy lives in
src/coreclr/runtime/ProcessEnvironment.cpp and is used only by the profiler
and diagnostic server environment APIs, managed Environment, runtime
configuration and the createdump child environment.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	src/coreclr/hosts/corerun/corerun.hpp
#	src/coreclr/nativeaot/Runtime/windows/PalMinWin.cpp
#	src/coreclr/pal/src/init/pal.cpp
#	src/coreclr/pal/src/misc/environ.cpp
#	src/coreclr/pal/tests/palsuite/CMakeLists.txt
#	src/coreclr/tools/superpmi/superpmi-shared/spmiutil.cpp
#	src/coreclr/tools/superpmi/superpmi/jithost.cpp

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

An unresolved Windows environment-read race can return an uninitialized, potentially unterminated buffer when a variable is deleted between lookups.

6 open issues
What changed in this PR

Moves environment access out of CoreCLR’s legacy PAL into shared minipal helpers and a runtime-owned environment store used by CoreCLR and NativeAOT.

Changes:

  • Adds shared environment readers and a synchronized Unix environment copy, exposed to managed code through QCalls.
  • Migrates runtime configuration, diagnostics, hosts, and tools to the new helpers.
  • Removes the legacy PAL implementation, declarations, and associated tests.

Review was source-based; no builds or tests were run.

File Description
src/​native/​minipal/​environ.h Defines shared environment APIs and ownership contracts.
src/​native/​minipal/​environ.c Implements environment lookup and snapshots.
src/​native/​minipal/​CMakeLists.txt Builds the new environment implementation.
src/​libraries/​System.Private.CoreLib/​src/​System/​Environment.Variables.Native.cs Adds QCall-backed managed environment access.
src/​libraries/​System.Private.CoreLib/​src/​System.Private.CoreLib.Shared.projitems Selects environment implementations by runtime.
src/​coreclr/​vm/​wasm/​wasi/​callhelpers-pinvoke.cpp Updates WASI environment QCall bindings.
src/​coreclr/​vm/​wasm/​browser/​callhelpers-pinvoke.cpp Updates browser environment QCall bindings.
src/​coreclr/​vm/​qcallentrypoints.cpp Registers replacement environment QCalls.
src/​coreclr/​vm/​proftoeeinterfaceimpl.cpp Routes profiler operations through ProcessEnvironment.
src/​coreclr/​vm/​perfmap.cpp Removes the PAL-specific configuration callback.
src/​coreclr/​vm/​gdbjit.cpp Uses minipal for debugger configuration lookup.
src/​coreclr/​vm/​eventing/​eventpipe/​ep-rt-coreclr.h Reads runtime-owned environment snapshots.
src/​coreclr/​vm/​eventing/​eventpipe/​ds-rt-coreclr.h Migrates diagnostic environment operations.
src/​coreclr/​vm/​CMakeLists.txt Builds ProcessEnvironment into CoreCLR.
src/​coreclr/​utilcode/​longfilepathwrappers.cpp Adapts environment wrappers to minipal.
src/​coreclr/​utilcode/​executableallocator.cpp Uses an owned environment-value copy.
src/​coreclr/​utilcode/​clrconfig.cpp Adds runtime environment callbacks.
src/​coreclr/​tools/​superpmi/​superpmi/​parallelsuperpmi.cpp Migrates temporary-directory lookup.
src/​coreclr/​tools/​superpmi/​superpmi/​jithost.cpp Migrates prefixed environment lookup.
src/​coreclr/​tools/​superpmi/​superpmi-shared/​spmiutil.cpp Migrates buffer-based lookups; clarifies a comment.
src/​coreclr/​runtime/​ProcessEnvironment.h Declares the runtime environment abstraction.
src/​coreclr/​runtime/​ProcessEnvironment.cpp Implements runtime-owned Unix environment storage.
src/​coreclr/​runtime/​MiscNativeHelpers.h Declares environment QCalls.
src/​coreclr/​runtime/​MiscNativeHelpers.cpp Implements managed environment bridges.
src/​coreclr/​pal/​tests/​palsuite/​paltestlist.txt Removes legacy environment test registrations.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​SetEnvironmentVariableW/​test4/​test4.cpp Removes the Windows case-handling test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​SetEnvironmentVariableW/​test3/​test3.cpp Removes the Unix case-handling test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​SetEnvironmentVariableW/​test2/​test.cpp Removes null-input and deletion tests.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​SetEnvironmentVariableW/​test1/​test.cpp Removes wide-value mutation tests.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​SetEnvironmentVariableA/​test4/​test4.cpp Removes the Windows case-handling test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​SetEnvironmentVariableA/​test3/​test3.cpp Removes the Unix case-handling test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​SetEnvironmentVariableA/​test2/​test2.cpp Removes null-input and deletion tests.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​SetEnvironmentVariableA/​test1/​test1.cpp Removes narrow-value mutation tests.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​GetEnvironmentVariableW/​test6/​test6.cpp Removes the Windows case-insensitive lookup test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​GetEnvironmentVariableW/​test5/​test5.cpp Removes the Unix case-sensitive lookup test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​GetEnvironmentVariableW/​test4/​test.cpp Removes the wide-value retrieval test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​GetEnvironmentVariableW/​test3/​test.cpp Removes missing/null-name lookup tests.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​GetEnvironmentVariableW/​test2/​test.cpp Removes the undersized wide-buffer test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​GetEnvironmentVariableW/​test1/​test.cpp Removes the wide-buffer sizing test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​GetEnvironmentVariableA/​test6/​test6.cpp Removes the Windows case-insensitive lookup test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​GetEnvironmentVariableA/​test5/​test5.cpp Removes the Unix case-sensitive lookup test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​GetEnvironmentVariableA/​test4/​test.cpp Removes the narrow-value retrieval test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​GetEnvironmentVariableA/​test3/​test.cpp Removes missing/null-name lookup tests.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​GetEnvironmentVariableA/​test2/​test.cpp Removes the undersized narrow-buffer test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​GetEnvironmentVariableA/​test1/​test.cpp Removes the narrow-buffer sizing test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​GetEnvironmentStringsW/​test1/​test.cpp Removes the environment enumeration test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​FreeEnvironmentStringsW/​test2/​test.cpp Removes permissive environment-block freeing tests.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​FreeEnvironmentStringsW/​test1/​test.cpp Removes the snapshot cleanup test.
src/​coreclr/​pal/​tests/​palsuite/​compilableTests.txt Removes deleted tests from the compilation list.
src/​coreclr/​pal/​tests/​palsuite/​CMakeLists.txt Removes deleted test sources.
src/​coreclr/​pal/​src/​thread/​thread.cpp Drops the obsolete environment header.
src/​coreclr/​pal/​src/​thread/​process.cpp Adds createdump environment callbacks and minipal lookup.
src/​coreclr/​pal/​src/​misc/​perfjitdump.cpp Migrates timestamp-option lookup.
src/​coreclr/​pal/​src/​misc/​environ.cpp Deletes the legacy PAL environment implementation.
src/​coreclr/​pal/​src/​misc/​dbgmsg.cpp Migrates debug settings to owned minipal values.
src/​coreclr/​pal/​src/​loader/​module.cpp Drops the obsolete environment header.
src/​coreclr/​pal/​src/​init/​pal.cpp Removes PAL environment initialization.
src/​coreclr/​pal/​src/​include/​pal/​environ.h Deletes internal PAL environment declarations.
src/​coreclr/​pal/​src/​exception/​machmessage.h Uses libc for the tracing flag.
src/​coreclr/​pal/​src/​exception/​machmessage.cpp Drops the obsolete environment header.
src/​coreclr/​pal/​src/​exception/​machexception.cpp Migrates exception-mode lookup.
src/​coreclr/​pal/​src/​debug/​debug.cpp Migrates settings and constructs debugger child environments.
src/​coreclr/​pal/​src/​configure.cmake Removes obsolete environment capability checks.
src/​coreclr/​pal/​src/​config.h.in Removes obsolete environment configuration macros.
src/​coreclr/​pal/​src/​CMakeLists.txt Stops building the deleted implementation.
src/​coreclr/​pal/​inc/​palprivate.h Removes narrow PAL environment declarations.
src/​coreclr/​pal/​inc/​pal.h Removes legacy APIs and adds the createdump callback.
src/​coreclr/​pal/​inc/​pal_error.h Removes the environment-initialization error constant.
src/​coreclr/​nativeaot/​Runtime/​windows/​PalMinWin.cpp Delegates Windows lookup to minipal.
src/​coreclr/​nativeaot/​Runtime/​unix/​PalUnix.cpp Reads the runtime-owned environment.
src/​coreclr/​nativeaot/​Runtime/​unix/​PalCreateDump.cpp Passes runtime environment data to createdump.
src/​coreclr/​nativeaot/​Runtime/​eventpipe/​ep-rt-aot.h Migrates temporary-directory lookup and cleanup.
src/​coreclr/​nativeaot/​Runtime/​eventpipe/​ep-rt-aot.cpp Uses shared runtime environment snapshots.
src/​coreclr/​nativeaot/​Runtime/​eventpipe/​ds-rt-aot.cpp Routes diagnostic mutations through ProcessEnvironment.
src/​coreclr/​nativeaot/​Runtime/​CMakeLists.txt Builds ProcessEnvironment into NativeAOT.
src/​coreclr/​minipal/​Unix/​mapping.cpp Migrates mapping-option lookup.
src/​coreclr/​inc/​clrconfig.h Declares environment configuration callbacks.
src/​coreclr/​hosts/​coreshim/​CoreShim.cpp Migrates host environment lookup.
src/​coreclr/​hosts/​coreshim/​CMakeLists.txt Links CoreShim with minipal.
src/​coreclr/​hosts/​corerun/​corerun.hpp Migrates Windows host environment helpers.
src/​coreclr/​dlls/​mscoree/​exports.cpp Installs runtime environment callbacks during startup.
src/​coreclr/​dlls/​mscordac/​mscordac_unixexports.src Removes commented legacy environment export entries.
src/​coreclr/​debug/​di/​process.cpp Migrates debugger test-option lookup.
src/​coreclr/​debug/​daccess/​daccess.cpp Migrates DAC debug-mode lookup.
src/​coreclr/​debug/​createdump/​shared/​createdumpunixcore.cpp Migrates pagemap-option lookup and cleanup.
src/​coreclr/​debug/​createdump/​createdumpmain.cpp Migrates dump-directory lookup and cleanup.

Review effort: Balanced

Comment thread src/native/minipal/environ.c Resolved
Comment thread src/coreclr/pal/src/debug/debug.cpp Resolved
Comment thread src/coreclr/vm/perfmap.cpp Resolved
Comment thread src/native/minipal/environ.c Resolved
am11 and others added 3 commits November 9, 2026 00:19
- Report presence and length from a single lookup so empty values are
  distinguished from missing ones in the profiler API and the QCall.
- Read PerfMapJitDumpPath from the runtime's environment copy, as main did
  with PAL_getenv.
- Drop inherited PAL_EXE_PID/PAL_EXE_NAME before adding the new values.
- Handle a variable removed between the probe and the read on Windows.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	src/coreclr/pal/src/misc/dbgmsg.cpp
#	src/coreclr/pal/src/misc/environ.cpp
#	src/coreclr/pal/tests/palsuite/miscellaneous/GetEnvironmentStringsW/test1/test.cpp
#	src/coreclr/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test4/test.cpp
#	src/coreclr/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test5/test5.cpp
#	src/coreclr/pal/tests/palsuite/miscellaneous/GetEnvironmentVariableW/test6/test6.cpp
#	src/coreclr/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp
#	src/coreclr/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test3/test3.cpp
#	src/coreclr/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test4/test4.cpp
Co-authored-by: Cursor <cursoragent@cursor.com>
@am11
am11 requested a review from jkotas November 9, 2026 18:32
@jkotas
jkotas requested a balanced review from Copilot November 10, 2026 21:32
Comment thread src/coreclr/pal/inc/pal.h Resolved
Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The retry path can return the same pooled array twice if the next Rent throws, potentially allowing unrelated callers to rent the same storage.

1 open issue
4 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread src/coreclr/pal/src/thread/process.cpp Resolved
Comment thread src/native/minipal/environ.c Resolved
Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

An empty inherited environment entry prematurely terminates the copied block, causing managed GetEnvironmentVariables() to omit subsequent valid variables.

1 open issue
1 resolved since last review

Review effort: Balanced

am11 and others added 2 commits November 12, 2026 10:47
Skip empty environment variable entries during copy.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread src/native/minipal/environ.c Resolved
Comment thread src/coreclr/pal/src/misc/dbgmsg.cpp Resolved
am11 and others added 4 commits November 13, 2026 09:35
Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	src/coreclr/vm/runtimehelpers.cpp
#	src/coreclr/vm/wasm/browser/callhelpers-pinvoke.cpp
#	src/coreclr/vm/wasm/wasi/callhelpers-pinvoke.cpp
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-PAL-coreclr only for closed issues 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.

3 participants