-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert fallback path of GetCommandLineArgs to managed #70608
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
39d2f90
P/Invoke definition
huoyaoyuan bc6540a
Use P/Invoke in managed code
huoyaoyuan 9711a33
Delete FCall definition
huoyaoyuan e36103c
Update managed call site
huoyaoyuan aaa5def
Add test using private reflection
huoyaoyuan 03d582a
Apply suggestions from code review
jkotas a3b3db5
Revert "Add test using private reflection"
huoyaoyuan 01eeb9e
Add managed test
huoyaoyuan 4ff89e1
Dispose result of RemoteExecutor
huoyaoyuan 9ebedfe
Native command line should be superset of managed
huoyaoyuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
13 changes: 13 additions & 0 deletions
13
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetCommandLine.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
internal static unsafe partial class Interop | ||
{ | ||
internal static partial class Kernel32 | ||
{ | ||
[LibraryImport(Libraries.Kernel32, EntryPoint = "GetCommandLineW")] | ||
internal static partial char* GetCommandLine(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/libraries/Common/src/Interop/Windows/Shell32/Interop.CommandLineToArgv.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
internal static unsafe partial class Interop | ||
{ | ||
internal static partial class Shell32 | ||
{ | ||
[LibraryImport(Libraries.Shell32, EntryPoint = "CommandLineToArgvW")] | ||
internal static partial char** CommandLineToArgv(char* lpCommandLine, int* pNumArgs); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,5 +70,38 @@ public static int CheckCommandLineArgs(string[] args) | |
|
||
return RemoteExecutor.SuccessExitCode; | ||
} | ||
|
||
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] | ||
public void GetCommandLineArgs_Fallback_Returns() | ||
{ | ||
if (PlatformDetection.IsNotMonoRuntime | ||
&& PlatformDetection.IsNotNativeAot | ||
&& PlatformDetection.IsWindows) | ||
{ | ||
// Currently fallback command line is only implemented on Windows coreclr | ||
RemoteExecutor.Invoke(CheckCommandLineArgsFallback).Dispose(); | ||
} | ||
} | ||
|
||
public static int CheckCommandLineArgsFallback() | ||
{ | ||
string[] oldArgs = Environment.GetCommandLineArgs(); | ||
|
||
// Clear the command line args set for managed entry point | ||
var field = typeof(Environment).GetField("s_commandLineArgs", BindingFlags.Static | BindingFlags.NonPublic); | ||
Assert.NotNull(field); | ||
field.SetValue(null, null); | ||
|
||
string[] args = Environment.GetCommandLineArgs(); | ||
Assert.NotEmpty(args); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we compare the return value with the original command line? The new value should be a super-set of the original command line. |
||
|
||
// The native command line should be superset of managed command line | ||
foreach (string arg in oldArgs) | ||
{ | ||
Assert.Contains(arg, args); | ||
} | ||
|
||
return RemoteExecutor.SuccessExitCode; | ||
} | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only other use of SegmentCommandLine is in ildasm that can be eliminated by just using the arguments passed into the main method. It would allow us to delete the
SegmentCommandLine
method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If ilasm and ildasm could share the same
main()
, that would also cleanup a lot of code indirection. They are logically doing the same thing (initialize PAL on Unix, and switch over command line args etc.), but ilasm's main implementation is much neater than that of ildasm's.(in a larger picture, corehost and corerun are also candidate of this consolidations, currently they both have their own PAL)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I mentioned this, but I'm not sure if they should be in one PR.
Ideally, many
main
s can share more code, which is some how out of scope.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is infinite amount of cleanup one can do in ilasm/ildasm. I would rather look into C# rewrite than trying to cleanup the existing C/C++ code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkoritzinsky and I have talked about a ilasm/ildasm rewrite for a myriad of reasons. There are many concerns with that but I agree effort to clean-up both code bases is low priority.