This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
[Release/3.1] Port profiler APIs to set and retrieve environment variables to 3.1 #27512
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.
This ports #27157 to 3.1.
Issue
On linux/unix/mac platforms the PAL creates a cache of the system environment variables at startup since accessing environment variables is not thread safe. This means that any call the
putenv
orgetenv
by native code after process startup will be ignored in managed code or any child processes spawned by managed code.Profilers often use environment variables to communicate with child processes or managed code, historically on Windows they could just call SetEnvironmentVariable and it would be picked up, but now on cross plat scenarios the only workaround is to use IL rewriting to inject a call to
Environment.SetEnvironmentVariable
, which is a substantial amount of work if the profiler is not already doing IL rewriting.Customer impact
Without this fix profilers won't be able to coordinate with child processes while debugging. See this comment by the profiler author requesting this be included in 3.1:
Fix description
Expose the PAL's implementation of
SetEnvironmentVariable
andGetEnvironmentVariable
on the profiler interfaces.Risk
There is very low risk (essentially no risk) to existing codepaths since the existing codepaths are unchanged. This fix only exposes new functionality and does not modify existing behavior.