8000 Refactor PowerShell Core to use the default CoreCLR loader instead by daxian-dbw · Pull Request #3903 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Refactor PowerShell Core to use the default CoreCLR loader instead #3903

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

Merged
merged 4 commits into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal void Copy(string source, int offset)

internal void Copy(SecureString source, int offset)
{
IntPtr plainTextString = ClrFacade.SecureStringToCoTaskMemUnicode(source);
IntPtr plainTextString = Marshal.SecureStringToCoTaskMemUnicode(source);
try
{
unsafe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ protected override void ProcessRecord()
{
//assigning to tempmodule to rethrow for exceptions on 64 bit machines
tempmodule = pmodule;
WriteObject(ClrFacade.GetProcessModuleFileVersionInfo(pmodule), true);
WriteObject(pmodule.FileVersionInfo, true);
}
}
catch (InvalidOperationException exception)
Expand All @@ -658,7 +658,7 @@ protected override void ProcessRecord()
{
if (exception.HResult == 299)
{
WriteObject(ClrFacade.GetProcessModuleFileVersionInfo(tempmodule), true);
WriteObject(tempmodule.FileVersionInfo, true);
}
else
{
Expand Down Expand Up @@ -710,7 +710,7 @@ protected override void ProcessRecord()
//if fileversion of each process is to be displayed
try
{
WriteObject(ClrFacade.GetProcessModuleFileVersionInfo(PsUtils.GetMainModule(process)), true);
WriteObject(PsUtils.GetMainModule(process).FileVersionInfo, true);
}
catch (InvalidOperationException exception)
{
Expand All @@ -726,7 +726,7 @@ protected override void ProcessRecord()
{
if (exception.HResult == 299)
{
WriteObject(ClrFacade.GetProcessModuleFileVersionInfo(PsUtils.GetMainModule(process)), true);
WriteObject(PsUtils.GetMainModule(process).FileVersionInfo, true);
}
else
{
Expand Down Expand Up @@ -1966,7 +1966,7 @@ protected override void BeginProcessing()
//UseNewEnvironment
if (_UseNewEnvironment)
{
ClrFacade.GetProcessEnvironment(startInfo).Clear();
startInfo.EnvironmentVariables.Clear();
LoadEnvironmentVariable(startInfo, Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine));
LoadEnvironmentVariable(startInfo, Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User));
}
Expand Down Expand Up @@ -2173,7 +2173,7 @@ private string ResolveFilePath(string path)

private void LoadEnvironmentVariable(ProcessStartInfo startinfo, IDictionary EnvironmentVariables)
{
var processEnvironment = ClrFacade.GetProcessEnvironment(startinfo);
var processEnvironment = startinfo.EnvironmentVariables;
foreach (DictionaryEntry entry in EnvironmentVariables)
{
if (processEnvironment.ContainsKey(entry.Key.ToString()))
Expand Down Expand Up @@ -2373,12 +2373,7 @@ private static StringBuilder BuildCommandLine(string executableFileName, string
return builder;
}

private static byte[] ConvertEnvVarsToByteArray(
#if CORECLR
IDictionary<string, string> sd)
#else
StringDictionary sd)
#endif
private static byte[] ConvertEnvVarsToByteArray(StringDictionary sd)
{
string[] array = new string[sd.Count];
byte[] bytes = null;
Expand Down Expand Up @@ -2497,7 +2492,7 @@ private Process StartWithCreateProcess(ProcessStartInfo startinfo)
creationFlags |= 0x00000004;

IntPtr AddressOfEnvironmentBlock = IntPtr.Zero;
var environmentVars = ClrFacade.GetProcessEnvironment(startinfo);
var environmentVars = startinfo.EnvironmentVariables;
if (environmentVars != null)
{
if (this.UseNewEnvironment)
Expand Down Expand Up @@ -2647,7 +2642,7 @@ internal ProcessCollection()
internal bool AssignProcessToJobObject(Process process)
{
// Add the process to the job object
bool result = NativeMethods.AssignProcessToJobObject(_jobObjectHandle, ClrFacade.GetRawProcessHandle(process));
bool result = NativeMethods.AssignProcessToJobObject(_jobObjectHandle, process.Handle);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,7 @@ protected override void BeginProcessing()
if (null != Credential)
{
username = Credential.UserName;
password = ClrFacade.SecureStringToCoTaskMemUnicode(Credential.Password);
password = Marshal.SecureStringToCoTaskMemUnicode(Credential.Password);
}

// Create the service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ private void LoadAssemblies(IEnumerable<string> assemblies)
Assembly assembly = LoadAssemblyHelper(assemblyName);
if (assembly == null)
{
assembly = LoadFrom(ResolveAssemblyName(assemblyName, false));
assembly = Assembly.LoadFrom(ResolveAssemblyName(assemblyName, false));
}

if (passThru)
Expand Down Expand Up @@ -1276,7 +1276,7 @@ private void CompileSourceToAssembly(string source)
{
ms.Flush();
ms.Seek(0, SeekOrigin.Begin);
Assembly assembly = LoadFrom(ms);
Assembly assembly = Assembly.Load(ms.ToArray());
CheckTypesForDuplicates(assembly);
if (passThru)
{
Expand All @@ -1292,7 +1292,7 @@ private void CompileSourceToAssembly(string source)
{
if (passThru)
{
Assembly assembly = LoadFrom(outputAssembly);
Assembly assembly = Assembly.LoadFrom(outputAssembly);
CheckTypesForDuplicates(assembly);
WriteTypes(assembly);
}
Expand All @@ -1318,16 +1318,6 @@ private AddTypeCompilerError[] GetErrors(ImmutableArray<Diagnostic> diagnostics)
ErrorNumber = d.Id
}).ToArray();
}

private Assembly LoadFrom(Stream assembly)
{
return ClrFacade.LoadFrom(assembly);
}

private Assembly LoadFrom(string path)
{
return ClrFacade.LoadFrom(path);
}
}


Expand Down Expand Up @@ -1955,7 +1945,7 @@ private void LoadAssemblyFromPathOrName(List<Type> generatedTypes)
{
foreach (string path in paths)
{
generatedTypes.AddRange(ClrFacade.LoadFrom(path).GetTypes());
generatedTypes.AddRange(Assembly.LoadFrom(path).GetTypes());
}
}
// Load the assembly by name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private string GetFilePath()
{
try
{
culture = ClrFacade.GetCultureInfo(_uiculture);
culture = CultureInfo.GetCultureInfo(_uiculture);
}
catch (ArgumentException)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,8 @@ internal ConsoleHost(RunspaceConfiguration configuration)
}
#endif

ClrFacade.SetCurrentThreadUiCulture(this.CurrentUICulture);
ClrFacade.SetCurrentThreadCulture(this.CurrentCulture);
Thread.CurrentThread.CurrentUICulture = this.CurrentUICulture;
Thread.CurrentThread.CurrentCulture = this.CurrentCulture;
// BUG: 610329. Tell PowerShell engine to apply console
// related properties while launching Pipeline Execution
// Thread.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Management.Automation.Runspaces;
using System.Management.Automation.Tracing;
using System.Globalization;
using System.Threading;

#if CORECLR
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -65,8 +66,8 @@ public int Start(string consoleFilePath, string[] args)
// The currentUICulture returned NativeCultureResolver supports this non
// traditional fallback on Vista. So it is important to set currentUICulture
// in the beginning before we do anything.
ClrFacade.SetCurrentThreadUiCulture(NativeCultureResolver.UICulture);
ClrFacade.SetCurrentThreadCulture(NativeCultureResolver.Culture);
Thread.CurrentThread.CurrentUICulture = NativeCultureResolver.UICulture;
Thread.CurrentThread.CurrentCulture = NativeCultureResolver.Culture;

RunspaceConfigForSingleShell configuration = null;
PSConsoleLoadException warning = null;
Expand Down
Loading
0