From 6e986f5ed76701109f83d50df1da53ddb23624ab Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sat, 5 Jan 2019 00:31:36 +0100 Subject: [PATCH] Remove stack marks from GetSatelliteAssembly. (#21812) --- .../src/System/Reflection/Emit/AssemblyBuilder.cs | 8 ++----- .../src/System/Reflection/RuntimeAssembly.cs | 25 ++++++---------------- .../Resources/ManifestBasedResourceGroveler.cs | 6 +++--- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs index e35c8da..ab544d6 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs @@ -523,21 +523,17 @@ namespace System.Reflection.Emit return InternalAssembly.GetLoadedModules(getResourceModules); } - [DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod. public override Assembly GetSatelliteAssembly(CultureInfo culture) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return InternalAssembly.InternalGetSatelliteAssembly(culture, null, ref stackMark); + return InternalAssembly.GetSatelliteAssembly(culture, null); } /// /// Useful for binding to a very specific version of a satellite assembly /// - [DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod. public override Assembly GetSatelliteAssembly(CultureInfo culture, Version version) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return InternalAssembly.InternalGetSatelliteAssembly(culture, version, ref stackMark); + return InternalAssembly.GetSatelliteAssembly(culture, version); } public override bool IsDynamic => true; diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs index c0a8101..8d1b8c9 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs @@ -674,41 +674,30 @@ namespace System.Reflection return null; } - [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod public override Assembly GetSatelliteAssembly(CultureInfo culture) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return InternalGetSatelliteAssembly(culture, null, ref stackMark); + return GetSatelliteAssembly(culture, null); } // Useful for binding to a very specific version of a satellite assembly - [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod public override Assembly GetSatelliteAssembly(CultureInfo culture, Version version) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return InternalGetSatelliteAssembly(culture, version, ref stackMark); - } - - [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod - internal Assembly InternalGetSatelliteAssembly(CultureInfo culture, - Version version, - ref StackCrawlMark stackMark) - { if (culture == null) throw new ArgumentNullException(nameof(culture)); - string name = GetSimpleName() + ".resources"; - return InternalGetSatelliteAssembly(name, culture, version, true, ref stackMark); + return InternalGetSatelliteAssembly(name, culture, version, true); } - [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod + [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod internal RuntimeAssembly InternalGetSatelliteAssembly(string name, CultureInfo culture, Version version, - bool throwOnFileNotFound, - ref StackCrawlMark stackMark) + bool throwOnFileNotFound) { + // This stack crawl mark is never used because the requesting assembly is explicitly specified, + // so the value could be anything. + StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; AssemblyName an = new AssemblyName(); an.SetPublicKey(GetPublicKey()); diff --git a/src/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.cs b/src/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.cs index b4f523b..ea754c1 100644 --- a/src/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.cs +++ b/src/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.cs @@ -71,7 +71,7 @@ namespace System.Resources } else { - satellite = GetSatelliteAssembly(lookForCulture, ref stackMark); + satellite = GetSatelliteAssembly(lookForCulture); if (satellite == null) { @@ -378,7 +378,7 @@ namespace System.Resources return satellite.GetManifestResourceStream(canonicalName, ref stackMark, canSkipSecurityCheck); } - private RuntimeAssembly GetSatelliteAssembly(CultureInfo lookForCulture, ref StackCrawlMark stackMark) + private RuntimeAssembly GetSatelliteAssembly(CultureInfo lookForCulture) { if (!_mediator.LookedForSatelliteContractVersion) { @@ -395,7 +395,7 @@ namespace System.Resources // Yet also somehow log this error for a developer. try { - satellite = _mediator.MainAssembly.InternalGetSatelliteAssembly(satAssemblyName, lookForCulture, _mediator.SatelliteContractVersion, false, ref stackMark); + satellite = _mediator.MainAssembly.InternalGetSatelliteAssembly(satAssemblyName, lookForCulture, _mediator.SatelliteContractVersion, false); } // Jun 08: for cases other than ACCESS_DENIED, we'll assert instead of throw to give release builds more opportunity to fallback. -- 2.7.4