Skip to content

Commit 3029f32

Browse files
authored
Merge branch 'main' into mldsa-openssl
2 parents c82ea47 + 66b3606 commit 3029f32

File tree

197 files changed

+1391
-25137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+1391
-25137
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Contract RuntimeInfo
2+
3+
This contract encapsulates support for fetching information about the target runtime.
4+
5+
## APIs of contract
6+
7+
```csharp
8+
public enum RuntimeInfoArchitecture : uint
9+
{
10+
Unknown = 0,
11+
X86,
12+
Arm32,
13+
X64,
14+
Arm64,
15+
LoongArch64,
16+
RISCV,
17+
}
18+
19+
public enum RuntimeInfoOperatingSystem : uint
20+
{
21+
Unknown = 0,
22+
Win,
23+
Unix,
24+
}
25+
```
26+
27+
```csharp
28+
// Gets the targets architecture. If this information is not available returns Unknown.
29+
RuntimeInfoArchitecture GetTargetArchitecture();
30+
31+
// Gets the targets operating system. If this information is not available returns Unknown.
32+
RuntimeInfoOperatingSystem GetTargetOperatingSystem();
33+
```
34+
35+
## Version 1
36+
37+
Global variables used:
38+
| Global Name | Type | Purpose |
39+
| --- | --- | --- |
40+
| Architecture | string | Target architecture |
41+
| OperatingSystem | string | Target operating system |
42+
43+
The contract implementation simply returns the contract descriptor global values parsed as the respective enum case-insensitively. If these globals are not available, the contract returns Unknown.

docs/design/datacontracts/contract-descriptor.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ a JSON integer constant.
8383
"globals":
8484
{
8585
"FEATURE_COMINTEROP": 0,
86-
"s_pThreadStore": [ 0 ] // indirect from pointer data offset 0
86+
"s_pThreadStore": [ 0 ], // indirect from pointer data offset 0
87+
"RuntimeID": "win-x64" // string value
8788
},
8889
"contracts": {"Thread": 1, "GCHandle": 1, "ThreadStore": 1}
8990
}

docs/design/datacontracts/data_descriptor.md

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,33 +212,69 @@ The global values will be in an array, with each value described by a dictionary
212212

213213
* `"name": "global value name"` the name of the global value
214214
* `"type": "type name"` the type of the global value
215-
* optional `"value": VALUE | [ int ] | "unknown"` the value of the global value, or an offset in an auxiliary array containing the value or "unknown".
215+
* optional `"value": <global_value>` where `<global_value>` is defined below
216+
217+
218+
Numeric constants must be within the range of the type of the global value. If a constant is out of range, behavior is undefined.
216219

217-
The `VALUE` may be a JSON numeric constant integer or a string containing a signed or unsigned
218-
decimal or hex (with prefix `0x` or `0X`) integer constant. The constant must be within the range
219-
of the type of the global value.
220220

221221
**Compact format**:
222222

223223
The global values will be in a dictionary, with each key being the name of a global and the values being one of:
224224

225-
* `[VALUE | [int], "type name"]` the type and value of a global
226-
* `VALUE | [int]` just the value of a global
225+
* `[<global_value>, "type name"]` the type and value of a global
226+
* `<global_value>` just the value of a global
227227

228-
As in the regular format, `VALUE` is a numeric constant or a string containing an integer constant.
228+
Where `<global_value>` is defined as below.
229+
230+
Numeric constants must be within the range of the type of the global value. If a constant is out of range, behavior is undefined.
229231

230232
Note that a two element array is unambiguously "type and value", whereas a one-element array is
231233
unambiguously "indirect value".
232234

235+
233236
**Both formats**
234237

238+
#### Specification Appendix
239+
240+
```
241+
<global_value> ::= <value> | <pointer_table_index>
242+
<pointer_table_index> ::= [ <number_value> ]
243+
<value> ::= <json_string> | <number_value>
244+
<number_value> ::= <json_number> | <decimal_string> | <hex_string>
245+
246+
<json_string> is any JSON string element
247+
<json_number> is any JSON number element
248+
<hex_string> is a <json_string> which can be parsed as a hexadecimal number prefixed with "0x" or "0X"
249+
<decimal_string> is a <json_string> which can be parsed as a decimal number.
250+
```
251+
252+
#### Parsing Rules
253+
`<json_number>` is parsed as a numeric value.
254+
`<hex_string>` and `<decimal_string>` can be parsed as either a string or numeric value.
255+
`<json_string>` (that does not form a valid hex or decimal number) is parsed as a string.
256+
257+
Example using compact format:
258+
```json
259+
{
260+
"int" : 1234, // Can only be parsed as numeric constant 1234
261+
"stringyInt" : "1234", // Can be parsed as 1234 or "1234"
262+
"stringyHex" : "0x1234", // Can be parsed as 4660 (0x1234 in decimal) or "0x1234"
263+
"stringValue" : "Hello World" // Can only be parsed as "Hello World"
264+
}
265+
```
266+
267+
#### Typing
268+
235269
For pointer and nuint globals, the value may be assumed to fit in a 64-bit unsigned integer. For
236270
nint globals, the value may be assumed to fit in a 64-bit signed integer.
237271

238272
Note that the logical descriptor does not contain "unknown" values: it is expected that the
239273
in-memory data descriptor will augment the baseline with a known offset for all fields in the
240274
baseline.
241275

276+
#### Indirect Types
277+
242278
If the value is given as a single-element array `[ int ]` then the value is stored in an auxiliary
243279
array that is part of the data contract descriptor. Only in-memory data descriptors may have
244280
indirect values; baseline data descriptors may not have indirect values.
@@ -251,7 +287,6 @@ The indirection array is not part of the data descriptor spec. It is part of th
251287
descriptor](./contract_descriptor.md#Contract_descriptor).
252288

253289

254-
255290
## Example
256291

257292
This is an example of a baseline descriptor for a 64-bit architecture. Suppose it has the name `"example-64"`
@@ -288,7 +323,7 @@ The baseline is given in the "regular" format.
288323
],
289324
"globals": [
290325
{ "name": "FEATURE_EH_FUNCLETS", "type": "uint8", "value": "0" }, // baseline defaults value to 0
291-
{ "name": "FEATURE_COMINTEROP", "type", "uint8", "value": "1"},
326+
{ "name": "FEATURE_COMINTEROP", "type": "uint8", "value": "1"},
292327
{ "name": "s_pThreadStore", "type": "pointer" } // no baseline value
293328
]
294329
}
@@ -308,7 +343,8 @@ The following is an example of an in-memory descriptor that references the above
308343
"globals":
309344
{
310345
"FEATURE_COMINTEROP": 0,
311-
"s_pThreadStore": [ 0 ] // indirect from aux data offset 0
346+
"s_pThreadStore": [ 0 ], // indirect from aux data offset 0
347+
"RuntimeID": "windows-x64"
312348
}
313349
}
314350
```
@@ -332,6 +368,7 @@ And the globals will be:
332368
| FEATURE_COMINTEROP | uint8 | 0 |
333369
| FEATURE_EH_FUNCLETS | uint8 | 0 |
334370
| s_pThreadStore | pointer | 0x0100ffe0 |
371+
| RuntimeID | string |"windows-x64"|
335372

336373
The `FEATURE_EH_FUNCLETS` global's value comes from the baseline - not the in-memory data
337374
descriptor. By contrast, `FEATURE_COMINTEROP` comes from the in-memory data descriptor - with the

src/coreclr/debug/daccess/cdac.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ namespace
5252

5353
return S_OK;
5454
}
55-
56-
int GetPlatform(uint32_t* platform, void* context)
57-
{
58-
ICorDebugDataTarget* target = reinterpret_cast<ICorDebugDataTarget*>(context);
59-
HRESULT hr = target->GetPlatform((CorDebugPlatform*)platform);
60-
if (FAILED(hr))
61-
return hr;
62-
63-
return S_OK;
64-
}
6555
}
6656

6757
CDAC CDAC::Create(uint64_t descriptorAddr, ICorDebugDataTarget* target, IUnknown* legacyImpl)
@@ -74,7 +64,7 @@ CDAC CDAC::Create(uint64_t descriptorAddr, ICorDebugDataTarget* target, IUnknown
7464
_ASSERTE(init != nullptr);
7565

7666
intptr_t handle;
77-
if (init(descriptorAddr, &ReadFromTargetCallback, &ReadThreadContext, &GetPlatform, target, &handle) != 0)
67+
if (init(descriptorAddr, &ReadFromTargetCallback, &ReadThreadContext, target, &handle) != 0)
7868
{
7969
::FreeLibrary(cdacLib);
8070
return {};

src/coreclr/debug/runtimeinfo/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ install_clr(TARGETS runtimeinfo DESTINATIONS lib COMPONENT runtime)
4242

4343
# cDAC contract descriptor
4444

45+
if("${CLR_DOTNET_RID}" STREQUAL "")
46+
message(FATAL_ERROR "CLR_DOTNET_RID is not set. Please ensure it is being set to the portable RID of the target platform by runtime.proj.")
47+
endif()
48+
configure_file(configure.h.in ${CMAKE_CURRENT_BINARY_DIR}/configure.h)
49+
4550
if (NOT CDAC_BUILD_TOOL_BINARY_PATH)
4651
# if CDAC_BUILD_TOOL_BINARY_PATH is unspecified (for example for a build without a .NET SDK or msbuild),
4752
# link a stub contract descriptor into the runtime
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef RUNTIME_INFO_CONFIGURE_H_INCLUDED
2+
#define RUNTIME_INFO_CONFIGURE_H_INCLUDED
3+
4+
#define RID_STRING @CLR_DOTNET_RID@
5+
6+
#endif // RUNTIME_INFO_CONFIGURE_H_INCLUDED

src/coreclr/debug/runtimeinfo/contracts.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"PlatformMetadata": 1,
2020
"PrecodeStubs": 2,
2121
"ReJIT": 1,
22+
"RuntimeInfo": 1,
2223
"RuntimeTypeSystem": 1,
2324
"StackWalk": 1,
2425
"StressLog": 2,

src/coreclr/debug/runtimeinfo/datadescriptor.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "methodtable.h"
1414
#include "threads.h"
1515

16+
#include "configure.h"
17+
1618
#include "../debug/ee/debugger.h"
1719

1820
#ifdef HAVE_GCCOVER
@@ -51,6 +53,12 @@ struct GlobalPointerSpec
5153
uint32_t PointerDataIndex;
5254
};
5355

56+
struct GlobalStringSpec
57+
{
58+
uint32_t Name;
59+
uint32_t StringValue;
60+
};
61+
5462
#define CONCAT(token1,token2) token1 ## token2
5563
#define CONCAT4(token1, token2, token3, token4) token1 ## token2 ## token3 ## token4
5664

@@ -59,6 +67,10 @@ struct GlobalPointerSpec
5967
#define MAKE_FIELDTYPELEN_NAME(tyname,membername) CONCAT4(cdac_string_pool_membertypename__, tyname, __, membername)
6068
#define MAKE_GLOBALLEN_NAME(globalname) CONCAT(cdac_string_pool_globalname__, globalname)
6169
#define MAKE_GLOBALTYPELEN_NAME(globalname) CONCAT(cdac_string_pool_globaltypename__, globalname)
70+
#define MAKE_GLOBALVALUELEN_NAME(globalname) CONCAT(cdac_string_pool_globalvalue__, globalname)
71+
72+
// used to stringify the result of a macros expansion
73+
#define STRINGIFY(x) #x
6274

6375
// define a struct where the size of each field is the length of some string. we will use offsetof to get
6476
// the offset of each struct element, which will be equal to the offset of the beginning of that string in the
@@ -71,6 +83,8 @@ struct CDacStringPoolSizes
7183
#define CDAC_TYPE_BEGIN(name) DECL_LEN(MAKE_TYPELEN_NAME(name), sizeof(#name))
7284
#define CDAC_TYPE_FIELD(tyname,membertyname,membername,offset) DECL_LEN(MAKE_FIELDLEN_NAME(tyname,membername), sizeof(#membername)) \
7385
DECL_LEN(MAKE_FIELDTYPELEN_NAME(tyname,membername), sizeof(#membertyname))
86+
#define CDAC_GLOBAL_STRING(name, stringval) DECL_LEN(MAKE_GLOBALLEN_NAME(name), sizeof(#name)) \
87+
DECL_LEN(MAKE_GLOBALVALUELEN_NAME(name), sizeof(STRINGIFY(stringval)))
7488
#define CDAC_GLOBAL_POINTER(name,value) DECL_LEN(MAKE_GLOBALLEN_NAME(name), sizeof(#name))
7589
#define CDAC_GLOBAL(name,tyname,value) DECL_LEN(MAKE_GLOBALLEN_NAME(name), sizeof(#name)) \
7690
DECL_LEN(MAKE_GLOBALTYPELEN_NAME(name), sizeof(#tyname))
@@ -84,6 +98,7 @@ struct CDacStringPoolSizes
8498
#define GET_FIELDTYPE_NAME(tyname,membername) offsetof(struct CDacStringPoolSizes, MAKE_FIELDTYPELEN_NAME(tyname,membername))
8599
#define GET_GLOBAL_NAME(globalname) offsetof(struct CDacStringPoolSizes, MAKE_GLOBALLEN_NAME(globalname))
86100
#define GET_GLOBALTYPE_NAME(globalname) offsetof(struct CDacStringPoolSizes, MAKE_GLOBALTYPELEN_NAME(globalname))
101+
#define GET_GLOBALSTRING_VALUE(globalname) offsetof(struct CDacStringPoolSizes, MAKE_GLOBALVALUELEN_NAME(globalname))
87102

88103
// count the types
89104
enum
@@ -123,6 +138,15 @@ enum
123138
#include "datadescriptor.h"
124139
};
125140

141+
// count the global strings
142+
enum
143+
{
144+
CDacBlobGlobalStringsCount =
145+
#define CDAC_GLOBALS_BEGIN() 0
146+
#define CDAC_GLOBAL_STRING(name,value) + 1
147+
#include "datadescriptor.h"
148+
};
149+
126150

127151
#define MAKE_TYPEFIELDS_TYNAME(tyname) CONCAT(CDacFieldsPoolTypeStart__, tyname)
128152

@@ -197,27 +221,31 @@ struct BinaryBlobDataDescriptor
197221
uint32_t GlobalLiteralValuesStart;
198222

199223
uint32_t GlobalPointersStart;
224+
uint32_t GlobalStringValuesStart;
200225
uint32_t NamesPoolStart;
201226

202227
uint32_t TypeCount;
203228
uint32_t FieldsPoolCount;
204229

205230
uint32_t GlobalLiteralValuesCount;
206231
uint32_t GlobalPointerValuesCount;
232+
uint32_t GlobalStringValuesCount;
207233

208234
uint32_t NamesPoolCount;
209235

210236
uint8_t TypeSpecSize;
211237
uint8_t FieldSpecSize;
212238
uint8_t GlobalLiteralSpecSize;
213239
uint8_t GlobalPointerSpecSize;
240+
uint8_t GlobalStringSpecSize;
214241
} Directory;
215242
uint32_t PlatformFlags;
216243
uint32_t BaselineName;
217244
struct TypeSpec Types[CDacBlobTypesCount];
218245
struct FieldSpec FieldsPool[CDacBlobFieldsPoolCount];
219246
struct GlobalLiteralSpec GlobalLiteralValues[CDacBlobGlobalLiteralsCount];
220247
struct GlobalPointerSpec GlobalPointerValues[CDacBlobGlobalPointersCount];
248+
struct GlobalStringSpec GlobalStringValues[CDacBlobGlobalStringsCount];
221249
uint8_t NamesPool[sizeof(struct CDacStringPoolSizes)];
222250
uint8_t EndMagic[4];
223251
};
@@ -242,16 +270,19 @@ struct MagicAndBlob BlobDataDescriptor = {
242270
/* .FieldsPoolStart = */ offsetof(struct BinaryBlobDataDescriptor, FieldsPool),
243271
/* .GlobalLiteralValuesStart = */ offsetof(struct BinaryBlobDataDescriptor, GlobalLiteralValues),
244272
/* .GlobalPointersStart = */ offsetof(struct BinaryBlobDataDescriptor, GlobalPointerValues),
273+
/* .GlobalStringValuesStart = */ offsetof(struct BinaryBlobDataDescriptor, GlobalStringValues),
245274
/* .NamesPoolStart = */ offsetof(struct BinaryBlobDataDescriptor, NamesPool),
246275
/* .TypeCount = */ CDacBlobTypesCount,
247276
/* .FieldsPoolCount = */ CDacBlobFieldsPoolCount,
248277
/* .GlobalLiteralValuesCount = */ CDacBlobGlobalLiteralsCount,
249278
/* .GlobalPointerValuesCount = */ CDacBlobGlobalPointersCount,
279+
/* .GlobalStringValuesCount = */ CDacBlobGlobalStringsCount,
250280
/* .NamesPoolCount = */ sizeof(struct CDacStringPoolSizes),
251281
/* .TypeSpecSize = */ sizeof(struct TypeSpec),
252282
/* .FieldSpecSize = */ sizeof(struct FieldSpec),
253283
/* .GlobalLiteralSpecSize = */ sizeof(struct GlobalLiteralSpec),
254284
/* .GlobalPointerSpecSize = */ sizeof(struct GlobalPointerSpec),
285+
/* .GlobalStringSpecSize = */ sizeof(struct GlobalStringSpec)
255286
},
256287
/* .PlatformFlags = */ (sizeof(void*) == 4 ? 0x02 : 0) | 0x01,
257288
/* .BaselineName = */ offsetof(struct CDacStringPoolSizes, cdac_string_pool_baseline_),
@@ -287,10 +318,16 @@ struct MagicAndBlob BlobDataDescriptor = {
287318
#include "datadescriptor.h"
288319
},
289320

321+
/* .GlobalStringValues = */ {
322+
#define CDAC_GLOBAL_STRING(name,value) { /* .Name = */ GET_GLOBAL_NAME(name), /* .Value = */ GET_GLOBALSTRING_VALUE(name) },
323+
#include "datadescriptor.h"
324+
},
325+
290326
/* .NamesPool = */ ("\0" // starts with a nul
291327
#define CDAC_BASELINE(name) name "\0"
292328
#define CDAC_TYPE_BEGIN(name) #name "\0"
293329
#define CDAC_TYPE_FIELD(tyname,membertyname,membername,offset) #membername "\0" #membertyname "\0"
330+
#define CDAC_GLOBAL_STRING(name,value) #name "\0" STRINGIFY(value) "\0"
294331
#define CDAC_GLOBAL_POINTER(name,value) #name "\0"
295332
#define CDAC_GLOBAL(name,tyname,value) #name "\0" #tyname "\0"
296333
#include "datadescriptor.h"

0 commit comments

Comments
 (0)