Repository navigation
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
|
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. |
jkotas
reviewed
Nov 7, 2026
am11
force-pushed
the
chore/minipal-environ
branch
from
November 8, 2026 00:00
a3a0a9f to
7ca2c4b
Compare
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>
3 tasks
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>
jkotas
reviewed
Nov 8, 2026
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
…e/minipal-environ
Contributor
There was a problem hiding this comment.
🟡 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
Reject failed second reads before returning the buffer · New Filter inherited PAL process entries before prepending overrides · New Preserve lone surrogates in NativeAOT environment values · New Read PerfMap config from the runtime environment copy · New Distinguish empty variables from missing variables in lookups · New Use UTF-8 conversions for Windows environment lookups · New
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
- 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>
jkotas
reviewed
Nov 10, 2026
jkotas
reviewed
Nov 10, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
jkotas
reviewed
Nov 10, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
jkotas
reviewed
Nov 11, 2026
jkotas
reviewed
Nov 11, 2026
jkotas
reviewed
Nov 11, 2026
This was referenced Nov 11, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
Skip empty environment variable entries during copy. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
jkotas
reviewed
Nov 13, 2026
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
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.



and delete coreclr-pal layer and tests.