-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[cdac] Start Loader contract and implement ISOSDacInterface::GetModuleData in cDAC #104257
Merged
Merged
Changes from 8 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 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 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,118 @@ | ||
# 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 | ||
} | ||
|
||
enum ModuleLookupTable | ||
{ | ||
FieldDefToDesc, | ||
ManifestModuleReferences, | ||
MemberRefToDesc, | ||
MethodDefToDesc, | ||
TypeDefToMethodTable, | ||
TypeRefToMethodTable, | ||
} | ||
lambdageek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
``` csharp | ||
ModuleHandle GetModuleHandle(TargetPointer); | ||
TargetPointer GetAssembly(ModuleHandle handle); | ||
ModuleFlags GetFlags(ModuleHandle handle); | ||
TargetPointer GetLoaderAllocator(ModuleHandle handle); | ||
TargetPointer GetThunkHeap(ModuleHandle handle); | ||
bool IsReflectionEmit(ModuleHandle handle); | ||
TargetPointer GetILBase(ModuleHandle handle); | ||
TargetPointer GetMetadataAddress(ModuleHandle handle, out ulong size); | ||
IDictionary<ModuleLookupTable, TargetPointer> GetLookupTables(ModuleHandle handle); | ||
lambdageek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
## Version 1 | ||
|
||
Data descriptors used: | ||
- `Module` | ||
- `PEAssembly` | ||
|
||
``` 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 */); | ||
} | ||
|
||
bool IsReflectionEmit(ModuleHandle handle) | ||
{ | ||
TargetPointer peAssembly = target.ReadPointer(handle.Address + /* Module::PEAssembly offset */); | ||
TargetPointer peImage = target.ReadPointer(peAssembly + /* PEAssembly::PEImage offset */); | ||
elinor-fung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return peImage == TargetPointer.Null; | ||
} | ||
|
||
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; | ||
} | ||
|
||
IDictionary<ModuleLookupTable, TargetPointer> GetLookupTables(ModuleHandle handle) | ||
lambdageek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
Dictionary<ModuleLookupTable, TargetPointer> tables = []; | ||
tables[ModuleLookupTable.FieldDefToDesc] = target.ReadPointer(handle.Address + /* Module::FieldDefToDescMap */); | ||
tables[ModuleLookupTable.ManifestModuleReferences] = target.ReadPointer(handle.Address + /* Module::ManifestModuleReferencesMap */); | ||
tables[ModuleLookupTable.MemberRefToDesc] = target.ReadPointer(handle.Address + /* Module::MemberRefToDescMap */); | ||
tables[ModuleLookupTable.MethodDefToDesc] = target.ReadPointer(handle.Address + /* Module::MethodDefToDescMap */); | ||
tables[ModuleLookupTable.TypeDefToMethodTable] = target.ReadPointer(handle.Address + /* Module::TypeDefToMethodTableMap */); | ||
tables[ModuleLookupTable.TypeRefToMethodTable] = target.ReadPointer(handle.Address + /* Module::TypeRefToMethodTableMap */); | ||
return tables; | ||
} | ||
``` |
This file contains 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 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 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 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 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 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 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 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,64 @@ | ||
// 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 | ||
} | ||
|
||
internal enum ModuleLookupTable | ||
{ | ||
FieldDefToDesc, | ||
ManifestModuleReferences, | ||
MemberRefToDesc, | ||
MethodDefToDesc, | ||
TypeDefToMethodTable, | ||
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 bool IsReflectionEmit(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 IDictionary<ModuleLookupTable, TargetPointer> 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the only value I found in dotnet/diagnostics and microsoft/clrmd that was actually used. And it was just to print an explicit
IS_EDIT_AND_CONTINUE
as part of dumpmodule (also prints the raw flag values).