Skip to content

Remove GetCommandLineW from PAL#125386

Open
huoyaoyuan wants to merge 11 commits intodotnet:mainfrom
huoyaoyuan:pal/commandline
Open

Remove GetCommandLineW from PAL#125386
huoyaoyuan wants to merge 11 commits intodotnet:mainfrom
huoyaoyuan:pal/commandline

Conversation

@huoyaoyuan
Copy link
Member

No description provided.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 10, 2026
Comment on lines +3742 to +3744
// exePath contains the full path to the executable.
MAKE_WIDEPTR_FROMUTF8(exePath, minipal_getexepath());
SIZE_T commandLineLen = (u16_strlen(exePath) + 1);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a potential behavioral change. Now it will always use the executable path of current process, instead of exePath from coreclr_initialize. This is only used through ep_rt_diagnostics_command_line_get.

Comment on lines +3690 to +3693
#ifdef TARGET_WINDOWS
// Use the result from GetCommandLineW() instead
pCmdLine = GetCommandLineW();
#endif // HOST_WINDOWS
Copy link
Member Author

Choose a reason for hiding this comment

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

This could affect ep for hosted dll. In nativeaot /proc/self/cmdline is used.

What's the desired semantic here?

Copy link
Member

Choose a reason for hiding this comment

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

A couple scenarios that his this:

  1. Access violation - coreclr!EventPipeEventSource::SendProcessInfo+0x135 #12656 - This was the issue the fallback was added to fix. Presumably unless we find some alternate solution then this PR would re-introduce that issue which we wouldn't want. I don't know that there is a well documented semantic but the low risk approach is that we would preserve the pre-existing behavior exactly. If we don't think we can do that, or we don't want to do that then it would be good to understand what are we gaining that would justify the compat risk.

  2. There are GetProcessInfo IPC commands (multiple variants) which also call into this code:
    server_thread
    -> server_loop_tick
    -> ds_process_protocol_helper_handle_ipc_message
    -> process_protocol_helper_get_process_info // command 0x00
    process_protocol_helper_get_process_info_2 // command 0x04
    process_protocol_helper_get_process_info_3 // command 0x08
    -> ep_rt_diagnostics_command_line_get
    -> GetCommandLineForDiagnostics

Those commands have documented behavior here. The expectation is that those commands are legal for tools to call as soon as the IPC server starts up (dotnet-monitor is one use-case). I believe that occurs before GetManagedCommandLine() is populated so those commands probably come down this fallback path as well and returning NULL won't work.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. Since the documentation specifies argv[0], I assume the OS-native executable path should be desirable.

@jkoritzinsky
Copy link
Member

@dotnet/dotnet-diag-contrib for the EventPipe impact

@lateralusX
Copy link
Member

lateralusX commented Mar 12, 2026

What is the motivation behind doing the change?

@huoyaoyuan
Copy link
Member Author

The motivation is to cleanup PAL layer and transit to minipal gradually.

// Use the result from GetCommandLineW() instead
pCmdLine = GetCommandLineW();
#else
pCmdLine = W("");
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we can just return a sentinel. We need to return similar results to what GetCommandLineW() would have returned before the change. I'm not sure if that means adjusting the timeline so that GetManagedCommandLine() gets populated earlier or maybe it means something similar to GetCommandLineW() needs to stay in the PAL.

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

Labels

area-PAL-coreclr community-contribution Indicates that the PR has been added by a community member EventPipe

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants