8000 Update native code to not call into PSAssemblyLoadContext (#3973) · PowerShell/PowerShell@6bb12c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6bb12c9

Browse files
authored
Update native code to not call into PSAssemblyLoadContext (#3973)
1 parent b4b4e60 commit 6bb12c9

File tree

3 files changed

+60
-64
lines changed

3 files changed

+60
-64
lines changed

src/powershell-native/nativemsh/pwrshcommon/pwrshcommon.cpp

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -669,28 +669,52 @@ namespace NativeMsh
669669
// NOTE: The names must not include the .dll extension because it will be added programmatically.
670670
static PCSTR trustedAssemblies[] =
671671
{
672+
"Microsoft.ApplicationInsights",
673+
"Microsoft.CodeAnalysis",
674+
"Microsoft.CodeAnalysis.CSharp",
672675
"Microsoft.CSharp",
676+
"Microsoft.Management.Infrastructure",
677+
"Microsoft.Management.Infrastructure.CimCmdlets",
678+
"Microsoft.Management.Infrastructure.Native",
679+
"Microsoft.PowerShell.Commands.Diagnostics",
680+
"Microsoft.PowerShell.Commands.Management",
681+
"Microsoft.PowerShell.Commands.Utility",
682+
"Microsoft.PowerShell.ConsoleHost",
683+
"Microsoft.PowerShell.CoreCLR.AssemblyLoadContext",
684+
"Microsoft.PowerShell.CoreCLR.Eventing",
685+
"Microsoft.PowerShell.LocalAccounts",
686+
"Microsoft.PowerShell.PSReadLine",
687+
"Microsoft.PowerShell.SDK",
688+
"Microsoft.PowerShell.Security",
673689
"Microsoft.VisualBasic",
674690
"Microsoft.Win32.Primitives",
675-
"Microsoft.Win32.Registry.AccessControl",
676691
"Microsoft.Win32.Registry",
692+
"Microsoft.Win32.Registry.AccessControl",
693+
"Microsoft.WSMan.Management",
694+
"Microsoft.WSMan.Runtime",
677695
"mscorlib",
696+
"netstandard",
697+
"Newtonsoft.Json",
698+
"System",
678699
"System.AppContext",
679700
"System.Buffers",
680-
"System.Collections.Concurrent",
681701
"System.Collections",
702+
"System.Collections.Concurrent",
682703
"System.Collections.Immutable",
683704
"System.Collections.NonGeneric",
684705
"System.Collections.Specialized",
706+
"System.ComponentModel",
685707
"System.ComponentModel.Annotations",
708+
"System.ComponentModel.Composition",
686709
"System.ComponentModel.DataAnnotations",
687-
"System.ComponentModel",
688710
"System.ComponentModel.EventBasedAsync",
689711
"System.ComponentModel.Primitives",
690712
"System.ComponentModel.TypeConverter",
691713
"System.Console",
692714
"System.Core",
715+
"System.Data",
693716
"System.Data.Common",
717+
"System.Data.SqlClient",
694718
"System.Diagnostics.Contracts",
695719
"System.Diagnostics.Debug",
696720
"System.Diagnostics.DiagnosticSource",
@@ -701,19 +725,22 @@ namespace NativeMsh
701725
"System.Diagnostics.Tools",
702726
"System.Diagnostics.TraceSource",
703727
"System.Diagnostics.Tracing",
704-
"System",
728+
"System.Drawing",
729+
"System.Drawing.Primitives",
705730
"System.Dynamic.Runtime",
706-
"System.Globalization.Calendars",
707731
"System.Globalization",
732+
"System.Globalization.Calendars",
708733
"System.Globalization.Extensions",
734+
"System.IO",
709735
"System.IO.Compression",
736+
"System.IO.Compression.FileSystem",
710737
"System.IO.Compression.ZipFile",
711-
"System.IO",
712-
"System.IO.FileSystem.AccessControl",
713738
"System.IO.FileSystem",
739+
"System.IO.FileSystem.AccessControl",
714740
"System.IO.FileSystem.DriveInfo",
715741
"System.IO.FileSystem.Primitives",
716742
"System.IO.FileSystem.Watcher",
743+
"System.IO.IsolatedStorage",
717744
"System.IO.MemoryMappedFiles",
718745
"System.IO.Packaging",
719746
"System.IO.Pipes",
@@ -722,28 +749,36 @@ namespace NativeMsh
722749
"System.Linq.Expressions",
723750
"System.Linq.Parallel",
724751
"System.Linq.Queryable",
752+
"System.Management.Automation",
725753
"System.Net",
726754
"System.Net.Http",
727755
"System.Net.Http.WinHttpHandler",
756+
"System.Net.HttpListener",
757+
"System.Net.Mail",
728758
"System.Net.NameResolution",
729759
"System.Net.NetworkInformation",
730760
"System.Net.Ping",
731761
"System.Net.Primitives",
732762
"System.Net.Requests",
733763
"System.Net.Security",
764+
"System.Net.ServicePoint",
734765
"System.Net.Sockets",
766+
"System.Net.WebClient",
735767
"System.Net.WebHeaderCollection",
736-
"System.Net.WebSockets.Client",
768+
"System.Net.WebProxy",
737769
"System.Net.WebSockets",
770+
"System.Net.WebSockets.Client",
738771
"System.Numerics",
739772
"System.Numerics.Vectors",
740773
"System.ObjectModel",
741774
"System.Private.CoreLib",
742775
"System.Private.DataContractSerialization",
743776
"System.Private.ServiceModel",
744777
"System.Private.Uri",
745-
"System.Reflection.DispatchProxy",
778+
"System.Private.Xml",
779+
"System.Private.Xml.Linq",
746780
"System.Reflection",
781+
"System.Reflection.DispatchProxy",
747782
"System.Reflection.Emit",
748783
"System.Reflection.Emit.ILGeneration",
749784
"System.Reflection.Emit.Lightweight",
@@ -753,15 +788,18 @@ namespace NativeMsh
753788
"System.Reflection.TypeExtensions",
754789
"System.Resources.Reader",
755790
"System.Resources.ResourceManager",
756-
"System.Runtime.CompilerServices.VisualC",
791+
"System.Resources.Writer",
757792
"System.Runtime",
793+
"System.Runtime.CompilerServices.VisualC",
758794
"System.Runtime.Extensions",
759795
"System.Runtime.Handles",
760796
"System.Runtime.InteropServices",
761797
"System.Runtime.InteropServices.RuntimeInformation",
798+
"System.Runtime.InteropServices.WindowsRuntime",
762799
"System.Runtime.Loader",
763800
"System.Runtime.Numerics",
764801
"System.Runtime.Serialization",
802+
"System.Runtime.Serialization.Formatters",
765803
"System.Runtime.Serialization.Json",
766804
"System.Runtime.Serialization.Primitives",
767805
"System.Runtime.Serialization.Xml",
@@ -778,29 +816,33 @@ namespace NativeMsh
778816
"System.Security.Principal",
779817
"System.Security.Principal.Windows",
780818
"System.Security.SecureString",
781-
"System.ServiceModel",
782819
"System.ServiceModel.Duplex",
783820
"System.ServiceModel.Http",
784821
"System.ServiceModel.NetTcp",
785822
"System.ServiceModel.Primitives",
786823
"System.ServiceModel.Security",
787824
"System.ServiceModel.Web",
788825
"System.ServiceProcess.ServiceController",
789-
"System.Text.Encoding.CodePages",
790826
"System.Text.Encoding",
827+
"System.Text.Encoding.CodePages",
791828
"System.Text.Encoding.Extensions",
792829
"System.Text.Encodings.Web",
793830
"System.Text.RegularExpressions",
794-
"System.Threading.AccessControl",
795831
"System.Threading",
832+
"System.Threading.AccessControl",
796833
"System.Threading.Overlapped",
797-
"System.Threading.Tasks.Dataflow",
798834
"System.Threading.Tasks",
835+
"System.Threading.Tasks.Dataflow",
799836
"System.Threading.Tasks.Extensions",
800837
"System.Threading.Tasks.Parallel",
801838
"System.Threading.Thread",
802839
"System.Threading.ThreadPool",
803840
"System.Threading.Timer",
841+
"System.Transactions",
842+
"System.Transactions.Local",
843+
"System.ValueTuple",
844+
"System.Web",
845+
"System.Web.HttpUtility",
804846
"System.Windows",
805847
"System.Xml",
806848
"System.Xml.Linq",
@@ -810,9 +852,7 @@ namespace NativeMsh
810852
"System.Xml.XmlDocument",
811853
"System.Xml.XmlSerializer",
812854
"System.Xml.XPath",
813-
"System.Xml.XPath.XDocument",
814-
"System.Xml.XPath.XmlDocument",
815-
"Microsoft.PowerShell.CoreCLR.AssemblyLoadContext"
855+
"System.Xml.XPath.XDocument"
816856
};
817857

818858
// Define the function pointer for the CLR entry point

src/powershell-native/nativemsh/pwrshexe/CssMainEntry.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ namespace NativeMsh
2626
// Define the function pointer for the powershell entry point.
2727
typedef int (STDMETHODCALLTYPE *MonadRunHelperFp)(LPCWSTR consoleFilePath, LPCWSTR * args, int argc); // int UnmanagedPSEntry.Start(string consoleFilePath, string[] args, int argc)
2828

29-
// Define the function pointer for AssemblyLoadContext initializer.
30-
typedef void (STDMETHODCALLTYPE *LoaderRunHelperFp)(LPCWSTR appPath);
31-
3229
bool TryRun(const int argc, const wchar_t* argv[], HostEnvironment &hostEnvironment, int &exitCode, bool verbose)
3330
{
3431
// Assume failure
@@ -54,28 +51,10 @@ namespace NativeMsh
5451
return false;
5552
}
5653

57-
//-------------------------------------------------------------
58-
// Set the powershell custom assembly loader to be the default
59-
LoaderRunHelperFp initDelegate = NULL;
60-
HRESULT hr = hostWrapper.CreateDelegate(
61-
"Microsoft.PowerShell.CoreCLR.AssemblyLoadContext, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
62-
"System.Management.Automation.PowerShellAssemblyLoadContextInitializer",
63-
"SetPowerShellAssemblyLoadContext",
64-
(void**)&initDelegate);
65-
66-
if (FAILED(hr))
67-
{
68-
output->DisplayMessage(false, g_CREATING_MSH_ENTRANCE_FAILED, hr);
69-
}
70-
else
71-
{
72-
initDelegate(hostEnvironment.GetHostDirectoryPathW());
73-
}
74-
7554
//-------------------------------------------------------------
7655
// Start the assembly
7756
MonadRunHelperFp pfnDelegate = NULL;
78-
hr = hostWrapper.CreateDelegate(
57+
HRESULT hr = hostWrapper.CreateDelegate(
7958
"Microsoft.PowerShell.ConsoleHost, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
8059
"Microsoft.PowerShell.UnmanagedPSEntry",
8160
"Start",

src/powershell-native/nativemsh/pwrshplugin/pwrshclrhost.cpp

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ typedef DWORD (WINAPI *InitPluginWkrPtrsFuncPtr)(__out PwrshPluginWkr_Ptrs* wkrP
3232

3333
#ifdef CORECLR
3434

35-
// Define the function pointer for the powershell entry point.
36-
typedef int (STDMETHODCALLTYPE *MonadRunHelperFp)(int length, LPCWSTR* commands);
37-
38-
// Define the function pointer for AssemblyLoadContext initializer.
39-
typedef void (STDMETHODCALLTYPE *LoaderRunHelperFp)(LPCWSTR appPath);
40-
4135
unsigned int PowerShellCoreClrWorker::LaunchClr(
4236
_In_ LPCWSTR wszMonadVersion,
4337
_In_ LPCWSTR wszRuntimeVersion,
@@ -54,34 +48,17 @@ unsigned int PowerShellCoreClrWorker::LoadWorkerCallbackPtrs(
5448

5549
*pPluginException = NULL;
5650

57-
// Set the powershell custom assembly loader to be the default
58-
LoaderRunHelperFp initDelegate = NULL;
59-
HRESULT hr = hostWrapper->CreateDelegate(
60-
"Microsoft.PowerShell.CoreCLR.AssemblyLoadContext, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
61-
"System.Management.Automation.PowerShellAssemblyLoadContextInitializer",
62-
"SetPowerShellAssemblyLoadContext",
63-
//(INT_PTR*)&initDelegate);
64-
(void**)&initDelegate);
65-
66-
if (FAILED(hr))
67-
{
68-
output->DisplayMessage(false, g_CREATING_MSH_ENTRANCE_FAILED, hr);
69-
}
70-
else
71-
{
72-
initDelegate(hostEnvironment.GetHostDirectoryPathW());
73-
}
74-
7551
// Call into powershell entry point
7652
InitPluginWkrPtrsFuncPtr entryPointDelegate = NULL;
7753

7854
// Create the function pointer for the managed entry point
7955
// It must be targeted at a static method in the managed code.
80-
hr = hostWrapper->CreateDelegate(
56+
HRESULT hr = hostWrapper->CreateDelegate(
8157
"System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
8258
"System.Management.Automation.Remoting.WSManPluginManagedEntryWrapper",
8359
"InitPlugin",
8460
(void**)&entryPointDelegate);
61+
8562
if (FAILED(hr))
8663
{
8764
output->DisplayMessage(false, g_CREATING_MSH_ENTRANCE_FAILED, hr);

0 commit comments

Comments
 (0)
0