-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cdac] Start Loader contract and implement ISOSDacInterface::GetModul…
…eData in cDAC (#104257) - Start a `Loader` contract - currently contains what is needed for GetModuleData - Implement `ISOSDacInterface::GetModuleData` in cDAC - Store base address and is reflection emit bit on `Module` for easier diagnostics access
- Loading branch information
1 parent
eae1542
commit 04a40c1
Showing
16 changed files
with
523 additions
and
15 deletions.
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,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 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,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.