Skip to content

Commit f2b7911

Browse files
authored
Adding GetComWrappersRCWData cDAC API (#118428)
* adding GetComWrappersRCWData cDAC API * allow duplicate contract and global names
1 parent 44414bf commit f2b7911

File tree

27 files changed

+280
-118
lines changed

27 files changed

+280
-118
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Contract ComWrappers
2+
3+
This contract is for getting information related to COM wrappers.
4+
5+
## APIs of contract
6+
7+
``` csharp
8+
// Get the address of the external COM object
9+
TargetPointer GetComWrappersIdentity(TargetPointer rcw);
10+
```
11+
12+
## Version 1
13+
14+
Data descriptors used:
15+
| Data Descriptor Name | Field | Meaning |
16+
| --- | --- | --- |
17+
| `NativeObjectWrapperObject` | `ExternalComObject` | Address of the external COM object |
18+
19+
Global variables used:
20+
| Global Name | Type | Purpose |
21+
| --- | --- | --- |
22+
23+
Contracts used:
24+
| Contract Name |
25+
| --- |
26+
27+
28+
``` csharp
29+
public TargetPointer GetComWrappersIdentity(TargetPointer address)
30+
{
31+
return _target.ReadPointer(address + /* NativeObjectWrapperObject::ExternalComObject offset */);
32+
}
33+
```

src/coreclr/clrdatadescriptors.cmake

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
function(generate_data_descriptors)
44
set(options EXPORT_VISIBLE)
5-
set(oneValueArgs LIBRARY_NAME CONTRACT_FILE CONTRACT_NAME INTERFACE_TARGET)
5+
set(oneValueArgs LIBRARY_NAME CONTRACT_NAME INTERFACE_TARGET)
66
set(multiValueArgs "")
77
cmake_parse_arguments(DATA_DESCRIPTORS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGV})
88

@@ -53,15 +53,14 @@ function(generate_data_descriptors)
5353
set(CONTRACT_BASELINE_DIR "${CLR_REPO_ROOT_DIR}/docs/design/datacontracts/data")
5454
set(CONTRACT_DESCRIPTOR_INPUT "${DATA_DESCRIPTOR_SHARED_SOURCE_DIR}/contract-descriptor.c.in")
5555
set(CONTRACT_DESCRIPTOR_OUTPUT "${GENERATED_CDAC_DESCRIPTOR_DIR}/contract-descriptor.c")
56-
set(CONTRACT_FILE "${DATA_DESCRIPTORS_CONTRACT_FILE}")
5756

5857
# generate the contract descriptor by running cdac-build-tool
5958
# n.b. this just uses `dotnet` from the PATH. InitializeDotNetCli adds the appropriate directory
6059
add_custom_command(
6160
OUTPUT "${CONTRACT_DESCRIPTOR_OUTPUT}"
6261
VERBATIM
63-
COMMAND ${CLR_DOTNET_HOST_PATH} ${CDAC_BUILD_TOOL_BINARY_PATH} compose -i "${CONTRACT_DESCRIPTOR_INPUT}" -o "${CONTRACT_DESCRIPTOR_OUTPUT}" -b "${CONTRACT_BASELINE_DIR}" -c "${CONTRACT_FILE}" $<TARGET_OBJECTS:${INTERMEDIARY_LIBRARY}>
64-
DEPENDS ${INTERMEDIARY_LIBRARY} ${DATA_DESCRIPTORS_DEPENDENCIES} $<TARGET_OBJECTS:${INTERMEDIARY_LIBRARY}> "${CONTRACT_FILE}" "${CONTRACT_DESCRIPTOR_INPUT}"
62+
COMMAND ${CLR_DOTNET_HOST_PATH} ${CDAC_BUILD_TOOL_BINARY_PATH} compose -i "${CONTRACT_DESCRIPTOR_INPUT}" -o "${CONTRACT_DESCRIPTOR_OUTPUT}" -b "${CONTRACT_BASELINE_DIR}" $<TARGET_OBJECTS:${INTERMEDIARY_LIBRARY}>
63+
DEPENDS ${INTERMEDIARY_LIBRARY} ${DATA_DESCRIPTORS_DEPENDENCIES} $<TARGET_OBJECTS:${INTERMEDIARY_LIBRARY}> "${CONTRACT_DESCRIPTOR_INPUT}"
6564
USES_TERMINAL
6665
)
6766

src/coreclr/debug/datadescriptor-shared/datadescriptor.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,20 @@ struct GlobalStringSpec
4949
uint32_t StringValue;
5050
};
5151

52+
struct GlobalContractSpec
53+
{
54+
uint32_t Name;
55+
uint32_t Version;
56+
};
57+
5258
#define CONCAT(token1,token2) token1 ## token2
5359
#define CONCAT4(token1, token2, token3, token4) token1 ## token2 ## token3 ## token4
5460

5561
#define MAKE_TYPELEN_NAME(tyname) CONCAT(cdac_string_pool_typename__, tyname)
5662
#define MAKE_FIELDLEN_NAME(tyname,membername) CONCAT4(cdac_string_pool_membername__, tyname, __, membername)
5763
#define MAKE_FIELDTYPELEN_NAME(tyname,membername) CONCAT4(cdac_string_pool_membertypename__, tyname, __, membername)
5864
#define MAKE_GLOBALLEN_NAME(globalname) CONCAT(cdac_string_pool_globalname__, globalname)
65+
#define MAKE_GLOBALCONTRACTLEN_NAME(globalname) CONCAT(cdac_string_pool_globalcontractname__, globalname)
5966
#define MAKE_GLOBALTYPELEN_NAME(globalname) CONCAT(cdac_string_pool_globaltypename__, globalname)
6067
#define MAKE_GLOBALVALUELEN_NAME(globalname) CONCAT(cdac_string_pool_globalvalue__, globalname)
6168

@@ -78,6 +85,7 @@ struct CDacStringPoolSizes
7885
DECL_LEN(MAKE_GLOBALVALUELEN_NAME(name), sizeof(STRINGIFY(stringval)))
7986
#define CDAC_GLOBAL_POINTER(name,value) DECL_LEN(MAKE_GLOBALLEN_NAME(name), sizeof(#name))
8087
#define CDAC_GLOBAL_SUB_DESCRIPTOR(name,value) DECL_LEN(MAKE_GLOBALLEN_NAME(name), sizeof(#name))
88+
#define CDAC_GLOBAL_CONTRACT(name,value) DECL_LEN(MAKE_GLOBALCONTRACTLEN_NAME(name), sizeof(#name))
8189
#define CDAC_GLOBAL(name,tyname,value) DECL_LEN(MAKE_GLOBALLEN_NAME(name), sizeof(#name)) \
8290
DECL_LEN(MAKE_GLOBALTYPELEN_NAME(name), sizeof(#tyname))
8391
#include "wrappeddatadescriptor.inc"
@@ -90,6 +98,7 @@ struct CDacStringPoolSizes
9098
#define GET_FIELDTYPE_NAME(tyname,membername) offsetof(struct CDacStringPoolSizes, MAKE_FIELDTYPELEN_NAME(tyname,membername))
9199
#define GET_GLOBAL_NAME(globalname) offsetof(struct CDacStringPoolSizes, MAKE_GLOBALLEN_NAME(globalname))
92100
#define GET_GLOBALTYPE_NAME(globalname) offsetof(struct CDacStringPoolSizes, MAKE_GLOBALTYPELEN_NAME(globalname))
101+
#define GET_GLOBALCONTRACT_NAME(globalname) offsetof(struct CDacStringPoolSizes, MAKE_GLOBALCONTRACTLEN_NAME(globalname))
93102
#define GET_GLOBALSTRING_VALUE(globalname) offsetof(struct CDacStringPoolSizes, MAKE_GLOBALVALUELEN_NAME(globalname))
94103

95104
// count the types
@@ -148,6 +157,15 @@ enum
148157
#include "wrappeddatadescriptor.inc"
149158
};
150159

160+
// count the contracts
161+
enum
162+
{
163+
CDacBlobGlobalContractsCount =
164+
#define CDAC_GLOBALS_BEGIN() 0
165+
#define CDAC_GLOBAL_CONTRACT(name,value) + 1
166+
#include "wrappeddatadescriptor.inc"
167+
};
168+
151169

152170
#define MAKE_TYPEFIELDS_TYNAME(tyname) CONCAT(CDacFieldsPoolTypeStart__, tyname)
153171

@@ -226,6 +244,7 @@ struct BinaryBlobDataDescriptor
226244
uint32_t GlobalStringValuesStart;
227245

228246
uint32_t GlobalSubDescriptorsStart;
247+
uint32_t GlobalContractsStart;
229248
uint32_t NamesPoolStart;
230249

231250
uint32_t TypeCount;
@@ -235,6 +254,7 @@ struct BinaryBlobDataDescriptor
235254
uint32_t GlobalPointerValuesCount;
236255
uint32_t GlobalStringValuesCount;
237256
uint32_t GlobalSubDescriptorsCount;
257+
uint32_t GlobalContractsCount;
238258

239259
uint32_t NamesPoolCount;
240260

@@ -253,6 +273,7 @@ struct BinaryBlobDataDescriptor
253273
struct GlobalPointerSpec GlobalPointerValues[CDacBlobGlobalPointersCount + 1];
254274
struct GlobalStringSpec GlobalStringValues[CDacBlobGlobalStringsCount + 1];
255275
struct GlobalPointerSpec GlobalSubDescriptorValues[CDacBlobGlobalSubDescriptorsCount + 1];
276+
struct GlobalContractSpec GlobalContractValues[CDacBlobGlobalContractsCount + 1];
256277
uint8_t NamesPool[sizeof(struct CDacStringPoolSizes)];
257278
uint8_t EndMagic[4];
258279
};
@@ -279,13 +300,15 @@ struct MagicAndBlob BlobDataDescriptor = {
279300
/* .GlobalPointersStart = */ offsetof(struct BinaryBlobDataDescriptor, GlobalPointerValues),
280301
/* .GlobalStringValuesStart = */ offsetof(struct BinaryBlobDataDescriptor, GlobalStringValues),
281302
/* .GlobalSubDescriptorsStart = */ offsetof(struct BinaryBlobDataDescriptor, GlobalSubDescriptorValues),
303+
/* .GlobalContractsStart = */ offsetof(struct BinaryBlobDataDescriptor, GlobalContractValues),
282304
/* .NamesPoolStart = */ offsetof(struct BinaryBlobDataDescriptor, NamesPool),
283305
/* .TypeCount = */ CDacBlobTypesCount,
284306
/* .FieldsPoolCount = */ CDacBlobFieldsPoolCount,
285307
/* .GlobalLiteralValuesCount = */ CDacBlobGlobalLiteralsCount,
286308
/* .GlobalPointerValuesCount = */ CDacBlobGlobalPointersCount,
287309
/* .GlobalStringValuesCount = */ CDacBlobGlobalStringsCount,
288310
/* .GlobalSubDescriptorsCount = */ CDacBlobGlobalSubDescriptorsCount,
311+
/* .GlobalContractsCount = */ CDacBlobGlobalContractsCount,
289312
/* .NamesPoolCount = */ sizeof(struct CDacStringPoolSizes),
290313
/* .TypeSpecSize = */ sizeof(struct TypeSpec),
291314
/* .FieldSpecSize = */ sizeof(struct FieldSpec),
@@ -337,13 +360,19 @@ struct MagicAndBlob BlobDataDescriptor = {
337360
#include "wrappeddatadescriptor.inc"
338361
},
339362

363+
/* .GlobalContractValues = */ {
364+
#define CDAC_GLOBAL_CONTRACT(name,value) { /* .Name = */ GET_GLOBALCONTRACT_NAME(name), /* .Version = */ value },
365+
#include "wrappeddatadescriptor.inc"
366+
},
367+
340368
/* .NamesPool = */ ("\0" // starts with a nul
341369
#define CDAC_BASELINE(name) name "\0"
342370
#define CDAC_TYPE_BEGIN(name) #name "\0"
343371
#define CDAC_TYPE_FIELD(tyname,membertyname,membername,offset) #membername "\0" #membertyname "\0"
344372
#define CDAC_GLOBAL_STRING(name,value) #name "\0" STRINGIFY(value) "\0"
345373
#define CDAC_GLOBAL_POINTER(name,value) #name "\0"
346374
#define CDAC_GLOBAL_SUB_DESCRIPTOR(name,value) #name "\0"
375+
#define CDAC_GLOBAL_CONTRACT(name,value) #name "\0"
347376
#define CDAC_GLOBAL(name,tyname,value) #name "\0" #tyname "\0"
348377
#include "wrappeddatadescriptor.inc"
349378
),

src/coreclr/debug/datadescriptor-shared/wrappeddatadescriptor.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
#ifndef CDAC_GLOBAL_SUB_DESCRIPTOR
4444
#define CDAC_GLOBAL_SUB_DESCRIPTOR(globalname,addr)
4545
#endif
46+
#ifndef CDAC_GLOBAL_CONTRACT
47+
#define CDAC_GLOBAL_CONTRACT(name,value)
48+
#endif
4649
#ifndef CDAC_GLOBALS_END
4750
#define CDAC_GLOBALS_END()
4851
#endif
@@ -62,4 +65,5 @@
6265
#undef CDAC_GLOBAL_POINTER
6366
#undef CDAC_GLOBAL_STRING
6467
#undef CDAC_GLOBAL_SUB_DESCRIPTOR
68+
#undef CDAC_GLOBAL_CONTRACT
6569
#undef CDAC_GLOBALS_END

src/coreclr/gc/datadescriptor/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ add_dependencies(gc_dll_wks_descriptor_interface eventing_headers)
1313
generate_data_descriptors(
1414
LIBRARY_NAME gc_dll_wks_descriptor
1515
CONTRACT_NAME "GCContractDescriptorWKS"
16-
CONTRACT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/contracts.jsonc"
1716
INTERFACE_TARGET gc_dll_wks_descriptor_interface)
1817

1918
if (FEATURE_SVR_GC)
@@ -25,7 +24,6 @@ if (FEATURE_SVR_GC)
2524
generate_data_descriptors(
2625
LIBRARY_NAME gc_dll_svr_descriptor
2726
CONTRACT_NAME "GCContractDescriptorSVR"
28-
CONTRACT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/contracts.jsonc"
2927
INTERFACE_TARGET gc_dll_svr_descriptor_interface)
3028
endif()
3129

@@ -38,7 +36,6 @@ if(BUILD_EXP_GC)
3836
generate_data_descriptors(
3937
LIBRARY_NAME gcexp_dll_wks_descriptor
4038
CONTRACT_NAME "GCContractDescriptorWKS"
41-
CONTRACT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/contracts.jsonc"
4239
INTERFACE_TARGET gcexp_dll_wks_descriptor_interface)
4340

4441
if (FEATURE_SVR_GC)
@@ -51,7 +48,6 @@ if(BUILD_EXP_GC)
5148
generate_data_descriptors(
5249
LIBRARY_NAME gcexp_dll_svr_descriptor
5350
CONTRACT_NAME "GCContractDescriptorSVR"
54-
CONTRACT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/contracts.jsonc"
5551
INTERFACE_TARGET gcexp_dll_svr_descriptor_interface)
5652
endif()
5753
endif()

src/coreclr/gc/datadescriptor/contracts.jsonc

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/coreclr/gc/datadescriptor/datadescriptor.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,6 @@ CDAC_GLOBAL_POINTER(Heaps, cdac_data<GC_NAMESPACE::gc_heap>::Heaps)
100100
CDAC_GLOBAL_POINTER(CurrentGCState, cdac_data<GC_NAMESPACE::gc_heap>::CurrentGCState)
101101
#endif // BACKGROUND_GC
102102

103+
CDAC_GLOBAL_CONTRACT(GC, 1)
104+
103105
CDAC_GLOBALS_END()

src/coreclr/tools/cdac-build-tool/ComposeCommand.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ internal sealed class ComposeCommand : Command
1212
{
1313
private readonly Argument<string[]> inputFiles = new("INPUT [INPUTS...]") { Arity = ArgumentArity.OneOrMore, Description = "One or more input files" };
1414
private readonly Option<string> outputFile = new("-o") { Arity = ArgumentArity.ExactlyOne, HelpName = "OUTPUT", Required = true, Description = "Output file" };
15-
private readonly Option<string[]> contractFile = new("-c") { Arity = ArgumentArity.ZeroOrMore, HelpName = "CONTRACT", Description = "Contract file (may be specified multiple times)" };
1615
private readonly Option<string> baselinePath = new("-b", "--baseline") { Arity = ArgumentArity.ExactlyOne, HelpName = "BASELINEPATH", Description = "Directory containing the baseline contracts"};
1716
private readonly Option<string> templateFile = new("-i", "--input-template") { Arity = ArgumentArity.ExactlyOne, HelpName = "TEMPLATE", Description = "Contract descriptor template to be filled in" };
1817
private readonly Option<bool> _verboseOption;
@@ -21,7 +20,6 @@ public ComposeCommand(Option<bool> verboseOption) : base("compose")
2120
_verboseOption = verboseOption;
2221
Add(inputFiles);
2322
Add(outputFile);
24-
Add(contractFile);
2523
Add(baselinePath);
2624
Add(templateFile);
2725
SetAction(Run);
@@ -65,7 +63,6 @@ private async Task<int> Run(ParseResult parse, CancellationToken token = default
6563
Console.Error.WriteLine($"Template file {templateFilePath} does not exist");
6664
return 1;
6765
}
68-
var contracts = parse.GetValue(contractFile);
6966
var verbose = parse.GetValue(_verboseOption);
7067
var builder = new DataDescriptorModel.Builder(baselinesDir);
7168
var scraper = new ObjectFileScraper(verbose, builder);
@@ -78,18 +75,6 @@ private async Task<int> Run(ParseResult parse, CancellationToken token = default
7875
return 1;
7976
}
8077
}
81-
if (contracts != null)
82-
{
83-
var contractReader = new ContractReader(builder);
84-
foreach (var contract in contracts)
85-
{
86-
if (!await contractReader.ParseContracts(contract, token).ConfigureAwait(false))
87-
{
88-
Console.Error.WriteLine($"could not parse contracts in {contract}");
89-
return 1;
90-
}
91-
}
92-
}
9378

9479
var model = builder.Build();
9580
if (verbose)

src/coreclr/tools/cdac-build-tool/ContractReader.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/coreclr/tools/cdac-build-tool/DataDescriptorModel.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,6 @@ public void AddOrUpdateContract(string name, int version)
165165
contract.Version = version;
166166
}
167167

168-
public void AddOrupdateContracts(IEnumerable<KeyValuePair<string, int>> contracts)
169-
{
170-
foreach (var (name, version) in contracts)
171-
{
172-
AddOrUpdateContract(name, version);
173-
}
174-
}
175-
176168
public void SetBaseline(string baseline)
177169
{
178170
if (_baseline != string.Empty && _baseline != baseline)

0 commit comments

Comments
 (0)