Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -22,11 +22,12 @@
*/
using System;
using System.Runtime.Serialization;
namespace IKVM.Reflection
{
#if !CORECLR
[Serializable]
#endif
public sealed class AmbiguousMatchException : Exception
{
public AmbiguousMatchException()
@@ -43,9 +44,11 @@ namespace IKVM.Reflection
{
}
private AmbiguousMatchException(SerializationInfo info, StreamingContext context)
#if !CORECLR
private AmbiguousMatchException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
#endif
}
}

View File

@@ -31,7 +31,10 @@ using IKVM.Reflection.Reader;
namespace IKVM.Reflection
{
public sealed class AssemblyName : ICloneable
public sealed class AssemblyName
#if !CORECLR
: ICloneable
#endif
{
private string name;
private string culture;
@@ -199,6 +202,7 @@ namespace IKVM.Reflection
set { codeBase = value; }
}
#if !CORECLR
public string EscapedCodeBase
{
get
@@ -209,6 +213,7 @@ namespace IKVM.Reflection
return tmp.EscapedCodeBase;
}
}
#endif
public ProcessorArchitecture ProcessorArchitecture
{
@@ -446,11 +451,13 @@ namespace IKVM.Reflection
return b == null || b.Length == 0 ? b : (byte[])b.Clone();
}
#if !CORECLR
public static bool ReferenceMatchesDefinition(AssemblyName reference, AssemblyName definition)
{
// HACK use the real AssemblyName to implement the (broken) ReferenceMatchesDefinition method
return System.Reflection.AssemblyName.ReferenceMatchesDefinition(new System.Reflection.AssemblyName(reference.FullName), new System.Reflection.AssemblyName(definition.FullName));
}
#endif
public static AssemblyName GetAssemblyName(string path)
{

View File

@@ -22,11 +22,12 @@
*/
using System;
using System.Runtime.Serialization;
namespace IKVM.Reflection
{
#if !CORECLR
[Serializable]
#endif
public sealed class BadImageFormatException : Exception
{
public BadImageFormatException()
@@ -43,9 +44,11 @@ namespace IKVM.Reflection
{
}
private BadImageFormatException(SerializationInfo info, StreamingContext context)
#if !CORECLR
private BadImageFormatException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
#endif
}
}

View File

@@ -82,7 +82,9 @@ namespace IKVM.Reflection.Emit
internal string Name;
internal string FileName;
internal ResourceAttributes Attributes;
#if !CORECLR
internal ResourceWriter Writer;
#endif
}
internal AssemblyBuilder(Universe universe, AssemblyName name, string dir, IEnumerable<CustomAttributeBuilder> customAttributes)
@@ -413,11 +415,13 @@ namespace IKVM.Reflection.Emit
foreach (ResourceFile resfile in resourceFiles)
{
#if !CORECLR
if (resfile.Writer != null)
{
resfile.Writer.Generate();
resfile.Writer.Close();
}
#endif
int fileToken = AddFile(manifestModule, resfile.FileName, 1 /*ContainsNoMetaData*/);
ManifestResourceTable.Record rec = new ManifestResourceTable.Record();
rec.Offset = 0;
@@ -448,6 +452,7 @@ namespace IKVM.Reflection.Emit
}
moduleBuilder.ExportTypes(fileToken, manifestModule);
}
moduleBuilder.CloseResources();
}
foreach (Module module in addedModules)
@@ -498,6 +503,7 @@ namespace IKVM.Reflection.Emit
resourceFiles.Add(resfile);
}
#if !CORECLR
public IResourceWriter DefineResource(string name, string description, string fileName)
{
return DefineResource(name, description, fileName, ResourceAttributes.Public);
@@ -521,6 +527,7 @@ namespace IKVM.Reflection.Emit
resourceFiles.Add(resfile);
return rw;
}
#endif
public void DefineVersionInfoResource()
{

View File

@@ -77,10 +77,12 @@ namespace IKVM.Reflection.Emit
methodBuilder.__AddDeclarativeSecurity(customBuilder);
}
#if !CORECLR
public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
{
methodBuilder.AddDeclarativeSecurity(securityAction, permissionSet);
}
#endif
public void SetImplementationFlags(MethodImplAttributes attributes)
{

View File

@@ -24,7 +24,9 @@
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
#if !NO_SYMBOL_WRITER
using System.Diagnostics.SymbolStore;
#endif
using System.Diagnostics;
using IKVM.Reflection.Writer;
@@ -110,7 +112,9 @@ namespace IKVM.Reflection.Emit
private readonly List<int> labels = new List<int>();
private readonly List<int> labelStackHeight = new List<int>();
private readonly List<LabelFixup> labelFixups = new List<LabelFixup>();
#if !NO_SYMBOL_WRITER
private readonly List<SequencePoint> sequencePoints = new List<SequencePoint>();
#endif
private readonly List<ExceptionBlock> exceptions = new List<ExceptionBlock>();
private readonly Stack<ExceptionBlock> exceptionStack = new Stack<ExceptionBlock>();
private ushort maxStack;
@@ -183,12 +187,14 @@ namespace IKVM.Reflection.Emit
private struct SequencePoint
{
#if !NO_SYMBOL_WRITER
internal ISymbolDocumentWriter document;
internal int offset;
internal int startLine;
internal int startColumn;
internal int endLine;
internal int endColumn;
#endif
}
private sealed class Scope
@@ -402,10 +408,12 @@ namespace IKVM.Reflection.Emit
public void UsingNamespace(string usingNamespace)
{
#if !NO_SYMBOL_WRITER
if (moduleBuilder.symbolWriter != null)
{
moduleBuilder.symbolWriter.UsingNamespace(usingNamespace);
}
#endif
}
public LocalBuilder DeclareLocal(Type localType)
@@ -882,6 +890,7 @@ namespace IKVM.Reflection.Emit
}
}
#if !NO_SYMBOL_WRITER
public void MarkSequencePoint(ISymbolDocumentWriter document, int startLine, int startColumn, int endLine, int endColumn)
{
SequencePoint sp = new SequencePoint();
@@ -893,6 +902,7 @@ namespace IKVM.Reflection.Emit
sp.endColumn = endColumn;
sequencePoints.Add(sp);
}
#endif
public void ThrowException(Type excType)
{
@@ -928,6 +938,7 @@ namespace IKVM.Reflection.Emit
rva = WriteFatHeaderAndCode(bb, localVarSigTok, initLocals);
}
#if !NO_SYMBOL_WRITER
if (moduleBuilder.symbolWriter != null)
{
if (sequencePoints.Count != 0)
@@ -955,6 +966,7 @@ namespace IKVM.Reflection.Emit
WriteScope(scope, localVarSigTok);
}
#endif
return rva;
}
@@ -1111,6 +1123,7 @@ namespace IKVM.Reflection.Emit
}
}
#if !NO_SYMBOL_WRITER
private void WriteScope(Scope scope, int localVarSigTok)
{
moduleBuilder.symbolWriter.OpenScope(scope.startOffset);
@@ -1134,5 +1147,6 @@ namespace IKVM.Reflection.Emit
}
moduleBuilder.symbolWriter.CloseScope(scope.endOffset);
}
#endif
}
}

View File

@@ -27,7 +27,9 @@ using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
#if !NO_SYMBOL_WRITER
using System.Diagnostics.SymbolStore;
#endif
using IKVM.Reflection.Metadata;
using IKVM.Reflection.Writer;
@@ -89,15 +91,19 @@ namespace IKVM.Reflection.Emit
{
if (ilgen != null)
{
#if !NO_SYMBOL_WRITER
if (this.ModuleBuilder.symbolWriter != null)
{
this.ModuleBuilder.symbolWriter.OpenMethod(new SymbolToken(-pseudoToken | 0x06000000), this);
}
#endif
rva = ilgen.WriteBody(initLocals);
#if !NO_SYMBOL_WRITER
if (this.ModuleBuilder.symbolWriter != null)
{
this.ModuleBuilder.symbolWriter.CloseMethod();
}
#endif
ilgen = null;
}
}
@@ -288,11 +294,13 @@ namespace IKVM.Reflection.Emit
declarativeSecurity.Add(customBuilder);
}
#if !CORECLR
public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
{
this.ModuleBuilder.AddDeclarativeSecurity(pseudoToken, securityAction, permissionSet);
this.attributes |= MethodAttributes.HasSecurity;
}
#endif
public void SetImplementationFlags(MethodImplAttributes attributes)
{
@@ -742,7 +750,8 @@ namespace IKVM.Reflection.Emit
{
if (methodSignature == null)
{
methodSignature = MethodSignature.MakeFromBuilder(returnType, parameterTypes, customModifiers, callingConvention, gtpb == null ? 0 : gtpb.Length);
methodSignature = MethodSignature.MakeFromBuilder(returnType ?? typeBuilder.Universe.System_Void, parameterTypes ?? Type.EmptyTypes,
customModifiers, callingConvention, gtpb == null ? 0 : gtpb.Length);
}
return methodSignature;
}

View File

@@ -1,5 +1,5 @@
/*
Copyright (C) 2008-2012 Jeroen Frijters
Copyright (C) 2008-2015 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -25,7 +25,9 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
#if !NO_SYMBOL_WRITER
using System.Diagnostics.SymbolStore;
#endif
using System.Security.Cryptography;
using System.Resources;
using System.Runtime.CompilerServices;
@@ -39,7 +41,8 @@ namespace IKVM.Reflection.Emit
public sealed class ModuleBuilder : Module, ITypeOwner
{
private static readonly bool usePublicKeyAssemblyReference = false;
private Guid mvid = Guid.NewGuid();
private Guid mvid;
private uint timestamp;
private long imageBaseAddress = 0x00400000;
private long stackReserve = -1;
private int fileAlignment = 0x200;
@@ -55,7 +58,6 @@ namespace IKVM.Reflection.Emit
internal readonly ByteBuffer methodBodies = new ByteBuffer(128 * 1024);
internal readonly List<int> tokenFixupOffsets = new List<int>();
internal readonly ByteBuffer initializedData = new ByteBuffer(512);
internal readonly ByteBuffer manifestResources = new ByteBuffer(512);
internal ResourceSection unmanagedResources;
private readonly Dictionary<MemberRefKey, int> importedMemberRefs = new Dictionary<MemberRefKey, int>();
private readonly Dictionary<MethodSpecKey, int> importedMethodSpecs = new Dictionary<MethodSpecKey, int>();
@@ -71,30 +73,81 @@ namespace IKVM.Reflection.Emit
internal readonly List<VTableFixups> vtablefixups = new List<VTableFixups>();
internal readonly List<UnmanagedExport> unmanagedExports = new List<UnmanagedExport>();
private List<InterfaceImplCustomAttribute> interfaceImplCustomAttributes;
private List<ResourceWriterRecord> resourceWriters;
private readonly List<ResourceWriterRecord> resourceWriters = new List<ResourceWriterRecord>();
private bool saved;
private struct ResourceWriterRecord
{
private readonly string name;
#if !CORECLR
private readonly ResourceWriter rw;
private readonly MemoryStream mem;
#endif
private readonly Stream stream;
private readonly ResourceAttributes attributes;
internal ResourceWriterRecord(string name, ResourceWriter rw, MemoryStream mem, ResourceAttributes attributes)
#if CORECLR
internal ResourceWriterRecord(string name, Stream stream, ResourceAttributes attributes)
{
this.name = name;
this.stream = stream;
this.attributes = attributes;
}
#else
internal ResourceWriterRecord(string name, Stream stream, ResourceAttributes attributes)
: this(name, null, stream, attributes)
{
}
internal ResourceWriterRecord(string name, ResourceWriter rw, Stream stream, ResourceAttributes attributes)
{
this.name = name;
this.rw = rw;
this.mem = mem;
this.stream = stream;
this.attributes = attributes;
}
#endif
internal void Emit(ModuleBuilder mb)
internal void Emit(ModuleBuilder mb, int offset)
{
rw.Generate();
mem.Position = 0;
mb.DefineManifestResource(name, mem, attributes);
rw.Close();
#if !CORECLR
if (rw != null)
{
rw.Generate();
}
#endif
ManifestResourceTable.Record rec = new ManifestResourceTable.Record();
rec.Offset = offset;
rec.Flags = (int)attributes;
rec.Name = mb.Strings.Add(name);
rec.Implementation = 0;
mb.ManifestResource.AddRecord(rec);
}
internal int GetLength()
{
return 4 + (int)stream.Length;
}
internal void Write(MetadataWriter mw)
{
mw.Write((int)stream.Length);
stream.Position = 0;
byte[] buffer = new byte[8192];
int length;
while ((length = stream.Read(buffer, 0, buffer.Length)) != 0)
{
mw.Write(buffer, 0, length);
}
}
internal void Close()
{
#if !CORECLR
if (rw != null)
{
rw.Close();
}
#endif
}
}
@@ -198,6 +251,15 @@ namespace IKVM.Reflection.Emit
if (emitSymbolInfo)
{
symbolWriter = SymbolSupport.CreateSymbolWriterFor(this);
if (universe.Deterministic && !symbolWriter.IsDeterministic)
{
throw new NotSupportedException();
}
}
if (!universe.Deterministic)
{
__PEHeaderTimeDateStamp = DateTime.UtcNow;
mvid = Guid.NewGuid();
}
// <Module> must be the first record in the TypeDef table
moduleType = new TypeBuilder(this, null, "<Module>");
@@ -450,11 +512,13 @@ namespace IKVM.Reflection.Emit
this.DeclSecurity.AddRecord(rec);
}
#if !CORECLR
internal void AddDeclarativeSecurity(int token, System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
{
// like Ref.Emit, we're using the .NET 1.x xml format
AddDeclSecurityRecord(token, (int)securityAction, this.Blobs.Add(ByteBuffer.Wrap(System.Text.Encoding.Unicode.GetBytes(permissionSet.ToXml().ToString()))));
}
#endif
internal void AddDeclarativeSecurity(int token, List<CustomAttributeBuilder> declarativeSecurity)
{
@@ -509,21 +573,10 @@ namespace IKVM.Reflection.Emit
public void DefineManifestResource(string name, Stream stream, ResourceAttributes attribute)
{
manifestResources.Align(8);
ManifestResourceTable.Record rec = new ManifestResourceTable.Record();
rec.Offset = manifestResources.Position;
rec.Flags = (int)attribute;
rec.Name = this.Strings.Add(name);
rec.Implementation = 0;
this.ManifestResource.AddRecord(rec);
manifestResources.Write(0); // placeholder for the length
manifestResources.Write(stream);
int savePosition = manifestResources.Position;
manifestResources.Position = rec.Offset;
manifestResources.Write(savePosition - (manifestResources.Position + 4));
manifestResources.Position = savePosition;
resourceWriters.Add(new ResourceWriterRecord(name, stream, attribute));
}
#if !CORECLR
public IResourceWriter DefineResource(string name, string description)
{
return DefineResource(name, description, ResourceAttributes.Public);
@@ -533,27 +586,61 @@ namespace IKVM.Reflection.Emit
{
// FXBUG we ignore the description, because there is no such thing
if (resourceWriters == null)
{
resourceWriters = new List<ResourceWriterRecord>();
}
MemoryStream mem = new MemoryStream();
ResourceWriter rw = new ResourceWriter(mem);
resourceWriters.Add(new ResourceWriterRecord(name, rw, mem, attribute));
return rw;
}
#endif
internal void EmitResources()
{
if (resourceWriters != null)
int offset = 0;
foreach (ResourceWriterRecord rwr in resourceWriters)
{
foreach (ResourceWriterRecord rwr in resourceWriters)
{
rwr.Emit(this);
}
// resources must be 8-byte aligned
offset = (offset + 7) & ~7;
rwr.Emit(this, offset);
offset += rwr.GetLength();
}
}
internal void WriteResources(MetadataWriter mw)
{
int offset = 0;
foreach (ResourceWriterRecord rwr in resourceWriters)
{
// resources must be 8-byte aligned
int alignment = ((offset + 7) & ~7) - offset;
for (int i = 0; i < alignment; i++)
{
mw.Write((byte)0);
}
rwr.Write(mw);
offset += rwr.GetLength() + alignment;
}
}
internal void CloseResources()
{
foreach (ResourceWriterRecord rwr in resourceWriters)
{
rwr.Close();
}
}
internal int GetManifestResourcesLength()
{
int length = 0;
foreach (ResourceWriterRecord rwr in resourceWriters)
{
// resources must be 8-byte aligned
length = (length + 7) & ~7;
length += rwr.GetLength();
}
return length;
}
public override Assembly Assembly
{
get { return asm; }
@@ -594,10 +681,12 @@ namespace IKVM.Reflection.Emit
}
}
#if !NO_SYMBOL_WRITER
public ISymbolDocumentWriter DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
{
return symbolWriter.DefineDocument(url, language, languageVendor, documentType);
}
#endif
public int __GetAssemblyToken(Assembly assembly)
{
@@ -1042,7 +1131,7 @@ namespace IKVM.Reflection.Emit
}
}
internal void WriteMetadata(MetadataWriter mw)
internal void WriteMetadata(MetadataWriter mw, out int guidHeapOffset)
{
mw.Write(0x424A5342); // Signature ("BSJB")
mw.Write((ushort)1); // MajorVersion
@@ -1095,6 +1184,7 @@ namespace IKVM.Reflection.Emit
Tables.Write(mw);
Strings.Write(mw);
UserStrings.Write(mw);
guidHeapOffset = mw.Position;
Guids.Write(mw);
if (!Blobs.IsEmpty)
{
@@ -1316,16 +1406,52 @@ namespace IKVM.Reflection.Emit
get { return fileName; }
}
internal Guid GetModuleVersionIdOrEmpty()
{
return mvid;
}
public override Guid ModuleVersionId
{
get { return mvid; }
get
{
if (mvid == Guid.Empty && universe.Deterministic)
{
// if a deterministic GUID is used, it can't be queried before the assembly has been written
throw new InvalidOperationException();
}
return mvid;
}
}
public void __SetModuleVersionId(Guid guid)
{
if (guid == Guid.Empty && universe.Deterministic)
{
// if you want to use Guid.Empty, don't set UniverseOptions.DeterministicOutput
throw new ArgumentOutOfRangeException();
}
mvid = guid;
}
internal uint GetTimeDateStamp()
{
return timestamp;
}
public DateTime __PEHeaderTimeDateStamp
{
get { return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(timestamp); }
set
{
if (value < new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc) || value > new DateTime(2106, 2, 7, 6, 28, 15, DateTimeKind.Utc))
{
throw new ArgumentOutOfRangeException();
}
timestamp = (uint)(value - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
}
}
public override Type[] __ResolveOptionalParameterTypes(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments, out CustomModifiers[] customModifiers)
{
throw new NotImplementedException();
@@ -1336,10 +1462,12 @@ namespace IKVM.Reflection.Emit
get { return moduleName; }
}
#if !NO_SYMBOL_WRITER
public ISymbolWriter GetSymWriter()
{
return symbolWriter;
}
#endif
public void DefineUnmanagedResource(string resourceFileName)
{
@@ -1361,10 +1489,12 @@ namespace IKVM.Reflection.Emit
{
token = -token | 0x06000000;
}
#if !NO_SYMBOL_WRITER
if (symbolWriter != null)
{
symbolWriter.SetUserEntryPoint(new SymbolToken(token));
}
#endif
}
public StringToken GetStringConstant(string str)
@@ -1536,6 +1666,7 @@ namespace IKVM.Reflection.Emit
FillAssemblyRefTable();
EmitResources();
ModuleWriter.WriteModule(null, null, this, PEFileKinds.Dll, portableExecutableKind, imageFileMachine, unmanagedResources, 0, streamOrNull);
CloseResources();
}
public void __AddAssemblyReference(AssemblyName assemblyName)

View File

@@ -649,11 +649,13 @@ namespace IKVM.Reflection.Emit
declarativeSecurity.Add(customBuilder);
}
#if !CORECLR
public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
{
this.ModuleBuilder.AddDeclarativeSecurity(token, securityAction, permissionSet);
this.attribs |= TypeAttributes.HasSecurity;
}
#endif
public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names)
{

View File

@@ -60,6 +60,7 @@ namespace IKVM.Reflection
const string PublicKeyTokenSilverlight = "7cec85d7bea7798e";
const string PublicKeyTokenWinFX = "31bf3856ad364e35";
#if !CORECLR
internal static bool CompareAssemblyIdentityNative(string assemblyIdentity1, bool unified1, string assemblyIdentity2, bool unified2, out AssemblyComparisonResult result)
{
bool equivalent;
@@ -69,6 +70,7 @@ namespace IKVM.Reflection
[DllImport("fusion", CharSet = CharSet.Unicode)]
private static extern int CompareAssemblyIdentity(string pwzAssemblyIdentity1, bool fUnified1, string pwzAssemblyIdentity2, bool fUnified2, out bool pfEquivalent, out AssemblyComparisonResult pResult);
#endif
// internal for use by mcs
internal static bool CompareAssemblyIdentityPure(string assemblyIdentity1, bool unified1, string assemblyIdentity2, bool unified2, out AssemblyComparisonResult result)

View File

@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{4CB170EF-DFE6-4A56-9E1B-A85449E827A7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IKVM.Reflection</RootNamespace>
<AssemblyName>IKVM.Reflection</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkSubset>
</TargetFrameworkSubset>
@@ -22,8 +22,6 @@
</SccAuxPath>
<SccProvider>
</SccProvider>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\ikvm-fork.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -49,6 +47,7 @@
<Compile Include="BadImageFormatException.cs" />
<Compile Include="Binder.cs" />
<Compile Include="ConstructorInfo.cs" />
<Compile Include="coreclr.cs" />
<Compile Include="CustomAttributeData.cs" />
<Compile Include="CustomAttributeNamedArgument.cs" />
<Compile Include="CustomAttributeTypedArgument.cs" />
@@ -146,4 +145,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

View File

@@ -228,6 +228,11 @@ namespace IKVM.Reflection.Impl
{
throw new InvalidOperationException();
}
public bool IsDeterministic
{
get { return true; }
}
}
}
#endif // MONO

View File

@@ -1184,5 +1184,10 @@ namespace IKVM.Reflection.Impl
{
throw new NotImplementedException();
}
public bool IsDeterministic
{
get { return false; }
}
}
}

View File

@@ -23,7 +23,9 @@
*/
using System;
using System.Runtime.InteropServices;
#if !NO_SYMBOL_WRITER
using System.Diagnostics.SymbolStore;
#endif
using IKVM.Reflection.Emit;
namespace IKVM.Reflection.Impl
@@ -41,13 +43,30 @@ namespace IKVM.Reflection.Impl
public uint PointerToRawData;
}
#if NO_SYMBOL_WRITER
struct SymbolToken
{
internal SymbolToken(int value) { }
}
interface ISymbolWriterImpl
{
byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd);
void RemapToken(int oldToken, int newToken);
void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, int addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset);
void OpenMethod(SymbolToken symbolToken, MethodBase mb);
bool IsDeterministic { get; }
}
#else
interface ISymbolWriterImpl : ISymbolWriter
{
byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd);
void RemapToken(int oldToken, int newToken);
void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset);
void OpenMethod(SymbolToken symbolToken, MethodBase mb);
bool IsDeterministic { get; }
}
#endif
static class SymbolSupport
{

View File

@@ -27,10 +27,14 @@ using System.Runtime.InteropServices;
namespace IKVM.Reflection
{
#if !CORECLR
[Serializable]
#endif
public sealed class MissingAssemblyException : InvalidOperationException
{
#if !CORECLR
[NonSerialized]
#endif
private readonly MissingAssembly assembly;
internal MissingAssemblyException(MissingAssembly assembly)
@@ -39,10 +43,12 @@ namespace IKVM.Reflection
this.assembly = assembly;
}
#if !CORECLR
private MissingAssemblyException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
#endif
public Assembly Assembly
{
@@ -50,10 +56,14 @@ namespace IKVM.Reflection
}
}
#if !CORECLR
[Serializable]
#endif
public sealed class MissingModuleException : InvalidOperationException
{
#if !CORECLR
[NonSerialized]
#endif
private readonly MissingModule module;
internal MissingModuleException(MissingModule module)
@@ -62,10 +72,12 @@ namespace IKVM.Reflection
this.module = module;
}
#if !CORECLR
private MissingModuleException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
#endif
public Module Module
{
@@ -73,10 +85,14 @@ namespace IKVM.Reflection
}
}
#if !CORECLR
[Serializable]
#endif
public sealed class MissingMemberException : InvalidOperationException
{
#if !CORECLR
[NonSerialized]
#endif
private readonly MemberInfo member;
internal MissingMemberException(MemberInfo member)
@@ -85,10 +101,12 @@ namespace IKVM.Reflection
this.member = member;
}
#if !CORECLR
private MissingMemberException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
#endif
public MemberInfo MemberInfo
{

View File

@@ -875,7 +875,11 @@ namespace IKVM.Reflection.Reader
{
return field;
}
#if CORECLR
throw new MissingFieldException(org.ToString() + "." + name);
#else
throw new MissingFieldException(org.ToString(), name);
#endif
}
else
{
@@ -894,7 +898,11 @@ namespace IKVM.Reflection.Reader
{
return method;
}
#if CORECLR
throw new MissingMethodException(org.ToString() + "." + name);
#else
throw new MissingMethodException(org.ToString(), name);
#endif
}
}

View File

@@ -74,11 +74,13 @@ namespace IKVM.Reflection
{
get
{
#if !CORECLR
if (Universe.MonoRuntime)
{
// MONOBUG workaround for https://bugzilla.xamarin.com/show_bug.cgi?id=5299
return MonoGetPublicKey();
}
#endif
using (RSACryptoServiceProvider rsa = CreateRSA())
{
byte[] cspBlob = rsa.ExportCspBlob(false);
@@ -125,6 +127,7 @@ namespace IKVM.Reflection
}
}
#if !CORECLR
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
private byte[] MonoGetPublicKey()
{
@@ -132,5 +135,6 @@ namespace IKVM.Reflection
? new System.Reflection.StrongNameKeyPair(keyPairArray).PublicKey
: new System.Reflection.StrongNameKeyPair(keyPairContainer).PublicKey;
}
#endif
}
}

View File

@@ -504,6 +504,7 @@ namespace IKVM.Reflection
return names.ToArray();
}
#if !CORECLR
public string GetEnumName(object value)
{
if (!IsEnum)
@@ -539,6 +540,7 @@ namespace IKVM.Reflection
}
return null;
}
#endif
public bool IsEnumDefined(object value)
{
@@ -1315,6 +1317,7 @@ namespace IKVM.Reflection
get { return IsClass && IsImport; }
}
#if !CORECLR
public bool IsContextful
{
get { return IsSubclassOf(this.Module.universe.Import(typeof(ContextBoundObject))); }
@@ -1324,6 +1327,7 @@ namespace IKVM.Reflection
{
get { return IsSubclassOf(this.Module.universe.Import(typeof(MarshalByRefObject))); }
}
#endif
public virtual bool IsVisible
{
@@ -1801,48 +1805,90 @@ namespace IKVM.Reflection
public InterfaceMapping GetInterfaceMap(Type interfaceType)
{
CheckBaked();
InterfaceMapping map = new InterfaceMapping();
if (!IsDirectlyImplementedInterface(interfaceType))
InterfaceMapping map;
map.InterfaceMethods = interfaceType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
map.InterfaceType = interfaceType;
map.TargetMethods = new MethodInfo[map.InterfaceMethods.Length];
map.TargetType = this;
FillInInterfaceMethods(interfaceType, map.InterfaceMethods, map.TargetMethods);
return map;
}
private void FillInInterfaceMethods(Type interfaceType, MethodInfo[] interfaceMethods, MethodInfo[] targetMethods)
{
FillInExplicitInterfaceMethods(interfaceMethods, targetMethods);
bool direct = IsDirectlyImplementedInterface(interfaceType);
if (direct)
{
Type baseType = this.BaseType;
if (baseType == null)
FillInImplicitInterfaceMethods(interfaceMethods, targetMethods);
}
Type baseType = this.BaseType;
if (baseType != null)
{
baseType.FillInInterfaceMethods(interfaceType, interfaceMethods, targetMethods);
ReplaceOverriddenMethods(targetMethods);
}
if (direct)
{
for (Type type = this.BaseType; type != null && type.Module == Module; type = type.BaseType)
{
throw new ArgumentException();
}
else
{
map = baseType.GetInterfaceMap(interfaceType);
type.FillInImplicitInterfaceMethods(interfaceMethods, targetMethods);
}
}
else
}
private void FillInImplicitInterfaceMethods(MethodInfo[] interfaceMethods, MethodInfo[] targetMethods)
{
MethodBase[] methods = null;
for (int i = 0; i < targetMethods.Length; i++)
{
map.InterfaceMethods = interfaceType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
map.InterfaceType = interfaceType;
map.TargetMethods = new MethodInfo[map.InterfaceMethods.Length];
FillInExplicitInterfaceMethods(map.InterfaceMethods, map.TargetMethods);
MethodInfo[] methods = GetMethods(BindingFlags.Instance | BindingFlags.Public);
for (int i = 0; i < map.TargetMethods.Length; i++)
if (targetMethods[i] == null)
{
if (map.TargetMethods[i] == null)
if (methods == null)
{
// TODO use proper method resolution (also take into account that no implicit base class implementation is used across assembly boundaries)
for (int j = 0; j < methods.Length; j++)
methods = __GetDeclaredMethods();
}
for (int j = 0; j < methods.Length; j++)
{
if (methods[j].IsVirtual
&& methods[j].Name == interfaceMethods[i].Name
&& methods[j].MethodSignature.Equals(interfaceMethods[i].MethodSignature))
{
if (methods[j].Name == map.InterfaceMethods[i].Name
&& methods[j].MethodSignature.Equals(map.InterfaceMethods[i].MethodSignature))
{
map.TargetMethods[i] = methods[j];
}
targetMethods[i] = (MethodInfo)methods[j];
break;
}
}
}
for (Type baseType = this.BaseType; baseType != null && interfaceType.IsAssignableFrom(baseType); baseType = baseType.BaseType)
{
baseType.FillInExplicitInterfaceMethods(map.InterfaceMethods, map.TargetMethods);
}
}
map.TargetType = this;
return map;
}
private void ReplaceOverriddenMethods(MethodInfo[] baseMethods)
{
__MethodImplMap impl = __GetMethodImplMap();
for (int i = 0; i < baseMethods.Length; i++)
{
if (baseMethods[i] != null && !baseMethods[i].IsFinal)
{
MethodInfo def = baseMethods[i].GetBaseDefinition();
for (int j = 0; j < impl.MethodDeclarations.Length; j++)
{
for (int k = 0; k < impl.MethodDeclarations[j].Length; k++)
{
if (impl.MethodDeclarations[j][k].GetBaseDefinition() == def)
{
baseMethods[i] = impl.MethodBodies[j];
goto next;
}
}
}
MethodInfo candidate = FindMethod(def.Name, def.MethodSignature) as MethodInfo;
if (candidate != null && candidate.IsVirtual && !candidate.IsNewSlot)
{
baseMethods[i] = candidate;
}
}
next: ;
}
}
internal void FillInExplicitInterfaceMethods(MethodInfo[] interfaceMethods, MethodInfo[] targetMethods)
@@ -2040,7 +2086,6 @@ namespace IKVM.Reflection
{
if (this.Assembly == this.Universe.Mscorlib
|| this.Assembly.GetName().Name.Equals("mscorlib", StringComparison.OrdinalIgnoreCase)
|| this.Assembly.GetName().Name.Equals("System.Runtime", StringComparison.OrdinalIgnoreCase)
// check if mscorlib forwards the type (.NETCore profile reference mscorlib forwards System.Enum and System.ValueType to System.Runtime.dll)
|| this.Universe.Mscorlib.FindType(new TypeName(__Namespace, __Name)) == this)
{
@@ -2662,6 +2707,8 @@ namespace IKVM.Reflection
internal static Type Make(Type type, Type[] typeArguments, CustomModifiers[] mods)
{
if (type.Universe.SupressReferenceTypeIdentityConversion)
return type.Universe.CanonicalizeType(new GenericTypeInstance(type, typeArguments, mods));
bool identity = true;
if (type is TypeBuilder || type is BakedType || type.__IsMissing)
{

View File

@@ -115,6 +115,12 @@ namespace IKVM.Reflection
* - Module.__ReadDataFromRVA()
* - MethodBase.GetMethodBody()
* - FieldInfo.__GetDataFromRVA()
*
* DeterministicOutput
* The generated output file will depend only on the input. In other words,
* the PE file header time stamp will be set to zero and the module version
* id will be based on a SHA1 of the contents, instead of a random guid.
* This option can not be used in combination with PDB file generation.
*/
[Flags]
@@ -129,6 +135,9 @@ namespace IKVM.Reflection
ResolveMissingMembers = 32,
DisableWindowsRuntimeProjection = 64,
DecodeVersionInfoAttributeBlobs = 128,
DeterministicOutput = 256,
SupressReferenceTypeIdentityConversion = 1 << 20
}
public sealed class Universe : IDisposable
@@ -817,6 +826,9 @@ namespace IKVM.Reflection
{
return asm;
}
#if CORECLR
return null;
#else
string fileName;
if (throwOnError)
{
@@ -847,6 +859,7 @@ namespace IKVM.Reflection
}
}
return LoadFile(fileName);
#endif
}
public Type GetType(string assemblyQualifiedTypeName)
@@ -919,9 +932,13 @@ namespace IKVM.Reflection
// this is equivalent to the Fusion CompareAssemblyIdentity API
public bool CompareAssemblyIdentity(string assemblyIdentity1, bool unified1, string assemblyIdentity2, bool unified2, out AssemblyComparisonResult result)
{
#if CORECLR
return Fusion.CompareAssemblyIdentityPure(assemblyIdentity1, unified1, assemblyIdentity2, unified2, out result);
#else
return useNativeFusion
? Fusion.CompareAssemblyIdentityNative(assemblyIdentity1, unified1, assemblyIdentity2, unified2, out result)
: Fusion.CompareAssemblyIdentityPure(assemblyIdentity1, unified1, assemblyIdentity2, unified2, out result);
#endif
}
public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access)
@@ -939,6 +956,7 @@ namespace IKVM.Reflection
return new AssemblyBuilder(this, name, dir, null);
}
#if !CORECLR
#if NET_4_0
[Obsolete]
#endif
@@ -958,6 +976,7 @@ namespace IKVM.Reflection
ab.__AddDeclarativeSecurity(CustomAttributeBuilder.__FromBlob(CustomAttributeBuilder.LegacyPermissionSet, (int)action, Encoding.Unicode.GetBytes(permissionSet.ToXml().ToString())));
}
}
#endif
internal void RegisterDynamicAssembly(AssemblyBuilder asm)
{
@@ -1102,7 +1121,11 @@ namespace IKVM.Reflection
}
return method;
}
#if CORECLR
throw new MissingMethodException(declaringType.ToString() + "." + name);
#else
throw new MissingMethodException(declaringType.ToString(), name);
#endif
}
internal FieldInfo GetMissingFieldOrThrow(Module requester, Type declaringType, string name, FieldSignature signature)
@@ -1116,7 +1139,11 @@ namespace IKVM.Reflection
}
return field;
}
#if CORECLR
throw new MissingFieldException(declaringType.ToString() + "." + name);
#else
throw new MissingFieldException(declaringType.ToString(), name);
#endif
}
internal PropertyInfo GetMissingPropertyOrThrow(Module requester, Type declaringType, string name, PropertySignature propertySignature)
@@ -1132,7 +1159,11 @@ namespace IKVM.Reflection
}
return property;
}
#if CORECLR
throw new System.MissingMemberException(declaringType.ToString() + "." + name);
#else
throw new System.MissingMemberException(declaringType.ToString(), name);
#endif
}
internal Type CanonicalizeType(Type type)
@@ -1222,5 +1253,15 @@ namespace IKVM.Reflection
{
get { return (options & UniverseOptions.DecodeVersionInfoAttributeBlobs) != 0; }
}
internal bool SupressReferenceTypeIdentityConversion
{
get { return (options & UniverseOptions.SupressReferenceTypeIdentityConversion) != 0; }
}
internal bool Deterministic
{
get { return (options & UniverseOptions.DeterministicOutput) != 0; }
}
}
}

View File

@@ -23,7 +23,6 @@
*/
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace IKVM.Reflection
{
@@ -33,7 +32,9 @@ namespace IKVM.Reflection
IList<CustomAttributeData> __GetCustomAttributes(Type attributeType, bool inherit);
}
#if !CORECLR
[Serializable]
#endif
public sealed class FileFormatLimitationExceededException : InvalidOperationException
{
public const int META_E_STRINGSPACE_FULL = unchecked((int)0x80131198);
@@ -44,10 +45,12 @@ namespace IKVM.Reflection
this.HResult = hresult;
}
#if !CORECLR
private FileFormatLimitationExceededException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
#endif
public int ErrorCode
{
@@ -55,26 +58,33 @@ namespace IKVM.Reflection
}
}
#if !CORECLR
[Serializable]
public sealed class Missing : ISerializable
#endif
public sealed class Missing
#if !CORECLR
: System.Runtime.Serialization.ISerializable
#endif
{
public static readonly Missing Value = new Missing();
private Missing() { }
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
#if !CORECLR
void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
{
info.SetType(typeof(SingletonSerializationHelper));
}
[Serializable]
private sealed class SingletonSerializationHelper : IObjectReference
private sealed class SingletonSerializationHelper : System.Runtime.Serialization.IObjectReference
{
public object GetRealObject(StreamingContext context)
public object GetRealObject(System.Runtime.Serialization.StreamingContext context)
{
return Value;
}
}
#endif
}
static class Empty<T>

Some files were not shown because too many files have changed in this diff Show More