Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAtsushi Kanamori <AtsushiKan@users.noreply.github.com>2017-06-14 20:28:45 +0300
committerGitHub <noreply@github.com>2017-06-14 20:28:45 +0300
commit0d5eeb0cd3a13deb06762ef6f6bdab9171334a21 (patch)
treeeb47130acb0ff921126be6a5a4d76f254f686d05
parent724bb2d90ed860902b43093f6e2457aa11bd6443 (diff)
Make Environment.GetCommandLineArgs() PNSE on Project N (#3881)
As opposed to NRE'ing due to using the result of a startup helper that doesn't exist on the N toolchain...
-rw-r--r--src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.CoreRT.cs61
-rw-r--r--src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.ProjectN.cs23
-rw-r--r--src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.cs52
-rw-r--r--src/System.Private.CoreLib/src/Resources/Strings.resx3
-rw-r--r--src/System.Private.CoreLib/src/System.Private.CoreLib.csproj5
5 files changed, 82 insertions, 62 deletions
diff --git a/src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.CoreRT.cs b/src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.CoreRT.cs
index 8174af9b5..c72b13b36 100644
--- a/src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.CoreRT.cs
+++ b/src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.CoreRT.cs
@@ -3,21 +3,15 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Collections;
using System.Runtime;
-using System.Runtime.CompilerServices;
namespace Internal.Runtime.Augments
{
/// <summary>For internal use only. Exposes runtime functionality to the Environments implementation in corefx.</summary>
public static partial class EnvironmentAugments
{
- public static int CurrentManagedThreadId => System.Threading.ManagedThreadId.Current;
- public static void FailFast(string message, Exception error) => RuntimeExceptionHelpers.FailFast(message, error);
-
public static void Exit(int exitCode)
{
-#if CORERT
s_latchedExitCode = exitCode;
ShutdownCore();
@@ -25,28 +19,6 @@ namespace Internal.Runtime.Augments
RuntimeImports.RhpShutdown();
Interop.ExitProcess(s_latchedExitCode);
-#else
- // This needs to be implemented for ProjectN.
- throw new PlatformNotSupportedException();
-#endif
- }
-
- internal static void ShutdownCore()
- {
- // Here we'll handle AppDomain.ProcessExit, shut down threading etc.
- }
-
- private static int s_latchedExitCode;
- public static int ExitCode
- {
- get
- {
- return s_latchedExitCode;
- }
- set
- {
- s_latchedExitCode = value;
- }
}
private static string[] s_commandLineArgs;
@@ -58,38 +30,7 @@ namespace Internal.Runtime.Augments
public static string[] GetCommandLineArgs()
{
- return (string[])s_commandLineArgs?.Clone();
+ return (string[])s_commandLineArgs.Clone();
}
-
- public static bool HasShutdownStarted => false; // .NET Core does not have shutdown finalization
-
- public static string StackTrace
- {
- // Disable inlining to have predictable stack frame to skip
- [MethodImpl(MethodImplOptions.NoInlining)]
- get
- {
- // RhGetCurrentThreadStackTrace returns the number of frames(cFrames) added to input buffer.
- // It returns a negative value, -cFrames which is the required array size, if the buffer is too small.
- // Initial array length is deliberately chosen to be 0 so that we reallocate to exactly the right size
- // for StackFrameHelper.FormatStackTrace call. If we want to do this optimistically with one call change
- // FormatStackTrace to accept an explicit length.
- IntPtr[] frameIPs = Array.Empty<IntPtr>();
- int cFrames = RuntimeImports.RhGetCurrentThreadStackTrace(frameIPs);
- if (cFrames < 0)
- {
- frameIPs = new IntPtr[-cFrames];
- cFrames = RuntimeImports.RhGetCurrentThreadStackTrace(frameIPs);
- if (cFrames < 0)
- {
- return "";
- }
- }
-
- return Internal.Diagnostics.StackTraceHelper.FormatStackTrace(frameIPs, 1, true);
- }
- }
-
- public static int TickCount => Environment.TickCount;
}
}
diff --git a/src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.ProjectN.cs b/src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.ProjectN.cs
new file mode 100644
index 000000000..f0fbc7b20
--- /dev/null
+++ b/src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.ProjectN.cs
@@ -0,0 +1,23 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+namespace Internal.Runtime.Augments
+{
+ /// <summary>For internal use only. Exposes runtime functionality to the Environments implementation in corefx.</summary>
+ public static partial class EnvironmentAugments
+ {
+ public static void Exit(int exitCode)
+ {
+ // This needs to be implemented for ProjectN.
+ throw new PlatformNotSupportedException();
+ }
+
+ public static string[] GetCommandLineArgs()
+ {
+ throw new PlatformNotSupportedException(SR.PlatformNotSupported_GetCommandLineArgs);
+ }
+ }
+}
diff --git a/src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.cs b/src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.cs
index 0780db2ea..1ad18b8d6 100644
--- a/src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.cs
+++ b/src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.cs
@@ -109,5 +109,57 @@ namespace Internal.Runtime.Augments
else
throw new ArgumentOutOfRangeException(nameof(target), target, SR.Format(SR.Arg_EnumIllegalVal, target));
}
+
+ public static int CurrentManagedThreadId => System.Threading.ManagedThreadId.Current;
+ public static void FailFast(string message, Exception error) => RuntimeExceptionHelpers.FailFast(message, error);
+
+ internal static void ShutdownCore()
+ {
+ // Here we'll handle AppDomain.ProcessExit, shut down threading etc.
+ }
+
+ private static int s_latchedExitCode;
+ public static int ExitCode
+ {
+ get
+ {
+ return s_latchedExitCode;
+ }
+ set
+ {
+ s_latchedExitCode = value;
+ }
+ }
+
+ public static bool HasShutdownStarted => false; // .NET Core does not have shutdown finalization
+
+ public static string StackTrace
+ {
+ // Disable inlining to have predictable stack frame to skip
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ get
+ {
+ // RhGetCurrentThreadStackTrace returns the number of frames(cFrames) added to input buffer.
+ // It returns a negative value, -cFrames which is the required array size, if the buffer is too small.
+ // Initial array length is deliberately chosen to be 0 so that we reallocate to exactly the right size
+ // for StackFrameHelper.FormatStackTrace call. If we want to do this optimistically with one call change
+ // FormatStackTrace to accept an explicit length.
+ IntPtr[] frameIPs = Array.Empty<IntPtr>();
+ int cFrames = RuntimeImports.RhGetCurrentThreadStackTrace(frameIPs);
+ if (cFrames < 0)
+ {
+ frameIPs = new IntPtr[-cFrames];
+ cFrames = RuntimeImports.RhGetCurrentThreadStackTrace(frameIPs);
+ if (cFrames < 0)
+ {
+ return "";
+ }
+ }
+
+ return Internal.Diagnostics.StackTraceHelper.FormatStackTrace(frameIPs, 1, true);
+ }
+ }
+
+ public static int TickCount => Environment.TickCount;
}
}
diff --git a/src/System.Private.CoreLib/src/Resources/Strings.resx b/src/System.Private.CoreLib/src/Resources/Strings.resx
index 53a8ed147..9e8c957ee 100644
--- a/src/System.Private.CoreLib/src/Resources/Strings.resx
+++ b/src/System.Private.CoreLib/src/Resources/Strings.resx
@@ -2449,4 +2449,7 @@
<data name="Arg_OpenType" xml:space="preserve">
<value>Cannot create an instance of {0} as it is an open type.</value>
</data>
+ <data name="PlatformNotSupported_GetCommandLineArgs" xml:space="preserve">
+ <value>Environment.GetCommandLineArgs() is not supported on this platform.</value>
+ </data>
</root>
diff --git a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj
index 7bb5fecda..330c5adb9 100644
--- a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj
+++ b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj
@@ -116,7 +116,8 @@
<Compile Include="Internal\Runtime\Augments\DynamicDelegateAugments.cs" />
<Compile Include="Internal\Runtime\Augments\EnumInfo.cs" />
<Compile Include="Internal\Runtime\Augments\EnvironmentAugments.cs" />
- <Compile Include="Internal\Runtime\Augments\EnvironmentAugments.CoreRT.cs" />
+ <Compile Condition="'$(IsProjectNLibrary)' != 'true'" Include="Internal\Runtime\Augments\EnvironmentAugments.CoreRT.cs" />
+ <Compile Condition="'$(IsProjectNLibrary)' == 'true'" Include="Internal\Runtime\Augments\EnvironmentAugments.ProjectN.cs" />
<Compile Condition="'$(TargetsWindows)'=='true'" Include="Internal\Runtime\Augments\EnvironmentAugments.Windows.cs" />
<Compile Condition="'$(TargetsUnix)'=='true'" Include="Internal\Runtime\Augments\EnvironmentAugments.Unix.cs" />
<Compile Include="Internal\Runtime\Augments\RuntimeThread.cs" />
@@ -852,4 +853,4 @@
</ItemGroup>
<Import Project="..\shared\System.Private.CoreLib.Shared.projitems" Label="Shared" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
-</Project> \ No newline at end of file
+</Project>