-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[cDAC] Implement GetCurrentAppDomain on IXCLRDataTask #124996
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
+145
−5
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fdfa018
Implement GetCurrentAppDomain for cDAC
barosiak df6c767
Merge branch 'main' into barosiak/GetCurrentAppDomain
barosiak 5235dec
Fix build issues
barosiak d78913d
Merge branch 'main' into barosiak/GetCurrentAppDomain
barosiak 7f4c747
Implement IsSameObject, expand test
barosiak 79ab08f
Add a space character
barosiak a96da61
Revert type substitution
barosiak d02e3b3
Merge branch 'main' into barosiak/GetCurrentAppDomain
barosiak 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
70 changes: 70 additions & 0 deletions
70
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataAppDomain.cs
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,70 @@ | ||
| // 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.Diagnostics; | ||
| using System.Runtime.InteropServices; | ||
| using System.Runtime.InteropServices.Marshalling; | ||
barosiak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.Legacy; | ||
|
|
||
| [GeneratedComClass] | ||
| public sealed unsafe partial class ClrDataAppDomain : IXCLRDataAppDomain | ||
| { | ||
| private readonly TargetPointer _appDomain; | ||
| private readonly IXCLRDataAppDomain? _legacyImpl; | ||
|
|
||
| public TargetPointer Address => _appDomain; | ||
|
|
||
| public ClrDataAppDomain(TargetPointer appDomain, IXCLRDataAppDomain? legacyImpl) | ||
| { | ||
| _appDomain = appDomain; | ||
| _legacyImpl = legacyImpl; | ||
| } | ||
|
|
||
barosiak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| int IXCLRDataAppDomain.GetProcess(/*IXCLRDataProcess*/ void** process) | ||
| => _legacyImpl is not null ? _legacyImpl.GetProcess(process) : HResults.E_NOTIMPL; | ||
|
|
||
| int IXCLRDataAppDomain.GetName(uint bufLen, uint* nameLen, char* name) | ||
| => _legacyImpl is not null ? _legacyImpl.GetName(bufLen, nameLen, name) : HResults.E_NOTIMPL; | ||
|
|
||
| int IXCLRDataAppDomain.GetUniqueID(ulong* id) | ||
| => _legacyImpl is not null ? _legacyImpl.GetUniqueID(id) : HResults.E_NOTIMPL; | ||
|
|
||
| int IXCLRDataAppDomain.GetFlags(uint* flags) | ||
| => _legacyImpl is not null ? _legacyImpl.GetFlags(flags) : HResults.E_NOTIMPL; | ||
|
|
||
| int IXCLRDataAppDomain.IsSameObject(IXCLRDataAppDomain* appDomain) | ||
| { | ||
| int hr = HResults.S_FALSE; | ||
| try | ||
| { | ||
| StrategyBasedComWrappers cw = new(); | ||
| object obj = cw.GetOrCreateObjectForComInstance((nint)appDomain, CreateObjectFlags.None); | ||
| if (obj is ClrDataAppDomain other) | ||
| { | ||
| hr = _appDomain == other._appDomain ? HResults.S_OK : HResults.S_FALSE; | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| hr = ex.HResult; | ||
| } | ||
|
|
||
| #if DEBUG | ||
| if (_legacyImpl is not null) | ||
| { | ||
| int hrLocal = _legacyImpl.IsSameObject(appDomain); | ||
| Debug.Assert(hrLocal == hr, $"cDAC: {hr}, DAC: {hrLocal}"); | ||
| } | ||
| #endif | ||
|
|
||
| return hr; | ||
| } | ||
|
|
||
| int IXCLRDataAppDomain.GetManagedObject(/*IXCLRDataValue*/ void** value) | ||
| => _legacyImpl is not null ? _legacyImpl.GetManagedObject(value) : HResults.E_NOTIMPL; | ||
|
|
||
| int IXCLRDataAppDomain.Request(uint reqCode, uint inBufferSize, byte* inBuffer, uint outBufferSize, byte* outBuffer) | ||
| => _legacyImpl is not null ? _legacyImpl.Request(reqCode, inBufferSize, inBuffer, outBufferSize, outBuffer) : HResults.E_NOTIMPL; | ||
| } | ||
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,45 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
barosiak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| using Microsoft.Diagnostics.DataContractReader.Legacy; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.Tests; | ||
|
|
||
| public unsafe class ClrDataTaskTests | ||
| { | ||
| [Theory] | ||
| [ClassData(typeof(MockTarget.StdArch))] | ||
| public void GetCurrentAppDomain(MockTarget.Architecture arch) | ||
| { | ||
| TargetTestHelpers helpers = new(arch); | ||
| MockMemorySpace.Builder builder = new(helpers); | ||
|
|
||
| ulong globalPtrAddr = 0x1000; | ||
| ulong expectedAppDomain = 0x2000; | ||
|
|
||
| byte[] ptrData = new byte[helpers.PointerSize]; | ||
| helpers.WritePointer(ptrData, expectedAppDomain); | ||
| builder.AddHeapFragment(new MockMemorySpace.HeapFragment | ||
| { | ||
| Address = globalPtrAddr, | ||
| Data = ptrData, | ||
| Name = "AppDomainGlobalPointer" | ||
| }); | ||
|
|
||
| var target = new TestPlaceholderTarget( | ||
| arch, | ||
| builder.GetMemoryContext().ReadFromTarget, | ||
| globals: [(Constants.Globals.AppDomain, globalPtrAddr)]); | ||
|
|
||
| TargetPointer taskAddress = new TargetPointer(0x5000); | ||
| IXCLRDataTask task = new ClrDataTask(taskAddress, target, legacyImpl: null); | ||
| int hr = task.GetCurrentAppDomain(out IXCLRDataAppDomain? appDomain); | ||
max-charlamb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Assert.Equal(HResults.S_OK, hr); | ||
| Assert.NotNull(appDomain); | ||
| ClrDataAppDomain clrAppDomain = Assert.IsType<ClrDataAppDomain>(appDomain); | ||
| Assert.Equal(new TargetPointer(expectedAppDomain), clrAppDomain.Address); | ||
| } | ||
| } | ||
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.