-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathSymReaderMetadataAdapter.cs
More file actions
121 lines (105 loc) · 3.75 KB
/
SymReaderMetadataAdapter.cs
File metadata and controls
121 lines (105 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// 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.txt file in the project root for more information.
using System.Runtime.InteropServices;
using System.Reflection;
using System.Diagnostics;
#if NET9_0_OR_GREATER
using System.Runtime.InteropServices.Marshalling;
#endif
namespace Microsoft.DiaSymReader
{
/// <summary>
/// Minimal implementation of IMetadataImport that implements APIs used by SymReader.
/// </summary>
#if NET9_0_OR_GREATER
[GeneratedComClass]
#endif
internal unsafe sealed partial class SymReaderMetadataAdapter : MetadataAdapterBase
{
private readonly ISymReaderMetadataProvider _metadataProvider;
public SymReaderMetadataAdapter(ISymReaderMetadataProvider metadataProvider)
{
Debug.Assert(metadataProvider != null);
_metadataProvider = metadataProvider!;
}
public override int GetSigFromToken(
int standaloneSignature,
[Out]byte** signature,
[Out]int* signatureLength)
{
// Happens when a constant doesn't have a signature:
// The caller expect the signature to have at least one byte on success,
// so we need to fail here. Otherwise AV happens.
var hr = _metadataProvider.TryGetStandaloneSignature(standaloneSignature, out byte* sig, out int length) ? HResult.S_OK : HResult.E_INVALIDARG;
if (signature != null)
{
*signature = sig;
}
if (signatureLength != null)
{
*signatureLength = length;
}
return hr;
}
public override int GetTypeDefProps(
int typeDef,
[Out]char* qualifiedName,
int qualifiedNameBufferLength,
[Out]int* qualifiedNameLength,
[Out]TypeAttributes* attributes,
[Out]int* baseType)
{
if (!_metadataProvider.TryGetTypeDefinitionInfo(typeDef, out var namespaceName, out var typeName, out var typeAttributes))
{
return HResult.E_INVALIDARG;
}
if (qualifiedNameLength != null || qualifiedName != null)
{
InteropUtilities.CopyQualifiedTypeName(
qualifiedName,
qualifiedNameBufferLength,
qualifiedNameLength,
namespaceName,
typeName);
}
if (attributes != null)
{
*attributes = typeAttributes;
}
if (baseType != null)
{
// unused
*baseType = 0;
}
return HResult.S_OK;
}
public override int GetTypeRefProps(
int typeRef,
[Out]int* resolutionScope, // ModuleRef or AssemblyRef
[Out]char* qualifiedName,
int qualifiedNameBufferLength,
[Out]int* qualifiedNameLength)
{
if (!_metadataProvider.TryGetTypeReferenceInfo(typeRef, out var namespaceName, out var typeName))
{
return HResult.E_INVALIDARG;
}
if (qualifiedNameLength != null || qualifiedName != null)
{
InteropUtilities.CopyQualifiedTypeName(
qualifiedName,
qualifiedNameBufferLength,
qualifiedNameLength,
namespaceName,
typeName);
}
if (resolutionScope != null)
{
// unused
*resolutionScope = 0;
}
return HResult.S_OK;
}
}
}