-
Notifications
You must be signed in to change notification settings - Fork 5k
[cdac] Start Loader contract and implement ISOSDacInterface::GetModuleData in cDAC #104257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
31bac53
Add Loader contract
elinor-fung d531f56
Make DAC call cDAC for GetModuleData
elinor-fung 1191ae8
Add functions to Loader contract to handle GetModuleData - still need…
elinor-fung e47c748
Handle getting metadata address
elinor-fung cb3db4e
Remove unnecessary data field
elinor-fung 9b017ae
Update doc
elinor-fung cc312a0
Cache base address on Module
elinor-fung 8be71bb
Get base address from Module, remove PEImage and PEImageLayout from d…
elinor-fung 0186012
Store Reflection.Emit bit on Module
elinor-fung 0f507f9
Check Module flags for Reflection.Emit, remove PEAssembly from data d…
elinor-fung 0c9dc67
Remove Module::PEAssembly from descriptor
elinor-fung 3f72d3d
Use struct for madule lookup tables
elinor-fung 39c50cd
Rename PEOffsets
elinor-fung 32cbeaa
Merge remote-tracking branch 'upstream/main' into cdac-module-data
elinor-fung ead9a6f
Apply suggestions from code review
elinor-fung 817da02
Update src/native/managed/cdacreader/src/Contracts/Loader_1.cs
elinor-fung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Contract Loader | ||
|
||
This contract is for getting information about loaded modules and assemblies | ||
|
||
## APIs of contract | ||
|
||
``` csharp | ||
readonly struct ModuleHandle | ||
{ | ||
// Opaque handle - no public members | ||
|
||
internal TargetPointer Address; | ||
} | ||
|
||
[Flags] | ||
enum ModuleFlags | ||
{ | ||
EditAndContinue = 0x00000008, // Edit and Continue is enabled for this module | ||
ReflectionEmit = 0x00000040, // Reflection.Emit was used to create this module | ||
} | ||
|
||
record struct ModuleLookupTables( | ||
TargetPointer FieldDefToDesc, | ||
TargetPointer ManifestModuleReferences, | ||
TargetPointer MemberRefToDesc, | ||
TargetPointer MethodDefToDesc, | ||
TargetPointer TypeDefToMethodTable, | ||
TargetPointer TypeRefToMethodTable); | ||
``` | ||
|
||
``` csharp | ||
ModuleHandle GetModuleHandle(TargetPointer); | ||
TargetPointer GetAssembly(ModuleHandle handle); | ||
ModuleFlags GetFlags(ModuleHandle handle); | ||
TargetPointer GetLoaderAllocator(ModuleHandle handle); | ||
TargetPointer GetThunkHeap(ModuleHandle handle); | ||
TargetPointer GetILBase(ModuleHandle handle); | ||
TargetPointer GetMetadataAddress(ModuleHandle handle, out ulong size); | ||
ModuleLookupTables GetLookupTables(ModuleHandle handle); | ||
``` | ||
|
||
## Version 1 | ||
|
||
Data descriptors used: | ||
- `Module` | ||
|
||
``` csharp | ||
ModuleHandle GetModuleHandle(TargetPointer modulePointer) | ||
{ | ||
return new ModuleHandle(modulePointer); | ||
} | ||
|
||
TargetPointer GetAssembly(ModuleHandle handle) | ||
{ | ||
return target.ReadPointer(handle.Address + /* Module::Assrembly offset */); | ||
} | ||
|
||
ModuleFlags GetFlags(ModuleHandle handle) | ||
{ | ||
return target.Read<uint>(handle.Address + /* Module::Flags offset */); | ||
} | ||
|
||
TargetPointer GetLoaderAllocator(ModuleHandle handle) | ||
{ | ||
return target.ReadPointer(handle.Address + /* Module::LoaderAllocator offset */); | ||
} | ||
|
||
TargetPointer GetThunkHeap(ModuleHandle handle) | ||
{ | ||
return target.ReadPointer(handle.Address + /* Module::ThunkHeap offset */); | ||
} | ||
|
||
TargetPointer GetILBase(ModuleHandle handle) | ||
{ | ||
return target.ReadPointer(handle.Address + /* Module::Base offset */); | ||
} | ||
|
||
TargetPointer GetMetadataAddress(ModuleHandle handle, out ulong size) | ||
{ | ||
TargetPointer baseAddress = GetILBase(handle); | ||
if (baseAddress == TargetPointer.Null) | ||
{ | ||
size = 0; | ||
return TargetPointer.Null; | ||
} | ||
|
||
// Read CLR header per https://learn.microsoft.com/windows/win32/debug/pe-format | ||
ulong clrHeaderRVA = ... | ||
|
||
// Read Metadata per ECMA-335 II.25.3.3 CLI Header | ||
ulong metadataDirectoryAddress = baseAddress + clrHeaderRva + /* offset to Metadata */ | ||
int rva = target.Read<int>(metadataDirectoryAddress); | ||
size = target.Read<int>(metadataDirectoryAddress + sizeof(int)); | ||
return baseAddress + rva; | ||
} | ||
|
||
ModuleLookupTables GetLookupTables(ModuleHandle handle) | ||
{ | ||
return new ModuleLookupTables( | ||
FieldDefToDescMap: target.ReadPointer(handle.Address + /* Module::FieldDefToDescMap */), | ||
ManifestModuleReferencesMap: target.ReadPointer(handle.Address + /* Module::ManifestModuleReferencesMap */), | ||
MemberRefToDescMap: target.ReadPointer(handle.Address + /* Module::MemberRefToDescMap */), | ||
MethodDefToDescMap: target.ReadPointer(handle.Address + /* Module::MethodDefToDescMap */), | ||
TypeDefToMethodTableMap: target.ReadPointer(handle.Address + /* Module::TypeDefToMethodTableMap */), | ||
TypeRefToMethodTableMap: target.ReadPointer(handle.Address + /* Module::TypeRefToMethodTableMap */)); | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Diagnostics.DataContractReader.Contracts; | ||
|
||
internal readonly struct ModuleHandle | ||
{ | ||
internal ModuleHandle(TargetPointer address) | ||
{ | ||
Address = address; | ||
} | ||
|
||
internal TargetPointer Address { get; } | ||
} | ||
|
||
[Flags] | ||
internal enum ModuleFlags | ||
{ | ||
EditAndContinue = 0x00000008, // Edit and Continue is enabled for this module | ||
ReflectionEmit = 0x00000040, // Reflection.Emit was used to create this module | ||
} | ||
|
||
internal record struct ModuleLookupTables( | ||
TargetPointer FieldDefToDesc, | ||
TargetPointer ManifestModuleReferences, | ||
TargetPointer MemberRefToDesc, | ||
TargetPointer MethodDefToDesc, | ||
TargetPointer TypeDefToMethodTable, | ||
TargetPointer TypeRefToMethodTable); | ||
|
||
internal interface ILoader : IContract | ||
{ | ||
static string IContract.Name => nameof(Loader); | ||
static IContract IContract.Create(Target target, int version) | ||
{ | ||
return version switch | ||
{ | ||
1 => new Loader_1(target), | ||
_ => default(Loader), | ||
}; | ||
} | ||
|
||
public virtual ModuleHandle GetModuleHandle(TargetPointer modulePointer) => throw new NotImplementedException(); | ||
|
||
public virtual TargetPointer GetAssembly(ModuleHandle handle) => throw new NotImplementedException(); | ||
public virtual ModuleFlags GetFlags(ModuleHandle handle) => throw new NotImplementedException(); | ||
public virtual TargetPointer GetLoaderAllocator(ModuleHandle handle) => throw new NotImplementedException(); | ||
public virtual TargetPointer GetThunkHeap(ModuleHandle handle) => throw new NotImplementedException(); | ||
|
||
public virtual TargetPointer GetILBase(ModuleHandle handle) => throw new NotImplementedException(); | ||
public virtual TargetPointer GetMetadataAddress(ModuleHandle handle, out ulong size) => throw new NotImplementedException(); | ||
|
||
public virtual ModuleLookupTables GetLookupTables(ModuleHandle handle) => throw new NotImplementedException(); | ||
} | ||
|
||
internal readonly struct Loader : ILoader | ||
{ | ||
// Everything throws NotImplementedException | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.