Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@@ -0,0 +1,35 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Reflection.Metadata.Tests", "tests\System.Reflection.Metadata.Tests.csproj", "{7061832A-E8CF-4AB6-A8DC-44D2F5A43A13}"
ProjectSection(ProjectDependencies) = postProject
{F3E433C8-352F-4944-BF7F-765CE435370D} = {F3E433C8-352F-4944-BF7F-765CE435370D}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Reflection.Metadata", "src\System.Reflection.Metadata.csproj", "{F3E433C8-352F-4944-BF7F-765CE435370D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{5C5F1FFD-CC57-4DFF-9CAF-0A2852323AD6}"
ProjectSection(SolutionItems) = preProject
..\.nuget\packages.Windows_NT.config = ..\.nuget\packages.Windows_NT.config
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
DebugNETCoreAppnetstandard1.1netstandard1.5|AnyCPU = DebugNETCoreAppnetstandard1.1netstandard1.5|AnyCPU
ReleaseNETCoreAppnetstandard1.1netstandard1.5|AnyCPU = ReleaseNETCoreAppnetstandard1.1netstandard1.5|AnyCPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7061832A-E8CF-4AB6-A8DC-44D2F5A43A13}.DebugNETCoreAppnetstandard1.1netstandard1.5|AnyCPU.ActiveCfg = netstandard1.5-Debug|Any CPU
{7061832A-E8CF-4AB6-A8DC-44D2F5A43A13}.DebugNETCoreAppnetstandard1.1netstandard1.5|AnyCPU.Build.0 = netstandard1.5-Debug|Any CPU
{7061832A-E8CF-4AB6-A8DC-44D2F5A43A13}.ReleaseNETCoreAppnetstandard1.1netstandard1.5|AnyCPU.ActiveCfg = netstandard1.5-Release|Any CPU
{7061832A-E8CF-4AB6-A8DC-44D2F5A43A13}.ReleaseNETCoreAppnetstandard1.1netstandard1.5|AnyCPU.Build.0 = netstandard1.5-Release|Any CPU
{F3E433C8-352F-4944-BF7F-765CE435370D}.DebugNETCoreAppnetstandard1.1netstandard1.5|AnyCPU.ActiveCfg = netstandard1.1-Debug|Any CPU
{F3E433C8-352F-4944-BF7F-765CE435370D}.DebugNETCoreAppnetstandard1.1netstandard1.5|AnyCPU.Build.0 = netstandard1.1-Debug|Any CPU
{F3E433C8-352F-4944-BF7F-765CE435370D}.ReleaseNETCoreAppnetstandard1.1netstandard1.5|AnyCPU.ActiveCfg = netstandard1.1-Release|Any CPU
{F3E433C8-352F-4944-BF7F-765CE435370D}.ReleaseNETCoreAppnetstandard1.1netstandard1.5|AnyCPU.Build.0 = netstandard1.1-Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.props" />
<PropertyGroup>
<PackageVersion>1.5.0</PackageVersion>
<AssemblyVersion>1.4.2.0</AssemblyVersion>
<IsNETCoreApp>true</IsNETCoreApp>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<Project Include="System.Reflection.Metadata.pkgproj" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
</Project>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<!-- we need to be supported on pre-nuget-3 platforms (Dev12, Dev11, etc) -->
<MinClientVersion>2.8.6</MinClientVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.Reflection.Metadata.csproj">
<SupportedFramework>net45;netcore45;netcoreapp1.0;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<Dependency Include="System.Collections.Immutable">
<TargetFramework>portable-net45+win8</TargetFramework>
<Version>1.1.37</Version>
</Dependency>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -0,0 +1,331 @@
# Known Issues in ECMA-335 CLI Specification
This is an informal list of notes on issues that have been encountered
with the ECMA-335 CLI specification, primarily during development,
testing, and support of System.Reflection.Metadata.
Some of these are definite spec errors while others could be reasoned
as Microsoft implementation quirks.
## Signatures
There is a general philosophical issue whereby the spec defines the
*syntax* of signatures to exclude errors such as:
* using void outside of return types or pointer element types
* instantiating a generic with a byref type
* having a field of byref type
* etc.
Another approach is to syntactically treat `VOID`, `TYPEDBYREF`,
`BYREF Type`, `CMOD_OPT Type`, `CMOD_REQ Type` as the other `Type`s
and then deal with the cases like those above as semantic errors in their use.
That is closer to how many implementations work. It is also how type syntax
is defined in the grammar for IL, with many of the semantic errors
deferred to peverify and/or runtime checking rather than being checked
during assembly.
The spec is also not entirely consistent in its use of the first
approach. Some errors, such as instantiating a generic with an
unmanaged pointer type, are not excluded from the spec's signature
grammars and diagrams.
Many of the specific issues below arise from the tension between these
two approaches.
### 1. `(CLASS | VALUETYPE)` cannot be followed by TypeSpec in practice
In II.23.2.12 and II.23.2.14, it is implied that the token in `(CLASS
| VALUETYPE) TypeDefOrRefOrSpecEncoded` can be a `TypeSpec`, when in
fact it must be a `TypeDef` or `TypeRef`.
peverify gives the following error:
```
[MD]: Error: Signature has token following ELEMENT_TYPE_CLASS
(_VALUETYPE) that is not a TypeDef or TypeRef
```
An insightful comment in CLR source code notes that this rule prevents
cycles in signatures, but see #2 below.
Related issue:
* https://github.com/dotnet/roslyn/issues/7970
#### Proposed specification change
a) Rename section II.23.2.8 from "TypeDefOrRefOrSpecEncoded" to "TypeDefOrRefEncoded and TypeDefOrRefOrSpecEncoded"
b) Replace
> These items are compact ways to store a TypeDef, TypeRef, or TypeSpec token in a Signature (§II.23.2.12).
with
> TypeDefOrRefEncoded is a compact representation of either TypeDef or TypeRef token in a Signature (§II.23.2.12). TypeDefOrRefOrSpecEncoded is a compact representation of either TypeDef, TypeRef or TypeSpec token in a Signature.
Also correct
> The encoded version of this TypeRef token is made up as follows:
to
> The compact representation of a TypeDef, TypeRef or TypeSpec token is made up as follows:
c) In section II.23.2.12 replace
```
Type ::=
...
CLASS TypeDefOrRefOrSpecEncoded
...
GENERICINST (CLASS | VALUETYPE) TypeDefOrRefOrSpecEncoded GenArgCount Type*
...
VALUETYPE TypeDefOrRefOrSpecEncoded
...
```
with
```
Type ::=
...
(CLASS | VALUETYPE) TypeDefOrRefEncoded
GENERICINST (CLASS | VALUETYPE) TypeDefOrRefEncoded GenArgCount Type+
...
```
Note also the correction of ```Type*``` to ```Type+```. A generic type instantiation shall have at least one type argument.
d) In section II.23.2.14 replace
```
TypeSpecBlob ::=
...
GENERICINST (CLASS | VALUETYPE) TypeDefOrRefOrSpecEncoded GenArgCount Type Type*
...
```
with
```
TypeSpecBlob ::=
...
GENERICINST (CLASS | VALUETYPE) TypeDefOrRefEncoded GenArgCount Type+
...
```
```Type Type*``` is simplified to ```Type+```.
#### Rationale of the proposal
1. The proposal removes the possibility of representing the same type via two different encodings. This approach is consistent with II.23.2.16: "Short form signatures" where a short form of a primitive type is preferred over the corresponding long form.
2. Potential TypeSpec recursion is prevented.
3. PEVerify, the CLR runtime and C# compiler prior to VS 2015 report an error when encountering an encoded TypeSpec in the positions decribed above.
### 2. `(CMOD_OPT | CMOD_REQ) <TypeSpec>` is permitted in practice
In II.23.2.7, it is noted that CMOD_OPT or CMOD_REQD is followed
by a TypeRef or TypeDef metadata token, but TypeSpec tokens are
also allowed by ilasm, csc, peverify, and the CLR.
Note, in particular, that TypeSpecs are used there by C++/CLI to
represent strongly-typed boxing in C++/CLI. e.g. `Nullable<int>^`
in C++/CLI becomes `[mscorlib]System.ValueType
modopt([mscorlib]System.Nulllable`1<int>)
modopt([mscorlib]System.Runtime.CompilerServices.IsBoxed)`
in IL.
This tolerance adds a loophole to the rule above whereby cyclical
signatures are in fact possible, e.g.:
* `TypeSpec #1: PTR CMOD_OPT <TypeSpec #1> I4`
Such signatures can currently cause crashes in the runtime and various
tools, so if the spec is amended to permit TypeSpecs as modifiers,
then there should be a clarification that cycles are nonetheless not
permitted, and ideally readers would detect such cycles and handle the
error with a suitable message rather than a stack overflow.
Related issues:
* https://github.com/dotnet/roslyn/issues/7971
* https://github.com/dotnet/coreclr/issues/2674
#### Proposed specification change
In section II.23.2.7, replace
> The CMOD_OPT or CMOD_REQD is followed by a metadata token that indexes a row in the TypeDef
table or the TypeRef table. However, these tokens are encoded and compressed – see §II.23.2.8
for details
with
> The CMOD_OPT or CMOD_REQD is followed by a metadata token that indexes a row in the TypeDef
table, TypeRef table, or TypeSpec table. However, these tokens are encoded and compressed –
see §II.23.2.8 for details. Furthermore, if a row in the TypeSpec table is indicated,
it must not create cycle.
### 3. Custom modifiers can go in more places than specified
Most notably, II.23.2.14 and II.23.21.12 (`Type` and `TypeSpec` grammars)
are missing custom modifiers for the element type of `ARRAY` and the
type arguments of `GENERICINST`.
Also, `LocalVarSig` as specified does not allow modifiers on
`TYPEDBYREF`, and that seems arbitrary since it is allowed on parameter
and return types.
#### Proposed specification change
a) In section II.23.2.4 FieldSig, replace the diagram with a production rule:
```
FieldSig ::= FIELD Type
```
b) In section II.23.2.5 PropertySig, replace the diagram with a production rule:
```
PropertySig ::= PROPERTY HASTHIS? ParamCount RetType Param*
```
Note that this change also allows properties to have BYREF type.
c) In section II.23.2.6 LocalVarSig, replace the diagram with production rules:
```
LocalVarSig ::=
LOCAL_SIG Count LocalVarType+
LocalVarType ::=
Type
CustomMod* Constraint BYREF? Type
CustomMod* BYREF Type
CustomMod* TYPEDBYREF
```
d) In section II.23.2.10 Param, replace the diagram with production rules:
```
Param ::=
Type
CustomMod* BYREF Type
CustomMod* TYPEDBYREF
```
e) In section II.23.2.11 RetType, replace the diagram with production rules:
```
RetType ::=
Type
CustomMod* BYREF Type
CustomMod* TYPEDBYREF
CustomMod* VOID
```
f) In section II.23.2.12 Type, add a production rule to the definition of ```Type```:
```
Type ::= CustomMod* Type
```
g) In sections II.23.2.12 Type and II.23.2.14 TypeSpec replace production rule
```
PTR CustomMod* Type
```
with
```
PTR Type
```
and replace production rule
```
SZARRAY CustomMod* Type
```
with
```
SZARRAY Type
```
### 4. BYREF can come before custom modifiers
Everywhere `BYREF` appears in the spec's box and pointer diagrams, it
comes after any custom modifiers, but the C++/CLI declaration `const
int&` is emitted as `BYREF CMOD_OPT IsConst I4`, and a call-site using
`CMOD_OPT IsConst BYREF I4` will not match.
Under the interpretation that `BYREF` is just a managed pointer type, it
makes sense that there should be parity between `PTR` and `BYREF` with
respect to modifiers. Consider, `const int*` vs. `int* const` in
C++. The former (pointer to constant int) is `PTR CMOD_OPT IsConst I4`
and the latter (constant pointer to int) is `CMOD_OPT IsConst PTR
I4`. The analogy from `const int*` to `const int&` justifies C++'s
encoding of `BYREF` before `CMOD_OPT` in defiance of the spec.
#### Proposed specification change
Already addressed by changes in proposal #3 above.
### 5. TypeSpecs can encode more than specified
In II.23.2.14, the grammar for a `TypeSpec` blob is a subset of the
`Type` grammar defined in II.23.21.12. However, in practice, it is
possible to have other types than what is listed.
Most notably, the important use of the `constrained.` IL prefix with
type parameters is not representable as specified since `MVAR` and `VAR`
are excluded from II.23.2.14.
More obscurely, the constrained. prefix also works with primitives,
e.g:
```
constrained. int32
callvirt instance string [mscorlib]System.Object::ToString()
```
which opens the door to `TypeSpec`s with I4, I8, etc. signatures.
It then follows that the only productions in `Type` that do not make
sense in `TypeSpec` are `(CLASS | VALUETYPE) TypeDefOrRef` since
`TypeDefOrRef` tokens can be used directly and the indirection through
a `TypeSpec` would serve no purpose.
In the same way as `constrained.`, (assuming #2 is a spec bug and not
an ilasm/peverify/CLR quirk), custom modifiers can beget `TypeSpec`s
beyond what is allowed by II.23.2.14, e.g. `modopt(int32)` creates a
typespec with signature I4.
Even more obscurely, this gives us a way to use `VOID`, `TYPEDBYREF`,
`CMOD_OPT`, and `CMOD_REQ` at the root of a `TypeSpec`, which are not even
specified as valid at the root of a `Type`: `modopt(int32
modopt(int32))`, `modopt(void)`, and `modopt(typedref)` all work in
practice. `CMOD_OPT` and `CMOD_REQ` at the root can also be otained by putting
a modifier on the type used with `constrained.`.
## Heap sizes
The ECMA-335-II specification isn't clear on the maximum sizes of #String, #Blob and #GUID heaps.
#### Proposed specification change
We propose the limit on #String and #Blob heap size is 2^29 (0.5 GB), that is any index to these heaps fits into 29 bits.
#### Rationale of the proposal
1) 2^29 is the maximum value representable by a compressed integer as defined elsewhere in the spec. Currently the metadata don't encode heap indices anywhere using compressed integers. However the Portable PDB specification uses compressed integers for efficient encoding of heap indices. We could extend the definition of compressed integer to cover all 32 bit integers, but it would be simpler if we could leave it as is.
2) 0.5 GB is a very large heap. Having such a big PE file seems unreasonable and very rare scenario (if it exists at all).
3) Having 3 spare bits available is very beneficial for the implementation. It allows to represent WinRT projected strings, namespaces, etc. in very efficient way. If we had to represent heap indices with all 32 bits it would bloat various structures and increase memory pressure. PE files over 0.5 GB of size are very rare, but the overhead would affect all compilers and tools working with the metadata reader.

View File

@@ -0,0 +1,65 @@
#PE/COFF Specification Addendum
## Deterministic PE/COFF File
PE/COFF file is _deterministic_ if it is produced by a tool that guarantees that the entire content of the file is based solely on documented inputs given to the tool (such as source files, resource files, compiler options, etc.) rather than ambient environment variables (such as the current time, the operating system, the bitness of the process running the tool, etc.). The content of the file can be reproduced exactly (bit for bit) given the same inputs.
The value of field TimeDateStamp in COFF File Header of a deterministic PE/COFF file does not indicate the date and time when the file was produced and should not be interpreted that way. Instead the value of the field is derived from a hash of the file content. The algorithm used to calculate this value is an implementation detail of the tool that produced the file.
## Debug Directory
Image files contain an optional debug directory that indicates what form of debug information is present and where it is. This directory consists of an array of debug directory entries whose location and size are indicated in the image optional header.
PE/COFF Specification defines the structure of Debug Directory in section 5.1.1. Each entry has a Type and a pointer to data. The format of the data is specific to the Type of the debug entry and not prescribed by the PE/COFF specification. The following paragraphs specify format of data of debug directory entries produced and consumed by CLI (Common Language Infrastructure) compilers, debuggers and other tools.
### CodeView Debug Directory Entry (type 2)
*Version Major=0, Minor=0* of the data format:
| Offset | Size | Field | Description |
|:-------|:-----|:---------------|----------------------------------------------------------------|
| 0 | 4 | Signature | 0x52 0x53 0x44 0x53 (ASCII string: "RSDS") |
| 4 | 16 | Guid | GUID (Globally Unique Identifier) of the associated PDB.
| 20 | 4 | Age | Iteration of the PDB. The first iteration is 1. The iteration is incremented each time the PDB content is augmented.
| 24 | | Path | UTF-8 NUL-terminated path to the associated .pdb file |
Guid and Age are used to match PE/COFF image with the associated PDB.
The associated .pdb file may not exist at the path indicated by Path field. If it doesn't the Path, Guid and Age can be used to find the corresponding PDB file locally or on a symbol server. The exact search algorithm used by tools to locate the PDB depends on the tool and its configuration.
If the containing PE/COFF file is deterministic the Guid field above and DateTimeStamp field of the directory entry are calculated deterministically based solely on the content of the associated .pdb file. Otherwise the value of Guid is random and the value of DateTimeStamp indicates the time and date that the debug data was created.
*Version Major=any, Minor=0x504d* of the data format has the same structure as above. The Age shall be 1. The format of the associated .pdb file is Portable PDB. The Major version specified in the entry indicates the version of the Portable PDB format. Together 16B of the Guid concatenated with 4B of the TimeDateStamp field of the entry form a PDB ID that should be used to match the PE/COFF image with the associated PDB (instead of Guid and Age). Matching PDB ID is stored in the #Pdb stream of the .pdb file.
### Deterministic Debug Directory Entry (type 16)
The entry doesn't have any data associated with it. All fields of the entry, but Type shall be zero.
Presence of this entry indicates that the containing PE/COFF file is deterministic.
### Embedded Portable PDB Debug Directory Entry (type 17)
Declares that debugging information is embedded in the PE file at location specified by PointerToRawData.
*Version Major=any, Minor=0x0100* of the data format:
| Offset | Size | Field | Description |
|:-------|:---------------|:-----------------|-------------------------------------------------------|
| 0 | 4 | Signature | 0x4D 0x50 0x44 0x42 |
| 4 | 4 | UncompressedSize | The size of decompressed Portable PDB image |
| 8 | SizeOfData - 8 | PortablePdbImage | Portable PDB image compressed using Deflate algorithm |
If both CodeView and Embedded Portable PDB entries are present then they shall represent the same data.
> Note: The reader may prefer to read from the file if it exists. This may be more efficient as it avoids in-memory decompression.
> Note: Including both entries enables a tool that does not recognize Embedded Portable PDB entry to locate debug information as long as it is also available in a file specified in CodeView entry. Such file can be created by extracting the embedded Portable PDB image to a separate file.
UncompressedSize shall be greater than 0. Other values are reserved for future use, in case the format of the data changes.
> Note: Some tools and APIs only work with the data blob and don't have access to the Debug Directory Entry itself to determine the version of the data format. To enable these tools to adopt new versions of the data blob the UncompressedSize highest bit shall be used to indicate version change and the new version shall be included in the data blob.
The Major version specified in the entry indicates the version of the Portable PDB format. The Minor version indicates the version of the Embedded Portable PDB data format.
The value of Stamp field in the entry shall be 0.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netstandard1.1;
netcoreapp;
uap;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//------------------------------------------------------------
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("System.Reflection.Metadata.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010015c01ae1f50e8cc09ba9eac9147cf8fd9fce2cfe9f8dce4f7301c4132ca9fb50ce8cbf1df4dc18dd4d210e4345c744ecb3365ed327efdbc52603faa5e21daa11234c8c4a73e51f03bf192544581ebe107adee3a34928e39d04e524a9ce729d5090bfd7dad9d10c722c0def9ccc08ff0a03790e48bcd1f9b6c476063e1966a1c4")]

View File

@@ -0,0 +1,471 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ImageTooSmall" xml:space="preserve">
<value>Image is too small.</value>
</data>
<data name="InvalidCorHeaderSize" xml:space="preserve">
<value>Invalid COR header size.</value>
</data>
<data name="InvalidHandle" xml:space="preserve">
<value>Invalid handle.</value>
</data>
<data name="UnexpectedHandleKind" xml:space="preserve">
<value>Unexpected handle kind: {0}.</value>
</data>
<data name="UnexpectedOpCode" xml:space="preserve">
<value>Unexpected op-code: {0}.</value>
</data>
<data name="InvalidLocalSignatureToken" xml:space="preserve">
<value>Invalid local signature token: 0x{0:X8}</value>
</data>
<data name="InvalidMetadataSectionSpan" xml:space="preserve">
<value>Invalid metadata section span.</value>
</data>
<data name="InvalidMethodHeader1" xml:space="preserve">
<value>Invalid method header: 0x{0:X2}</value>
</data>
<data name="InvalidMethodHeader2" xml:space="preserve">
<value>Invalid method header: 0x{0:X2} 0x{1:X2}</value>
</data>
<data name="InvalidPESignature" xml:space="preserve">
<value>Invalid PE signature.</value>
</data>
<data name="InvalidSehHeader" xml:space="preserve">
<value>Invalid SEH header: 0x{0:X2}</value>
</data>
<data name="InvalidToken" xml:space="preserve">
<value>Invalid token.</value>
</data>
<data name="MetadataImageDoesNotRepresentAnAssembly" xml:space="preserve">
<value>Metadata image doesn't represent an assembly.</value>
</data>
<data name="StandaloneDebugMetadataImageDoesNotContainModuleTable" xml:space="preserve">
<value>Standalone debug metadata image doesn't contain Module table.</value>
</data>
<data name="PEImageNotAvailable" xml:space="preserve">
<value>PE image not available.</value>
</data>
<data name="MissingDataDirectory" xml:space="preserve">
<value>Missing data directory.</value>
</data>
<data name="NotMetadataHeapHandle" xml:space="preserve">
<value>Specified handle is not a valid metadata heap handle.</value>
</data>
<data name="NotMetadataTableOrUserStringHandle" xml:space="preserve">
<value>Specified handle is not a valid metadata table or UserString heap handle.</value>
</data>
<data name="SectionTooSmall" xml:space="preserve">
<value>Section too small.</value>
</data>
<data name="StreamMustSupportReadAndSeek" xml:space="preserve">
<value>Stream must support read and seek operations.</value>
</data>
<data name="UnknownFileFormat" xml:space="preserve">
<value>Unknown file format.</value>
</data>
<data name="UnknownPEMagicValue" xml:space="preserve">
<value>Unknown PE Magic value.</value>
</data>
<data name="MetadataTableNotSorted" xml:space="preserve">
<value>Metadata table {0} not sorted.</value>
</data>
<data name="AssemblyTableInvalidNumberOfRows" xml:space="preserve">
<value>Invalid number of rows of Assembly table: {0}.</value>
</data>
<data name="ModuleTableInvalidNumberOfRows" xml:space="preserve">
<value>Invalid number of rows of Module table: {0}.</value>
</data>
<data name="UnknownTables" xml:space="preserve">
<value>Unknown tables: 0x{0:x16}.</value>
</data>
<data name="IllegalTablesInCompressedMetadataStream" xml:space="preserve">
<value>Illegal tables in compressed metadata stream.</value>
</data>
<data name="TableRowCountSpaceTooSmall" xml:space="preserve">
<value>Table row count space to small.</value>
</data>
<data name="OutOfBoundsRead" xml:space="preserve">
<value>Read out of bounds.</value>
</data>
<data name="OutOfBoundsWrite" xml:space="preserve">
<value>Write out of bounds.</value>
</data>
<data name="MetadataHeaderTooSmall" xml:space="preserve">
<value>Metadata header too small.</value>
</data>
<data name="MetadataSignature" xml:space="preserve">
<value>Invalid COR20 header signature.</value>
</data>
<data name="NotEnoughSpaceForVersionString" xml:space="preserve">
<value>Not enough space for version string.</value>
</data>
<data name="StreamHeaderTooSmall" xml:space="preserve">
<value>Stream header too small.</value>
</data>
<data name="NotEnoughSpaceForStreamHeaderName" xml:space="preserve">
<value>Not enough space for stream header name.</value>
</data>
<data name="NotEnoughSpaceForStringStream" xml:space="preserve">
<value>Not enough space for String stream.</value>
</data>
<data name="NotEnoughSpaceForBlobStream" xml:space="preserve">
<value>Not enough space for Blob stream.</value>
</data>
<data name="NotEnoughSpaceForGUIDStream" xml:space="preserve">
<value>Not enough space for GUID stream.</value>
</data>
<data name="NotEnoughSpaceForMetadataStream" xml:space="preserve">
<value>Not enough space for Metadata stream.</value>
</data>
<data name="InvalidMetadataStreamFormat" xml:space="preserve">
<value>Invalid Metadata stream format.</value>
</data>
<data name="MetadataTablesTooSmall" xml:space="preserve">
<value>Metadata tables too small.</value>
</data>
<data name="MetadataTableHeaderTooSmall" xml:space="preserve">
<value>Metadata table header too small.</value>
</data>
<data name="WinMDMissingMscorlibRef" xml:space="preserve">
<value>Missing mscorlib reference in AssemblyRef table.</value>
</data>
<data name="UnableToReadMetadataFile" xml:space="preserve">
<value>Unable to read metadata file.</value>
</data>
<data name="UnexpectedStreamEnd" xml:space="preserve">
<value>Unexpected stream end.</value>
</data>
<data name="InvalidMethodRva" xml:space="preserve">
<value>Invalid relative virtual address (RVA): 0x{0:X8}</value>
</data>
<data name="CantGetOffsetForVirtualHeapHandle" xml:space="preserve">
<value>Can't get a heap offset for a virtual heap handle</value>
</data>
<data name="InvalidSectionName" xml:space="preserve">
<value>Invalid section name</value>
</data>
<data name="InvalidNumberOfSections" xml:space="preserve">
<value>Invalid number of sections in declared in PE header.</value>
</data>
<data name="InvalidSignature" xml:space="preserve">
<value>Invalid signature.</value>
</data>
<data name="PEImageDoesNotHaveMetadata" xml:space="preserve">
<value>PE image does not have metadata.</value>
</data>
<data name="InvalidCodedIndex" xml:space="preserve">
<value>Invalid coded index.</value>
</data>
<data name="InvalidCompressedInteger" xml:space="preserve">
<value>Invalid compressed integer.</value>
</data>
<data name="InvalidDocumentName" xml:space="preserve">
<value>Invalid document name.</value>
</data>
<data name="RowIdOrHeapOffsetTooLarge" xml:space="preserve">
<value>Row ID or heap offset is too large.</value>
</data>
<data name="EnCMapNotSorted" xml:space="preserve">
<value>EnCMap table not sorted or has missing records.</value>
</data>
<data name="InvalidSerializedString" xml:space="preserve">
<value>Invalid serialized string.</value>
</data>
<data name="StreamTooLarge" xml:space="preserve">
<value>Stream length minus starting position is too large to hold a PEImage.</value>
</data>
<data name="NegativeByteCountOrOffset" xml:space="preserve">
<value>Negative byte count or offset.</value>
</data>
<data name="ImageTooSmallOrContainsInvalidOffsetOrCount" xml:space="preserve">
<value>Image is either too small or contains an invalid byte offset or count.</value>
</data>
<data name="LitteEndianArchitectureRequired" xml:space="preserve">
<value>Little-endian architecture required.</value>
</data>
<data name="MetadataStringDecoderEncodingMustBeUtf8" xml:space="preserve">
<value>The MetadataStringDecoder instance used to instantiate the Metadata reader must have a UTF8 encoding.</value>
</data>
<data name="InvalidConstantValue" xml:space="preserve">
<value>Invalid constant value.</value>
</data>
<data name="InvalidConstantValueOfType" xml:space="preserve">
<value>Value of type '{0}' is not a constant.</value>
</data>
<data name="InvalidImportDefinitionKind" xml:space="preserve">
<value>Invalid import definition kind: {0}.</value>
</data>
<data name="ValueTooLarge" xml:space="preserve">
<value>Value is too large.</value>
</data>
<data name="BlobTooLarge" xml:space="preserve">
<value>Blob is to large.</value>
</data>
<data name="InvalidTypeSize" xml:space="preserve">
<value>Invalid type size.</value>
</data>
<data name="HandleBelongsToFutureGeneration" xml:space="preserve">
<value>Handle belongs to a future generation</value>
</data>
<data name="InvalidRowCount" xml:space="preserve">
<value>Invalid row count: {0}</value>
</data>
<data name="InvalidEntryPointToken" xml:space="preserve">
<value>Invalid entry point token: 0x{0:8X}</value>
</data>
<data name="TooManySubnamespaces" xml:space="preserve">
<value>There are too many subnamespaces.</value>
</data>
<data name="TooManyExceptionRegions" xml:space="preserve">
<value>There are too many exception regions.</value>
</data>
<data name="SequencePointValueOutOfRange" xml:space="preserve">
<value>Sequence point value is out of range.</value>
</data>
<data name="InvalidDirectoryRVA" xml:space="preserve">
<value>Invalid directory relative virtual address.</value>
</data>
<data name="InvalidDirectorySize" xml:space="preserve">
<value>Invalid directory size.</value>
</data>
<data name="InvalidDebugDirectoryEntryCharacteristics" xml:space="preserve">
<value>The value of field Characteristics in debug directory entry must be zero.</value>
</data>
<data name="UnexpectedCodeViewDataSignature" xml:space="preserve">
<value>Unexpected CodeView data signature value.</value>
</data>
<data name="UnexpectedEmbeddedPortablePdbDataSignature" xml:space="preserve">
<value>Unexpected Embedded Portable PDB data signature value.</value>
</data>
<data name="UnexpectedSignatureHeader" xml:space="preserve">
<value>Expected signature header for '{0}', but found '{1}' (0x{2:x2}).</value>
</data>
<data name="UnexpectedSignatureHeader2" xml:space="preserve">
<value>Expected signature header for '{0}' or '{1}', but found '{2}' (0x{3:x2}).</value>
</data>
<data name="NotTypeDefOrRefHandle" xml:space="preserve">
<value>Specified handle is not a TypeDefinitionHandle or TypeRefererenceHandle.</value>
</data>
<data name="UnexpectedSignatureTypeCode" xml:space="preserve">
<value>Unexpected SignatureTypeCode: (0x{0:x}).</value>
</data>
<data name="SignatureTypeSequenceMustHaveAtLeastOneElement" xml:space="preserve">
<value>Signature type sequence must have at least one element.</value>
</data>
<data name="NotTypeDefOrRefOrSpecHandle" xml:space="preserve">
<value>Specified handle is not a TypeDefinitionHandle, TypeRefererenceHandle, or TypeSpecificationHandle.</value>
</data>
<data name="UnexpectedDebugDirectoryType" xml:space="preserve">
<value>The Debug directory was not of type {0}.</value>
</data>
<data name="HeapSizeLimitExceeded" xml:space="preserve">
<value>The limit on the size of {0} heap has been exceeded.</value>
</data>
<data name="BuilderMustAligned" xml:space="preserve">
<value>Builder must be aligned to 4 byte boundary.</value>
</data>
<data name="BuilderAlreadyLinked" xml:space="preserve">
<value>The operation is not valid on this builder as it has been linked with another one.</value>
</data>
<data name="ReturnedBuilderSizeTooSmall" xml:space="preserve">
<value>The size of the builder returned by {0}.{1} is smaller than requested.</value>
</data>
<data name="SignatureNotVarArg" xml:space="preserve">
<value>Can't add vararg parameters to non-vararg signature.</value>
</data>
<data name="LabelDoesntBelongToBuilder" xml:space="preserve">
<value>Specified label doesn't belong to the current builder.</value>
</data>
<data name="ControlFlowBuilderNotAvailable" xml:space="preserve">
<value>Can't emit a branch or exception region, the current encoder not created with a control flow builder.</value>
</data>
<data name="BaseReaderMustBeFullMetadataReader" xml:space="preserve">
<value>Base reader must be a full metadata reader.</value>
</data>
<data name="ModuleAlreadyAdded" xml:space="preserve">
<value>Module already added.</value>
</data>
<data name="AssemblyAlreadyAdded" xml:space="preserve">
<value>Assembly already added.</value>
</data>
<data name="ExpectedListOfSize" xml:space="preserve">
<value>Expected list of size {0}.</value>
</data>
<data name="ExpectedArrayOfSize" xml:space="preserve">
<value>Expected array of size {0}.</value>
</data>
<data name="ExpectedNonEmptyList" xml:space="preserve">
<value>Expected non-empty list.</value>
</data>
<data name="ExpectedNonEmptyString" xml:space="preserve">
<value>Expected non-empty string.</value>
</data>
<data name="ReadersMustBeDeltaReaders" xml:space="preserve">
<value>Specified readers must be minimal delta metadata readers.</value>
</data>
<data name="SignatureProviderReturnedInvalidSignature" xml:space="preserve">
<value>Signature provider returned invalid signature.</value>
</data>
<data name="UnknownSectionName" xml:space="preserve">
<value>Unknown section name: '{0}'.</value>
</data>
<data name="HashTooShort" xml:space="preserve">
<value>Hash must be at least {0}B long.</value>
</data>
<data name="UnexpectedArrayLength" xml:space="preserve">
<value>Expected array of length {0}.</value>
</data>
<data name="ValueMustBeMultiple" xml:space="preserve">
<value>Value must be multiple of {0}.</value>
</data>
<data name="MustNotReturnNull" xml:space="preserve">
<value>{0} must not return null.</value>
</data>
<data name="MetadataVersionTooLong" xml:space="preserve">
<value>Metadata version too long.</value>
</data>
<data name="RowCountMustBeZero" xml:space="preserve">
<value>Row count must be zero for table #{0}.</value>
</data>
<data name="RowCountOutOfRange" xml:space="preserve">
<value>Row count specified for table index {0} is out of allowed range.</value>
</data>
<data name="SizeMismatch" xml:space="preserve">
<value>Declared size doesn't correspond to the actual size.</value>
</data>
<data name="DataTooBig" xml:space="preserve">
<value>Data too big to fit in memory.</value>
</data>
<data name="UnsupportedFormatVersion" xml:space="preserve">
<value>Unsupported format version: {0}</value>
</data>
<data name="DistanceBetweenInstructionAndLabelTooBig" xml:space="preserve">
<value>The distance between the instruction {0} (offset {1}) and the target label doesn't fit the operand size: {2}</value>
</data>
<data name="LabelNotMarked" xml:space="preserve">
<value>Label {0} has not been marked.</value>
</data>
<data name="MethodHasNoExceptionRegions" xml:space="preserve">
<value>Method body was created with no exception regions.</value>
</data>
<data name="InvalidExceptionRegionBounds" xml:space="preserve">
<value>Invalid exception region bounds: start offset ({0}) is greater than end offset ({1}).</value>
</data>
</root>

View File

@@ -0,0 +1,259 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<ProjectGuid>{F3E433C8-352F-4944-BF7F-765CE435370D}</ProjectGuid>
<AssemblyName>System.Reflection.Metadata</AssemblyName>
<DocumentationFile>$(OutputPath)System.Reflection.Metadata.xml</DocumentationFile>
<RootNamespace>System.Reflection.Metadata</RootNamespace>
<FileAlignment>512</FileAlignment>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefaultLanguage>en-US</DefaultLanguage>
<NoWarn>1591</NoWarn>
<CLSCompliant>false</CLSCompliant>
<PackageTargetFramework Condition="'$(TargetGroup)' == 'netstandard1.1'">netstandard1.1;portable-net45+win8</PackageTargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard1.1-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard1.1-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="System\Reflection\Internal\Utilities\ExceptionUtilities.cs" />
<Compile Include="System\Reflection\Internal\Utilities\PathUtilities.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\Encoding\FunctionPointerAttributes.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\Encoding\MethodBodyStreamEncoder.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\Encoding\MethodBodyAttributes.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\MetadataBuilder.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\MetadataRootBuilder.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\SerializedMetadataHeaps.cs" />
<Compile Include="System\Reflection\Metadata\EntityHandle.cs" />
<Compile Include="System\Reflection\Metadata\Internal\VirtualHeap.cs" />
<Compile Include="System\Reflection\Metadata\Internal\GuidHeap.cs" />
<Compile Include="System\Reflection\Metadata\Internal\BlobHeap.cs" />
<Compile Include="System\Reflection\Metadata\Internal\StringHeap.cs" />
<Compile Include="System\Reflection\Metadata\PooledBlobBuilder.cs" />
<Compile Include="System\Reflection\Metadata\Blob.cs" />
<Compile Include="System\Reflection\Metadata\BlobWriter.cs" />
<Compile Include="System\Reflection\Metadata\BlobWriterImpl.cs" />
<Compile Include="System\Reflection\Metadata\BlobBuilder.cs" />
<Compile Include="System\Reflection\Metadata\BlobBuilder.Enumerators.cs" />
<Compile Include="System\Reflection\Internal\Utilities\ByteSequenceComparer.cs" />
<Compile Include="System\Reflection\Internal\Utilities\DecimalUtilities.cs" />
<Compile Include="System\Reflection\Internal\Utilities\EnumerableExtensions.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\CustomAttributeDecoder.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\PortablePdbVersions.cs" />
<Compile Include="System\Reflection\Metadata\ReservedBlob.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\CustomAttributeNamedArgument.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\CustomAttributeTypedArgument.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\CustomAttributeValue.cs" />
<Compile Include="System\Reflection\Metadata\Decoding\ICustomAttributeTypeProvider.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\Encoding\ControlFlowBuilder.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\Encoding\ExceptionRegionEncoder.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\Encoding\InstructionEncoder.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\Encoding\LabelHandle.cs" />
<Compile Include="System\Reflection\Metadata\IL\ILOpCode.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\CodedIndex.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\PortablePdbBuilder.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\MetadataBuilder.Tables.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\Encoding\BlobEncoders.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\MetadataSizes.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\MetadataBuilder.Heaps.cs" />
<Compile Include="System\Reflection\Metadata\IL\ILOpCodeExtensions.cs" />
<Compile Include="System\Reflection\Metadata\ImageFormatLimitationException.cs" />
<Compile Include="System\Reflection\Metadata\Internal\HeapSizeFlag.cs" />
<Compile Include="System\Reflection\Metadata\Internal\MetadataWriterUtilities.cs" />
<Compile Include="System\Reflection\Metadata\MetadataStreamOptions.cs" />
<Compile Include="System\Reflection\Metadata\MetadataReaderProvider.cs" />
<Compile Include="System\Reflection\Metadata\BlobContentId.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\PrimitiveSerializationTypeCode.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\Handles.TypeSystem.cs" />
<Compile Include="System\Reflection\PortableExecutable\ManagedPEBuilder.cs" />
<Compile Include="System\Reflection\PortableExecutable\ManagedTextSection.cs" />
<Compile Include="System\Reflection\PortableExecutable\PEBuilder.cs" />
<Compile Include="System\Reflection\PortableExecutable\DebugDirectory\DebugDirectoryBuilder.cs" />
<Compile Include="System\Reflection\PortableExecutable\PEDirectoriesBuilder.cs" />
<Compile Include="System\Reflection\PortableExecutable\PEHeaderBuilder.cs" />
<Compile Include="System\Reflection\PortableExecutable\ResourceSectionBuilder.cs" />
<Compile Include="System\Reflection\PortableExecutable\SectionLocation.cs" />
<Compile Include="System\Reflection\Internal\Utilities\BlobUtilities.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\InternalsVisibleTo.cs" />
<Compile Include="System\Reflection\Internal\MemoryBlocks\AbstractMemoryBlock.cs" />
<Compile Include="System\Reflection\Internal\MemoryBlocks\ByteArrayMemoryBlock.cs" />
<Compile Include="System\Reflection\Internal\MemoryBlocks\ByteArrayMemoryProvider.cs" />
<Compile Include="System\Reflection\Internal\MemoryBlocks\ExternalMemoryBlock.cs" />
<Compile Include="System\Reflection\Internal\MemoryBlocks\ExternalMemoryBlockProvider.cs" />
<Compile Include="System\Reflection\Internal\MemoryBlocks\MemoryBlockProvider.cs" />
<Compile Include="System\Reflection\Internal\MemoryBlocks\MemoryMappedFileBlock.cs" />
<Compile Include="System\Reflection\Internal\MemoryBlocks\NativeHeapMemoryBlock.cs" />
<Compile Include="System\Reflection\Internal\MemoryBlocks\StreamConstraints.cs" />
<Compile Include="System\Reflection\Internal\MemoryBlocks\StreamMemoryBlockProvider.cs" />
<Compile Include="System\Reflection\Internal\Utilities\BitArithmetic.cs" />
<Compile Include="System\Reflection\Internal\Utilities\StringUtils.cs" />
<Compile Include="System\Reflection\Internal\Utilities\EmptyArray.cs" />
<Compile Include="System\Reflection\Internal\Utilities\EncodingHelper.cs" />
<Compile Include="System\Reflection\Internal\Utilities\FileStreamReadLightUp.cs" />
<Compile Include="System\Reflection\Internal\Utilities\Hash.cs" />
<Compile Include="System\Reflection\Internal\Utilities\ImmutableByteArrayInterop.cs" />
<Compile Include="System\Reflection\Internal\Utilities\ImmutableMemoryStream.cs" />
<Compile Include="System\Reflection\Internal\Utilities\LightUpHelper.cs" />
<Compile Include="System\Reflection\Internal\Utilities\MemoryBlock.cs" />
<Compile Include="System\Reflection\Internal\Utilities\MemoryMapLightUp.cs" />
<Compile Include="System\Reflection\Internal\Utilities\PooledStringBuilder.cs" />
<Compile Include="System\Reflection\Internal\Utilities\ObjectPool`1.cs" />
<Compile Include="System\Reflection\Internal\Utilities\ReadOnlyUnmanagedMemoryStream.cs" />
<Compile Include="System\Reflection\Internal\Utilities\StreamExtensions.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\AssemblyDefinition.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\AssemblyFile.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\AssemblyReference.cs" />
<Compile Include="System\Reflection\Metadata\BlobReader.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\Constant.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\ConstantTypeCode.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\CustomAttribute.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\CustomAttributeNamedArgumentKind.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\DeclarativeSecurityAttribute.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\ArrayShape.cs" />
<Compile Include="System\Reflection\Metadata\Decoding\ISZArrayTypeProvider.cs" />
<Compile Include="System\Reflection\Metadata\Decoding\ISignatureTypeProvider.cs" />
<Compile Include="System\Reflection\Metadata\Decoding\ISimpleTypeProvider.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\SignatureTypeKind.cs" />
<Compile Include="System\Reflection\Metadata\Decoding\IConstructedTypeProvider.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\SignatureDecoder.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\MethodSignature.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\PrimitiveTypeCode.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\EditAndContinueLogEntry.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\EditAndContinueOperation.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\ExportedTypeExtensions.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\HeapIndex.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\MetadataReaderExtensions.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\MetadataTokens.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\TableIndex.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\EventDefinition.cs" />
<Compile Include="System\Reflection\Metadata\IL\ExceptionRegion.cs" />
<Compile Include="System\Reflection\Metadata\IL\ExceptionRegionKind.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\ExportedType.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\FieldDefinition.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\GenericParameter.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\GenericParameterConstraint.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\HandleCollections.TypeSystem.cs" />
<Compile Include="System\Reflection\Metadata\HandleComparer.cs" />
<Compile Include="System\Reflection\Metadata\HandleKind.cs" />
<Compile Include="System\Reflection\Metadata\Handle.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\InterfaceImplementation.cs" />
<Compile Include="System\Reflection\Metadata\Internal\COR20Constants.cs" />
<Compile Include="System\Reflection\Metadata\Internal\CorElementType.cs" />
<Compile Include="System\Reflection\Metadata\Internal\CustomAttributeTypeTag.cs" />
<Compile Include="System\Reflection\Metadata\Internal\HasConstantTag.cs" />
<Compile Include="System\Reflection\Metadata\Internal\HasCustomAttributeTag.cs" />
<Compile Include="System\Reflection\Metadata\Internal\HasDeclSecurityTag.cs" />
<Compile Include="System\Reflection\Metadata\Internal\HasFieldMarshalTag.cs" />
<Compile Include="System\Reflection\Metadata\Internal\HasSemanticsTag.cs" />
<Compile Include="System\Reflection\Metadata\Internal\UserStringHeap.cs" />
<Compile Include="System\Reflection\Metadata\Internal\ImplementationTag.cs" />
<Compile Include="System\Reflection\Metadata\Internal\MemberForwardedTag.cs" />
<Compile Include="System\Reflection\Metadata\Internal\MemberRefParentTag.cs" />
<Compile Include="System\Reflection\Metadata\Internal\MetadataFlags.cs" />
<Compile Include="System\Reflection\Metadata\Internal\MetadataStreamConstants.cs" />
<Compile Include="System\Reflection\Metadata\Internal\MethodDefOrRefTag.cs" />
<Compile Include="System\Reflection\Metadata\Internal\NamespaceCache.cs" />
<Compile Include="System\Reflection\Metadata\Internal\NamespaceData.cs" />
<Compile Include="System\Reflection\Metadata\Internal\ResolutionScopeTag.cs" />
<Compile Include="System\Reflection\Metadata\Internal\StreamHeader.cs" />
<Compile Include="System\Reflection\Metadata\Internal\Tables.cs" />
<Compile Include="System\Reflection\Metadata\Internal\Treatments.cs" />
<Compile Include="System\Reflection\Metadata\Internal\TypeDefOrRefTag.cs" />
<Compile Include="System\Reflection\Metadata\Internal\TypeOrMethodDefTag.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\ManifestResource.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\MemberReference.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\StandaloneSignatureKind.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\MemberReferenceKind.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\MetadataAggregator.cs" />
<Compile Include="System\Reflection\Metadata\MetadataKind.cs" />
<Compile Include="System\Reflection\Metadata\MetadataReader.cs" />
<Compile Include="System\Reflection\Metadata\MetadataReader.WinMD.cs" />
<Compile Include="System\Reflection\Metadata\MetadataReaderOptions.cs" />
<Compile Include="System\Reflection\Metadata\MetadataStringComparer.cs" />
<Compile Include="System\Reflection\Metadata\MetadataStringDecoder.cs" />
<Compile Include="System\Reflection\Metadata\IL\MethodBodyBlock.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\MethodDefinition.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\MethodImplementation.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\MethodImport.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\MethodSpecification.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\ModuleDefinition.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\ModuleReference.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\NamespaceDefinition.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\Parameter.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\CustomDebugInformation.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\DebugMetadataHeader.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\Document.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\DocumentNameBlobHandle.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\HandleCollections.Debug.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\Handles.Debug.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\HasCustomDebugInformationTag.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\ImportDefinition.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\ImportDefinitionKind.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\ImportDefinitionCollection.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\LocalConstant.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\ImportScope.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\LocalScope.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\LocalVariable.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\LocalVariableAttributes.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\MethodDebugInformation.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\SequencePoint.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\SequencePointCollection.cs" />
<Compile Include="System\Reflection\Metadata\PortablePdb\Tables.Debug.cs" />
<Compile Include="System\Reflection\Metadata\PEReaderExtensions.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\PropertyDefinition.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\SerializationTypeCode.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\SignatureAttributes.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\SignatureCallingConvention.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\SignatureHeader.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\SignatureKind.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\SignatureTypeCode.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\StandaloneSignature.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\TypeDefinition.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\TypeLayout.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\TypeReference.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\TypeSpecification.cs" />
<Compile Include="System\Reflection\PortableExecutable\CoffHeader.cs" />
<Compile Include="System\Reflection\PortableExecutable\CorFlags.cs" />
<Compile Include="System\Reflection\PortableExecutable\CorHeader.cs" />
<Compile Include="System\Reflection\PortableExecutable\DebugDirectory\CodeViewDebugDirectoryData.cs" />
<Compile Include="System\Reflection\PortableExecutable\DebugDirectory\DebugDirectoryEntry.cs" />
<Compile Include="System\Reflection\PortableExecutable\DebugDirectory\DebugDirectoryEntryType.cs" />
<Compile Include="System\Reflection\PortableExecutable\DirectoryEntry.cs" />
<Compile Include="System\Reflection\PortableExecutable\Machine.cs" />
<Compile Include="System\Reflection\PortableExecutable\PEBinaryReader.cs" />
<Compile Include="System\Reflection\PortableExecutable\PEFileFlags.cs" />
<Compile Include="System\Reflection\PortableExecutable\PEHeader.cs" />
<Compile Include="System\Reflection\PortableExecutable\PEHeaders.cs" />
<Compile Include="System\Reflection\PortableExecutable\PEMemoryBlock.cs" />
<Compile Include="System\Reflection\PortableExecutable\PEReader.cs" />
<Compile Include="System\Reflection\PortableExecutable\PEStreamOptions.cs" />
<Compile Include="System\Reflection\PortableExecutable\SectionHeader.cs" />
<Compile Include="System\Reflection\Throw.cs" />
<Compile Include="System\Reflection\System.Reflection.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\System.Collections.Immutable\src\System.Collections.Immutable.csproj" />
<Reference Include="System.Collections" />
<Reference Include="System.Diagnostics.Debug" />
<Reference Include="System.IO" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Linq" />
<Reference Include="System.Reflection" />
<Reference Include="System.Reflection.Extensions" />
<Reference Include="System.Reflection.Primitives" />
<Reference Include="System.Resources.ResourceManager" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.Extensions" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Text.Encoding" />
<Reference Include="System.Text.Encoding.Extensions" />
<Reference Include="System.Threading" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -0,0 +1,61 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Immutable;
using System.Reflection.Metadata;
namespace System.Reflection.Internal
{
/// <summary>
/// Represents a disposable blob of memory accessed via unsafe pointer.
/// </summary>
internal abstract class AbstractMemoryBlock : IDisposable
{
/// <summary>
/// Pointer to the underlying data (not valid after disposal).
/// </summary>
public unsafe abstract byte* Pointer { get; }
/// <summary>
/// Size of the block.
/// </summary>
public abstract int Size { get; }
public unsafe BlobReader GetReader() => new BlobReader(Pointer, Size);
/// <summary>
/// Returns the content of the entire memory block.
/// </summary>
/// <remarks>
/// Does not check bounds.
///
/// Only creates a copy of the data if they are not represented by a managed byte array,
/// or if the specified range doens't span the entire block.
/// </remarks>
public unsafe virtual ImmutableArray<byte> GetContentUnchecked(int start, int length)
{
var result = BlobUtilities.ReadImmutableBytes(Pointer + start, length);
GC.KeepAlive(this);
return result;
}
/// <summary>
/// Disposes the block.
/// </summary>
/// <remarks>
/// The operation is idempotent, but must not be called concurrently with any other operations on the block
/// or with another call to Dispose.
///
/// Using the block after dispose is an error in our code and therefore no effort is made to throw a tidy
/// ObjectDisposedException and null ref or AV is possible.
/// </remarks>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected abstract void Dispose(bool disposing);
}
}

View File

@@ -0,0 +1,40 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Immutable;
using System.Diagnostics;
namespace System.Reflection.Internal
{
/// <summary>
/// Represents a memory block backed by an array of bytes.
/// </summary>
internal sealed class ByteArrayMemoryBlock : AbstractMemoryBlock
{
private ByteArrayMemoryProvider _provider;
private readonly int _start;
private readonly int _size;
internal ByteArrayMemoryBlock(ByteArrayMemoryProvider provider, int start, int size)
{
_provider = provider;
_size = size;
_start = start;
}
protected override void Dispose(bool disposing)
{
Debug.Assert(disposing);
_provider = null;
}
public unsafe override byte* Pointer => _provider.Pointer + _start;
public override int Size => _size;
public override ImmutableArray<byte> GetContentUnchecked(int start, int length)
{
return ImmutableArray.Create(_provider.Array, _start + start, length);
}
}
}

View File

@@ -0,0 +1,70 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
namespace System.Reflection.Internal
{
internal sealed class ByteArrayMemoryProvider : MemoryBlockProvider
{
private readonly ImmutableArray<byte> _array;
private StrongBox<GCHandle> _pinned;
public ByteArrayMemoryProvider(ImmutableArray<byte> array)
{
Debug.Assert(!array.IsDefault);
_array = array;
}
~ByteArrayMemoryProvider()
{
Dispose(disposing: false);
}
protected override void Dispose(bool disposing)
{
_pinned?.Value.Free();
_pinned = null;
}
public override int Size => _array.Length;
public ImmutableArray<byte> Array => _array;
protected override AbstractMemoryBlock GetMemoryBlockImpl(int start, int size)
{
return new ByteArrayMemoryBlock(this, start, size);
}
public override Stream GetStream(out StreamConstraints constraints)
{
constraints = new StreamConstraints(null, 0, Size);
return new ImmutableMemoryStream(_array);
}
internal unsafe byte* Pointer
{
get
{
if (_pinned == null)
{
var newPinned = new StrongBox<GCHandle>(
GCHandle.Alloc(ImmutableByteArrayInterop.DangerousGetUnderlyingArray(_array), GCHandleType.Pinned));
if (Interlocked.CompareExchange(ref _pinned, newPinned, null) != null)
{
// another thread has already allocated the handle:
newPinned.Value.Free();
}
}
return (byte*)_pinned.Value.AddrOfPinnedObject();
}
}
}
}

View File

@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Immutable;
using System.Diagnostics;
namespace System.Reflection.Internal
{
/// <summary>
/// Class representing raw memory but not owning the memory.
/// </summary>
internal unsafe sealed class ExternalMemoryBlock : AbstractMemoryBlock
{
// keeps the owner of the memory alive as long as the block is alive:
private readonly object _memoryOwner;
private byte* _buffer;
private int _size;
public ExternalMemoryBlock(object memoryOwner, byte* buffer, int size)
{
_memoryOwner = memoryOwner;
_buffer = buffer;
_size = size;
}
protected override void Dispose(bool disposing)
{
Debug.Assert(disposing);
_buffer = null;
_size = 0;
}
public override byte* Pointer => _buffer;
public override int Size => _size;
}
}

View File

@@ -0,0 +1,60 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
using System.IO;
namespace System.Reflection.Internal
{
/// <summary>
/// Represents raw memory owned by an external object.
/// </summary>
internal unsafe sealed class ExternalMemoryBlockProvider : MemoryBlockProvider
{
private byte* _memory;
private int _size;
public unsafe ExternalMemoryBlockProvider(byte* memory, int size)
{
_memory = memory;
_size = size;
}
public override int Size
{
get
{
return _size;
}
}
protected override AbstractMemoryBlock GetMemoryBlockImpl(int start, int size)
{
return new ExternalMemoryBlock(this, _memory + start, size);
}
public override Stream GetStream(out StreamConstraints constraints)
{
constraints = new StreamConstraints(null, 0, _size);
return new ReadOnlyUnmanagedMemoryStream(_memory, _size);
}
protected override void Dispose(bool disposing)
{
Debug.Assert(disposing);
// we don't own the memory, just null out the pointer.
_memory = null;
_size = 0;
}
public byte* Pointer
{
get
{
return _memory;
}
}
}
}

View File

@@ -0,0 +1,63 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.IO;
using System.Reflection.PortableExecutable;
namespace System.Reflection.Internal
{
internal abstract class MemoryBlockProvider : IDisposable
{
/// <summary>
/// Creates and hydrates a memory block representing all data.
/// </summary>
/// <exception cref="IOException">Error while reading from the memory source.</exception>
public AbstractMemoryBlock GetMemoryBlock()
{
return GetMemoryBlockImpl(0, Size);
}
/// <summary>
/// Creates and hydrates a memory block representing data in the specified range.
/// </summary>
/// <param name="start">Starting offset relative to the beginning of the data represented by this provider.</param>
/// <param name="size">Size of the resulting block.</param>
/// <exception cref="IOException">Error while reading from the memory source.</exception>
public AbstractMemoryBlock GetMemoryBlock(int start, int size)
{
// Add cannot overflow as it is the sum of two 32-bit values done in 64 bits.
// Negative start or size is handle by overflow to greater than maximum size = int.MaxValue.
if ((ulong)(unchecked((uint)start)) + unchecked((uint)size) > (ulong)this.Size)
{
Throw.ImageTooSmallOrContainsInvalidOffsetOrCount();
}
return GetMemoryBlockImpl(start, size);
}
/// <exception cref="IOException">IO error while reading from the underlying stream.</exception>
protected abstract AbstractMemoryBlock GetMemoryBlockImpl(int start, int size);
/// <summary>
/// Gets a seekable and readable <see cref="Stream"/> that can be used to read all data.
/// The operations on the stream has to be done under a lock of <see cref="StreamConstraints.GuardOpt"/> if non-null.
/// The image starts at <see cref="StreamConstraints.ImageStart"/> and has size <see cref="StreamConstraints.ImageSize"/>.
/// It is the caller's responsibility not to read outside those bounds.
/// </summary>
public abstract Stream GetStream(out StreamConstraints constraints);
/// <summary>
/// The size of the data.
/// </summary>
public abstract int Size { get; }
protected abstract void Dispose(bool disposing);
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

View File

@@ -0,0 +1,50 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Immutable;
using System.Runtime.InteropServices;
namespace System.Reflection.Internal
{
internal unsafe sealed class MemoryMappedFileBlock : AbstractMemoryBlock
{
private readonly int _size;
private IDisposable _accessor; // MemoryMappedViewAccessor
private byte* _pointer;
private SafeBuffer _safeBuffer;
internal unsafe MemoryMappedFileBlock(IDisposable accessor, SafeBuffer safeBuffer, byte* pointer, int size)
{
_accessor = accessor;
_safeBuffer = safeBuffer;
_pointer = pointer;
_size = size;
}
~MemoryMappedFileBlock()
{
Dispose(false);
}
protected override void Dispose(bool disposing)
{
if (_safeBuffer != null)
{
_safeBuffer.ReleasePointer();
_safeBuffer = null;
}
if (_accessor != null)
{
_accessor.Dispose();
_accessor = null;
}
_pointer = null;
}
public override byte* Pointer => _pointer;
public override int Size => _size;
}
}

View File

@@ -0,0 +1,41 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Immutable;
using System.Runtime.InteropServices;
namespace System.Reflection.Internal
{
/// <summary>
/// Represents memory block allocated on native heap.
/// </summary>
/// <remarks>
/// Owns the native memory resource.
/// </remarks>
internal unsafe sealed class NativeHeapMemoryBlock : AbstractMemoryBlock
{
private byte* _pointer;
private readonly int _size;
internal NativeHeapMemoryBlock(int size)
{
_pointer = (byte*)Marshal.AllocHGlobal(size);
_size = size;
}
~NativeHeapMemoryBlock()
{
Dispose(false);
}
protected override void Dispose(bool disposing)
{
Marshal.FreeHGlobal((IntPtr)_pointer);
_pointer = null;
}
public override byte* Pointer => _pointer;
public override int Size => _size;
}
}

View File

@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System.Reflection.Internal
{
internal struct StreamConstraints
{
public readonly object GuardOpt;
public readonly long ImageStart;
public readonly int ImageSize;
public StreamConstraints(object guardOpt, long startPosition, int imageSize)
{
GuardOpt = guardOpt;
ImageStart = startPosition;
ImageSize = imageSize;
}
}
}

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