Skip to content

Prototype fix for Environement.GetCommandLineArgs()[0] (#101837) - #101880

Closed
xoofx wants to merge 1 commit into
dotnet:mainfrom
xoofx:fix-argv0-GetCommandLineArgs
Closed

xoofx wants to merge 1 commit into
dotnet:mainfrom
xoofx:fix-argv0-GetCommandLineArgs

Conversation

@xoofx

@xoofx xoofx commented May 5, 2024 •

Copy link
Copy Markdown
Member

Fixes #101837

I'm putting this PR in a draft state, as the code in this PR is hacking around with the restriction of the existing API. As I believe that the API CorHost2::ExecuteAssembly cannot be changed, so it makes the correction trickier. I would appreciate guidance on how to solve this properly.

Another aspect that I'm unfamiliar with is how dotnet.exe foo.dll relates to the changes made here. It could definitely be broken by these changes.

@ghost ghost added the area-Host label May 5, 2024
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label May 5, 2024
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

CONTRACTL_END;

// If argc is negative if argv includes the original argv[0]
PCWSTR exePath;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
PCWSTR exePath;
PCWSTR invocationName;

@jkotas
jkotas requested a review from elinor-fung May 5, 2024 16:17
@jkotas

jkotas commented May 5, 2024

Copy link
Copy Markdown
Member

@elinor-fung What would be the best way to pass the original argv[0] from the C main entrypoint all the way to the corelib?

@elinor-fung

Copy link
Copy Markdown
Member

Another aspect that I'm unfamiliar with is how dotnet.exe foo.dll relates to the changes made here. It could definitely be broken by these changes.

The product executable - so dotnet for dotnet.exe foo.dll or apphost for foo.exe (as opposed to corerun used for testing) - is at:

#if defined(_WIN32)
int __cdecl wmain(const int argc, const pal::char_t* argv[])
#else
int main(const int argc, const pal::char_t* argv[])
#endif

It has the FEATURE_APPHOST define to distinguish between apphost and dotnet.

We could make the host_runtime_contract implementation return a property that represents the invocation name, so the runtime could use HostInformation to get it and set the command line in managed.

@elinor-fung

Copy link
Copy Markdown
Member

Actually, I wonder if it would make sense to change the exePath parameter for coreclr_initialize to actually be the invocation name instead. It seems like it is just used for PAL_InitializeCoreCLR to set the command line that gets returned by the PAL GetCommandLine (in which case the actual argv[0] is probably more fitting) and to set the bundle path for single-file (which can just use the current executable path).

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@github-actions github-actions Bot locked and limited conversation to collaborators Jul 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Host 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.

Environment.ProcessPath / Environment.GetCommandLineArgs()[0] discrepancies

3 participants