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

@@ -302,22 +302,6 @@ namespace IKVM.Reflection.Writer
}
}
internal void Write(System.IO.Stream stream)
{
const int chunkSize = 8192;
for (; ; )
{
if (pos + chunkSize > buffer.Length)
Grow(chunkSize);
int read = stream.Read(buffer, pos, chunkSize);
if (read <= 0)
{
break;
}
pos += read;
}
}
internal byte[] ToArray()
{
int len = this.Length;

View File

@@ -72,6 +72,11 @@ namespace IKVM.Reflection.Writer
stream.Write(value, 0, value.Length);
}
internal void Write(byte[] buffer, int offset, int count)
{
stream.Write(buffer, offset, count);
}
internal void Write(byte value)
{
stream.WriteByte(value);

View File

@@ -1,5 +1,5 @@
/*
Copyright (C) 2008-2011 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
@@ -81,7 +81,8 @@ namespace IKVM.Reflection.Writer
moduleBuilder.ApplyUnmanagedExports(imageFileMachine);
moduleBuilder.FixupMethodBodyTokens();
moduleBuilder.ModuleTable.Add(0, moduleBuilder.Strings.Add(moduleBuilder.moduleName), moduleBuilder.Guids.Add(moduleBuilder.ModuleVersionId), 0, 0);
int moduleVersionIdIndex = moduleBuilder.Guids.Add(moduleBuilder.GetModuleVersionIdOrEmpty());
moduleBuilder.ModuleTable.Add(0, moduleBuilder.Strings.Add(moduleBuilder.moduleName), moduleVersionIdIndex, 0, 0);
if (moduleBuilder.UserStrings.IsEmpty)
{
@@ -212,6 +213,9 @@ namespace IKVM.Reflection.Writer
writer.Headers.OptionalHeader.DataDirectory[6].Size = code.DebugDirectoryLength;
}
// Set the PE File timestamp
writer.Headers.FileHeader.TimeDateStamp = moduleBuilder.GetTimeDateStamp();
// we need to start by computing the number of sections, because code.PointerToRawData depends on that
writer.Headers.FileHeader.NumberOfSections = 2;
@@ -309,7 +313,8 @@ namespace IKVM.Reflection.Writer
}
stream.Seek(text.PointerToRawData, SeekOrigin.Begin);
code.Write(mw, sdata.VirtualAddress);
int guidHeapOffset;
code.Write(mw, sdata.VirtualAddress, out guidHeapOffset);
if (sdata.SizeOfRawData != 0)
{
@@ -332,17 +337,28 @@ namespace IKVM.Reflection.Writer
// file alignment
stream.SetLength(reloc.PointerToRawData + reloc.SizeOfRawData);
// if we don't have a guid, generate one based on the contents of the assembly
if (moduleBuilder.universe.Deterministic && moduleBuilder.GetModuleVersionIdOrEmpty() == Guid.Empty)
{
Guid guid = GenerateModuleVersionId(stream);
stream.Position = guidHeapOffset + (moduleVersionIdIndex - 1) * 16;
stream.Write(guid.ToByteArray(), 0, 16);
moduleBuilder.__SetModuleVersionId(guid);
}
// do the strong naming
if (keyPair != null)
{
StrongName(stream, keyPair, writer.HeaderSize, text.PointerToRawData, code.StrongNameSignatureRVA - text.VirtualAddress + text.PointerToRawData, code.StrongNameSignatureLength);
}
#if !NO_SYMBOL_WRITER
if (moduleBuilder.symbolWriter != null)
{
moduleBuilder.WriteSymbolTokenMap();
moduleBuilder.symbolWriter.Close();
}
#endif
}
private static int ComputeStrongNameSignatureLength(byte[] publicKey)
@@ -424,5 +440,24 @@ namespace IKVM.Reflection.Writer
length -= read;
}
}
private static Guid GenerateModuleVersionId(Stream stream)
{
SHA1Managed hash = new SHA1Managed();
using (CryptoStream cs = new CryptoStream(Stream.Null, hash, CryptoStreamMode.Write))
{
stream.Seek(0, SeekOrigin.Begin);
byte[] buf = new byte[8192];
HashChunk(stream, cs, buf, (int)stream.Length);
}
byte[] bytes = new byte[16];
Buffer.BlockCopy(hash.Hash, 0, bytes, 0, bytes.Length);
// set GUID type to "version 4" (random)
bytes[7] &= 0x0F;
bytes[7] |= 0x40;
bytes[8] &= 0x3F;
bytes[8] |= 0x80;
return new Guid(bytes);
}
}
}

View File

@@ -158,7 +158,7 @@ namespace IKVM.Reflection.Writer
public WORD Machine;
public WORD NumberOfSections;
public DWORD TimeDateStamp = (uint)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
public DWORD TimeDateStamp;
public DWORD PointerToSymbolTable = 0;
public DWORD NumberOfSymbols = 0;
public WORD SizeOfOptionalHeader = 0xE0;

View File

@@ -38,6 +38,7 @@ namespace IKVM.Reflection.Writer
private readonly CliHeader cliHeader;
private readonly ModuleBuilder moduleBuilder;
private readonly uint strongNameSignatureLength;
private readonly uint manifestResourcesLength;
private readonly ExportTables exportTables;
private readonly List<RelocationBlock> relocations = new List<RelocationBlock>();
@@ -47,6 +48,7 @@ namespace IKVM.Reflection.Writer
this.cliHeader = cliHeader;
this.moduleBuilder = moduleBuilder;
this.strongNameSignatureLength = (uint)strongNameSignatureLength;
this.manifestResourcesLength = (uint)moduleBuilder.GetManifestResourcesLength();
if (moduleBuilder.unmanagedExports.Count != 0)
{
this.exportTables = new ExportTables(this);
@@ -110,7 +112,7 @@ namespace IKVM.Reflection.Writer
private uint ResourcesLength
{
get { return (uint)moduleBuilder.manifestResources.Length; }
get { return manifestResourcesLength; }
}
internal uint StrongNameSignatureRVA
@@ -273,7 +275,7 @@ namespace IKVM.Reflection.Writer
}
}
internal void Write(MetadataWriter mw, uint sdataRVA)
internal void Write(MetadataWriter mw, uint sdataRVA, out int guidHeapOffset)
{
// Now that we're ready to start writing, we need to do some fix ups
moduleBuilder.TypeRef.Fixup(moduleBuilder);
@@ -341,7 +343,7 @@ namespace IKVM.Reflection.Writer
}
// Resources
mw.Write(moduleBuilder.manifestResources);
moduleBuilder.WriteResources(mw);
// The strong name signature live here (if it exists), but it will written later
// and the following alignment padding will take care of reserving the space.
@@ -354,7 +356,7 @@ namespace IKVM.Reflection.Writer
// Metadata
AssertRVA(mw, MetadataRVA);
moduleBuilder.WriteMetadata(mw);
moduleBuilder.WriteMetadata(mw, out guidHeapOffset);
// alignment padding
for (int i = (int)(VTableFixupsRVA - (MetadataRVA + MetadataLength)); i > 0; i--)

View File

@@ -108,7 +108,11 @@ namespace IKVM.Reflection.Writer
{
if (name.CultureInfo != null)
{
#if CORECLR
throw new NotImplementedException();
#else
lcid = name.CultureInfo.LCID;
#endif
}
}
catch (ArgumentException)