diff options
Diffstat (limited to 'src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs')
-rw-r--r-- | src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs | 280 |
1 files changed, 4 insertions, 276 deletions
diff --git a/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs index 9331ae193c..5575e28917 100644 --- a/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs @@ -38,7 +38,6 @@ namespace System.Reflection.Emit using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; - using System.Security.Permissions; using System.Security.Policy; using System.Threading; @@ -156,10 +155,7 @@ namespace System.Reflection.Emit // AssemblyBuilder class. // deliberately not [serializable] - [ClassInterface(ClassInterfaceType.None)] - [ComDefaultInterface(typeof(_AssemblyBuilder))] - [ComVisible(true)] - public sealed class AssemblyBuilder : Assembly, _AssemblyBuilder + public sealed class AssemblyBuilder : Assembly { #region FCALL [MethodImplAttribute(MethodImplOptions.InternalCall)] @@ -221,11 +217,6 @@ namespace System.Reflection.Emit return InternalAssembly.GetNativeHandle(); } - internal Version GetVersion() - { - return InternalAssembly.GetVersion(); - } - #if FEATURE_APPX internal bool ProfileAPICheck { @@ -243,9 +234,6 @@ namespace System.Reflection.Emit AssemblyBuilderAccess access, String dir, Evidence evidence, - PermissionSet requiredPermissions, - PermissionSet optionalPermissions, - PermissionSet refusedPermissions, ref StackCrawlMark stackMark, IEnumerable<CustomAttributeBuilder> unsafeAssemblyAttributes, SecurityContextSource securityContextSource) @@ -257,9 +245,7 @@ namespace System.Reflection.Emit #if FEATURE_REFLECTION_ONLY_LOAD && access != AssemblyBuilderAccess.ReflectionOnly #endif // FEATURE_REFLECTION_ONLY_LOAD -#if FEATURE_COLLECTIBLE_TYPES && access != AssemblyBuilderAccess.RunAndCollect -#endif // FEATURE_COLLECTIBLE_TYPES ) { throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)access), nameof(access)); @@ -274,18 +260,6 @@ namespace System.Reflection.Emit // Clone the name in case the caller modifies it underneath us. name = (AssemblyName)name.Clone(); - // If the caller is trusted they can supply identity - // evidence for the new assembly. Otherwise we copy the - // current grant and deny sets from the caller's assembly, - // inject them into the new assembly and mark policy as - // resolved. If/when the assembly is persisted and - // reloaded, the normal rules for gathering evidence will - // be used. - if (evidence != null) -#pragma warning disable 618 - new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand(); -#pragma warning restore 618 - // Scan the assembly level attributes for any attributes which modify how we create the // assembly. Currently, we look for any attribute which modifies the security transparency // of the assembly. @@ -320,9 +294,6 @@ namespace System.Reflection.Emit name, evidence, ref stackMark, - requiredPermissions, - optionalPermissions, - refusedPermissions, securityRulesBlob, aptcaBlob, access, @@ -333,10 +304,6 @@ namespace System.Reflection.Emit name.Name, access, dir); - m_assemblyData.AddPermissionRequests(requiredPermissions, - optionalPermissions, - refusedPermissions); - #if FEATURE_APPX if (AppDomain.ProfileAPICheck) { @@ -393,7 +360,7 @@ namespace System.Reflection.Emit StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return InternalDefineDynamicAssembly(name, access, null, - null, null, null, null, ref stackMark, null, SecurityContextSource.CurrentAssembly); + null, ref stackMark, null, SecurityContextSource.CurrentAssembly); } [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable @@ -407,7 +374,7 @@ namespace System.Reflection.Emit StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return InternalDefineDynamicAssembly(name, access, - null, null, null, null, null, + null, null, ref stackMark, assemblyAttributes, SecurityContextSource.CurrentAssembly); } @@ -418,9 +385,6 @@ namespace System.Reflection.Emit AssemblyName name, Evidence identity, ref StackCrawlMark stackMark, - PermissionSet requiredPermissions, - PermissionSet optionalPermissions, - PermissionSet refusedPermissions, byte[] securityRulesBlob, byte[] aptcaBlob, AssemblyBuilderAccess access, @@ -434,9 +398,6 @@ namespace System.Reflection.Emit AssemblyBuilderAccess access, String dir, Evidence evidence, - PermissionSet requiredPermissions, - PermissionSet optionalPermissions, - PermissionSet refusedPermissions, ref StackCrawlMark stackMark, IEnumerable<CustomAttributeBuilder> unsafeAssemblyAttributes, SecurityContextSource securityContextSource) @@ -449,9 +410,6 @@ namespace System.Reflection.Emit access, dir, evidence, - requiredPermissions, - optionalPermissions, - refusedPermissions, ref stackMark, unsafeAssemblyAttributes, securityContextSource); @@ -532,12 +490,6 @@ namespace System.Reflection.Emit if (emitSymbolInfo) { writer = SymWrapperCore.SymWriter.CreateSymWriter(); - // Set the underlying writer for the managed writer - // that we're using. Note that this function requires - // unmanaged code access. -#pragma warning disable 618 - new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert(); -#pragma warning restore 618 String fileName = "Unused"; // this symfile is never written to disk so filename does not matter. @@ -559,19 +511,8 @@ namespace System.Reflection.Emit return dynModule; } // DefineDynamicModuleInternalNoLock - #endregion - - private Assembly LoadISymWrapper() - { - if (m_assemblyData.m_ISymWrapperAssembly != null) - return m_assemblyData.m_ISymWrapperAssembly; - Assembly assem = Assembly.Load("ISymWrapper, Version=" + ThisAssembly.Version + - ", Culture=neutral, PublicKeyToken=" + AssemblyRef.MicrosoftPublicKeyToken); - - m_assemblyData.m_ISymWrapperAssembly = assem; - return assem; - } +#endregion internal void CheckContext(params Type[][] typess) { @@ -839,52 +780,11 @@ namespace System.Reflection.Emit } return null; } - - /********************************************** - * - * Setting the entry point if the assembly builder is building - * an exe. - * - **********************************************/ - public void SetEntryPoint( - MethodInfo entryMethod) - { - SetEntryPoint(entryMethod, PEFileKinds.ConsoleApplication); - } - public void SetEntryPoint( - MethodInfo entryMethod, // entry method for the assembly. We use this to determine the entry module - PEFileKinds fileKind) // file kind for the assembly. - { - lock(SyncRoot) - { - SetEntryPointNoLock(entryMethod, fileKind); - } - } - - private void SetEntryPointNoLock( - MethodInfo entryMethod, // entry method for the assembly. We use this to determine the entry module - PEFileKinds fileKind) // file kind for the assembly. - { - - if (entryMethod == null) - throw new ArgumentNullException(nameof(entryMethod)); - Contract.EndContractBlock(); - - BCLDebug.Log("DYNIL", "## DYNIL LOGGING: AssemblyBuilder.SetEntryPoint"); - - Module tmpModule = entryMethod.Module; - if (tmpModule == null || !InternalAssembly.Equals(tmpModule.Assembly)) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EntryMethodNotDefinedInAssembly")); - - m_assemblyData.m_entryPointMethod = entryMethod; - m_assemblyData.m_peFileKind = fileKind; - } /********************************************** * Use this function if client decides to form the custom attribute blob themselves **********************************************/ - [System.Runtime.InteropServices.ComVisible(true)] public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) { if (con == null) @@ -947,78 +847,6 @@ namespace System.Reflection.Emit } } - - /********************************************** - * - * Saves the assembly to disk. Also saves all dynamic modules defined - * in this dynamic assembly. Assembly file name can be the same as one of - * the module's name. If so, assembly info is stored within that module. - * Assembly file name can be different from all of the modules underneath. In - * this case, assembly is stored stand alone. - * - **********************************************/ - - public void Save(String assemblyFileName) // assembly file name - { - Save(assemblyFileName, System.Reflection.PortableExecutableKinds.ILOnly, System.Reflection.ImageFileMachine.I386); - } - - public void Save(String assemblyFileName, - PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine) - { - lock(SyncRoot) - { - SaveNoLock(assemblyFileName, portableExecutableKind, imageFileMachine); - } - } - - private void SaveNoLock(String assemblyFileName, - PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine) - { - // AssemblyBuilderAccess.Save can never be set in CoreCLR - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CantSaveTransientAssembly")); - } - - internal bool IsPersistable() - { - { - return false; - } - } - - /********************************************** - * - * Internal helper to walk the nested type hierachy - * - **********************************************/ - private int DefineNestedComType(Type type, int tkResolutionScope, int tkTypeDef) - { - Type enclosingType = type.DeclaringType; - if (enclosingType == null) - { - // Use full type name for non-nested types. - return AddExportedTypeOnDisk(GetNativeHandle(), type.FullName, tkResolutionScope, tkTypeDef, type.Attributes); - } - - tkResolutionScope = DefineNestedComType(enclosingType, tkResolutionScope, tkTypeDef); - // Use simple name for nested types. - return AddExportedTypeOnDisk(GetNativeHandle(), type.Name, tkResolutionScope, tkTypeDef, type.Attributes); - } - - internal int DefineExportedTypeInMemory(Type type, int tkResolutionScope, int tkTypeDef) - { - Type enclosingType = type.DeclaringType; - if (enclosingType == null) - { - // Use full type name for non-nested types. - return AddExportedTypeInMemory(GetNativeHandle(), type.FullName, tkResolutionScope, tkTypeDef, type.Attributes); - } - - tkResolutionScope = DefineExportedTypeInMemory(enclosingType, tkResolutionScope, tkTypeDef); - // Use simple name for nested types. - return AddExportedTypeInMemory(GetNativeHandle(), type.Name, tkResolutionScope, tkTypeDef, type.Attributes); - } - /********************************************** * * Private methods @@ -1030,105 +858,5 @@ namespace System.Reflection.Emit * @internonly **********************************************/ private AssemblyBuilder() {} - - // Create a new module in which to emit code. This module will not contain the manifest. - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] - static private extern void DefineDynamicModule(RuntimeAssembly containingAssembly, - bool emitSymbolInfo, - String name, - String filename, - StackCrawlMarkHandle stackMark, - ref IntPtr pInternalSymWriter, - ObjectHandleOnStack retModule, - bool fIsTransient, - out int tkFile); - - private static Module DefineDynamicModule(RuntimeAssembly containingAssembly, - bool emitSymbolInfo, - String name, - String filename, - ref StackCrawlMark stackMark, - ref IntPtr pInternalSymWriter, - bool fIsTransient, - out int tkFile) - { - RuntimeModule retModule = null; - - DefineDynamicModule(containingAssembly.GetNativeHandle(), - emitSymbolInfo, - name, - filename, - JitHelpers.GetStackCrawlMarkHandle(ref stackMark), - ref pInternalSymWriter, - JitHelpers.GetObjectHandleOnStack(ref retModule), - fIsTransient, - out tkFile); - - return retModule; - } - - // The following functions are native helpers for creating on-disk manifest - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] - static private extern void PrepareForSavingManifestToDisk(RuntimeAssembly assembly, RuntimeModule assemblyModule); // module to contain assembly information if assembly is embedded - - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] - static private extern void SaveManifestToDisk(RuntimeAssembly assembly, - String strFileName, - int entryPoint, - int fileKind, - int portableExecutableKind, - int ImageFileMachine); - - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] - static private extern int AddFile(RuntimeAssembly assembly, String strFileName); - - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] - static private extern void SetFileHashValue(RuntimeAssembly assembly, - int tkFile, - String strFullFileName); - - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] - static private extern int AddExportedTypeInMemory(RuntimeAssembly assembly, - String strComTypeName, - int tkAssemblyRef, - int tkTypeDef, - TypeAttributes flags); - - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] - static private extern int AddExportedTypeOnDisk(RuntimeAssembly assembly, - String strComTypeName, - int tkAssemblyRef, - int tkTypeDef, - TypeAttributes flags); - - // Add an entry to assembly's manifestResource table for a stand alone resource. - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] - static private extern void AddStandAloneResource(RuntimeAssembly assembly, - String strName, - String strFileName, - String strFullFileName, - int attribute); - - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] -#pragma warning disable 618 - static private extern void AddDeclarativeSecurity(RuntimeAssembly assembly, SecurityAction action, byte[] blob, int length); -#pragma warning restore 618 - - // Functions for defining unmanaged resources. - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] - static private extern void CreateVersionInfoResource(String filename, String title, String iconFilename, String description, - String copyright, String trademark, String company, String product, - String productVersion, String fileVersion, int lcid, bool isDll, - StringHandleOnStack retFileName); } } |