using System;
using System.Collections.Generic;
-using System.Collections.Immutable;
using System.Security.Cryptography;
using System.Text;
/// <summary>
/// Dictionary given a mangled name for a given <see cref="TypeDesc"/>
/// </summary>
- private ImmutableDictionary<TypeDesc, string> _mangledTypeNames = ImmutableDictionary<TypeDesc, string>.Empty;
+ private Dictionary<TypeDesc, string> _mangledTypeNames = new Dictionary<TypeDesc, string>();
/// <summary>
/// Given a set of names <param name="set"/> check if <param name="origName"/>
public override string GetMangledTypeName(TypeDesc type)
{
- string mangledName;
- if (_mangledTypeNames.TryGetValue(type, out mangledName))
- return mangledName;
+ lock (this)
+ {
+ string mangledName;
+ if (_mangledTypeNames.TryGetValue(type, out mangledName))
+ return mangledName;
- return ComputeMangledTypeName(type);
+ return ComputeMangledTypeName(type);
+ }
}
private string EnterNameScopeSequence => _mangleForCplusPlus ? "_A_" : "<";
// Ensure that name is unique and update our tables accordingly.
name = DisambiguateName(name, deduplicator);
deduplicator.Add(name);
- _mangledTypeNames = _mangledTypeNames.Add(t, name);
+ _mangledTypeNames.Add(t, name);
}
}
+ return _mangledTypeNames[type];
}
-
- return _mangledTypeNames[type];
}
string mangledName;
{
// Ensure that name is unique and update our tables accordingly.
if (!_mangledTypeNames.ContainsKey(type))
- _mangledTypeNames = _mangledTypeNames.Add(type, mangledName);
+ _mangledTypeNames.Add(type, mangledName);
}
return mangledName;
}
- private ImmutableDictionary<MethodDesc, Utf8String> _mangledMethodNames = ImmutableDictionary<MethodDesc, Utf8String>.Empty;
- private ImmutableDictionary<MethodDesc, Utf8String> _unqualifiedMangledMethodNames = ImmutableDictionary<MethodDesc, Utf8String>.Empty;
+ private Dictionary<MethodDesc, Utf8String> _mangledMethodNames = new Dictionary<MethodDesc, Utf8String>();
+ private Dictionary<MethodDesc, Utf8String> _unqualifiedMangledMethodNames = new Dictionary<MethodDesc, Utf8String>();
public override Utf8String GetMangledMethodName(MethodDesc method)
{
lock (this)
{
if (!_mangledMethodNames.ContainsKey(method))
- _mangledMethodNames = _mangledMethodNames.Add(method, utf8MangledName);
+ _mangledMethodNames.Add(method, utf8MangledName);
}
return utf8MangledName;
private Utf8String GetUnqualifiedMangledMethodName(MethodDesc method)
{
- Utf8String mangledName;
- if (_unqualifiedMangledMethodNames.TryGetValue(method, out mangledName))
- return mangledName;
+ lock (this)
+ {
+ Utf8String mangledName;
+ if (_unqualifiedMangledMethodNames.TryGetValue(method, out mangledName))
+ return mangledName;
- return ComputeUnqualifiedMangledMethodName(method);
+ return ComputeUnqualifiedMangledMethodName(method);
+ }
}
private Utf8String GetPrefixMangledTypeName(IPrefixMangledType prefixMangledType)
name = DisambiguateName(name, deduplicator);
deduplicator.Add(name);
- _unqualifiedMangledMethodNames = _unqualifiedMangledMethodNames.Add(m, name);
+ _unqualifiedMangledMethodNames.Add(m, name);
}
}
+ return _unqualifiedMangledMethodNames[method];
}
-
- return _unqualifiedMangledMethodNames[method];
}
Utf8String utf8MangledName;
lock (this)
{
if (!_unqualifiedMangledMethodNames.ContainsKey(method))
- _unqualifiedMangledMethodNames = _unqualifiedMangledMethodNames.Add(method, utf8MangledName);
+ _unqualifiedMangledMethodNames.Add(method, utf8MangledName);
}
}
return utf8MangledName;
}
- private ImmutableDictionary<FieldDesc, Utf8String> _mangledFieldNames = ImmutableDictionary<FieldDesc, Utf8String>.Empty;
+ private Dictionary<FieldDesc, Utf8String> _mangledFieldNames = new Dictionary<FieldDesc, Utf8String>();
public override Utf8String GetMangledFieldName(FieldDesc field)
{
- Utf8String mangledName;
- if (_mangledFieldNames.TryGetValue(field, out mangledName))
- return mangledName;
+ lock (this)
+ {
+ Utf8String mangledName;
+ if (_mangledFieldNames.TryGetValue(field, out mangledName))
+ return mangledName;
- return ComputeMangledFieldName(field);
+ return ComputeMangledFieldName(field);
+ }
}
private Utf8String ComputeMangledFieldName(FieldDesc field)
if (prependTypeName != null)
name = prependTypeName + "__" + name;
- _mangledFieldNames = _mangledFieldNames.Add(f, name);
+ _mangledFieldNames.Add(f, name);
}
}
+ return _mangledFieldNames[field];
}
-
- return _mangledFieldNames[field];
}
lock (this)
{
if (!_mangledFieldNames.ContainsKey(field))
- _mangledFieldNames = _mangledFieldNames.Add(field, utf8MangledName);
+ _mangledFieldNames.Add(field, utf8MangledName);
}
return utf8MangledName;
}
- private ImmutableDictionary<string, string> _mangledStringLiterals = ImmutableDictionary<string, string>.Empty;
+ private Dictionary<string, string> _mangledStringLiterals = new Dictionary<string, string>();
public override string GetMangledStringName(string literal)
{
string mangledName;
- if (_mangledStringLiterals.TryGetValue(literal, out mangledName))
- return mangledName;
+ lock (this)
+ {
+ if (_mangledStringLiterals.TryGetValue(literal, out mangledName))
+ return mangledName;
+ }
mangledName = SanitizeNameWithHash(literal);
lock (this)
{
if (!_mangledStringLiterals.ContainsKey(literal))
- _mangledStringLiterals = _mangledStringLiterals.Add(literal, mangledName);
+ _mangledStringLiterals.Add(literal, mangledName);
}
return mangledName;
using System.Collections.Immutable;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
+using System.Reflection.PortableExecutable;
using Internal.Text;
using Internal.TypeSystem;
using Internal.TypeSystem.Ecma;
private unsafe byte[] GetRvaData(int targetPointerSize)
{
int size = 0;
- byte[] result = Array.Empty<byte>();
MetadataReader metadataReader = _module.MetadataReader;
BlobReader metadataBlob = new BlobReader(_module.PEReader.GetMetadata().Pointer, _module.PEReader.GetMetadata().Length);
metadataBlob.Offset = metadataReader.GetTableMetadataOffset(TableIndex.FieldRva);
- ImmutableArray<byte> memBlock = _module.PEReader.GetSectionData(_rva).GetContent();
-
for (int i = 1; i <= metadataReader.GetTableRowCount(TableIndex.FieldRva); i++)
{
int currentFieldRva = metadataBlob.ReadInt32();
int currentSize = field.FieldType.GetElementSize().AsInt;
if (currentSize > size)
{
- if (currentSize > memBlock.Length)
- throw new BadImageFormatException();
-
// We need to handle overlapping fields by reusing blobs based on the rva, and just update
// the size and contents
size = currentSize;
- result = new byte[AlignmentHelper.AlignUp(size, targetPointerSize)];
- memBlock.CopyTo(0, result, 0, size);
}
}
Debug.Assert(size > 0);
+
+ PEMemoryBlock block = _module.PEReader.GetSectionData(_rva);
+ if (block.Length < size)
+ throw new BadImageFormatException();
+
+ byte[] result = new byte[AlignmentHelper.AlignUp(size, targetPointerSize)];
+ block.GetContent(0, size).CopyTo(result);
return result;
}