Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4175,7 +4175,35 @@ public int GetModuleMetaDataFileInfo(ulong vmModule, uint* dwTimeStamp, uint* dw
}

public int IsThreadSuspendedOrHijacked(ulong vmThread, Interop.BOOL* pResult)
=> LegacyFallbackHelper.CanFallback() && _legacy is not null ? _legacy.IsThreadSuspendedOrHijacked(vmThread, pResult) : HResults.E_NOTIMPL;
{
int hr = HResults.S_OK;
try
{
if (pResult is null)
throw new NullReferenceException();

*pResult = Interop.BOOL.FALSE;
Contracts.ThreadState threadState = _target.Contracts.Thread.GetThreadData(vmThread).State;
*pResult = (threadState & (Contracts.ThreadState.DebugSyncSuspended | Contracts.ThreadState.Hijacked)) != 0
? Interop.BOOL.TRUE : Interop.BOOL.FALSE;
Comment thread
noahfalk marked this conversation as resolved.
}
catch (System.Exception ex)
{
hr = ex.HResult;
}
#if DEBUG
if (_legacy is not null)
{
Interop.BOOL resultLocal = Interop.BOOL.FALSE;
Interop.BOOL* resultLocalPtr = pResult is null ? null : &resultLocal;
int hrLocal = _legacy.IsThreadSuspendedOrHijacked(vmThread, resultLocalPtr);
Debug.ValidateHResult(hr, hrLocal);
if (hr == HResults.S_OK)
Debug.Assert(*pResult == resultLocal);
}
#endif
return hr;
}

public int CreateHeapWalk(nuint* pHandle)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,31 @@ public unsafe void IsThreadMarkedDead_CrossValidateWithContract(TestConfiguratio
}
}

[ConditionalTheory]
[MemberData(nameof(TestConfigurations))]
public unsafe void IsThreadSuspendedOrHijacked_CrossValidateWithContract(TestConfiguration config)
{
InitializeDumpTest(config);
DacDbiImpl dbi = CreateDacDbi();

IThread threadContract = Target.Contracts.Thread;
ThreadStoreData storeData = threadContract.GetThreadStoreData();

TargetPointer current = storeData.FirstThread;
while (current != TargetPointer.Null)
{
Interop.BOOL isSuspendedOrHijacked;
int hr = dbi.IsThreadSuspendedOrHijacked(current, &isSuspendedOrHijacked);
Assert.Equal(System.HResults.S_OK, hr);

ThreadData data = threadContract.GetThreadData(current);
bool contractSaysSuspendedOrHijacked = (data.State & (Contracts.ThreadState.DebugSyncSuspended | Contracts.ThreadState.Hijacked)) != 0;
Assert.Equal(contractSaysSuspendedOrHijacked, isSuspendedOrHijacked == Interop.BOOL.TRUE);

current = data.NextThread;
}
}

[ConditionalTheory]
[MemberData(nameof(TestConfigurations))]
public unsafe void TryGetVolatileOSThreadID_MatchesContract(TestConfiguration config)
Expand Down
37 changes: 37 additions & 0 deletions src/native/managed/cdac/tests/UnitTests/DacDbiImplTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,43 @@ private static (DacDbiImpl DacDbi, TestPlaceholderTarget Target) CreateDacDbiWit
return (dacDbi, target);
}

[Theory]
[ClassData(typeof(MockTarget.StdArch))]
public void IsThreadSuspendedOrHijacked_NullOutput_ReturnsEPointer(MockTarget.Architecture arch)
{
var mockThread = new Mock<IThread>();
TestPlaceholderTarget target = new TestPlaceholderTarget.Builder(arch)
.AddMockContract(mockThread)
.Build();
DacDbiImpl dacDbi = new(target, legacyObj: null);

int hr = dacDbi.IsThreadSuspendedOrHijacked(0, null);

Assert.Equal(System.HResults.E_POINTER, hr);
}

[Theory]
[ClassData(typeof(MockTarget.StdArch))]
public void IsThreadSuspendedOrHijacked_ContractFailure_InitializesOutput(MockTarget.Architecture arch)
{
const ulong ThreadAddress = 0x1000;
InvalidOperationException exception = new();
var mockThread = new Mock<IThread>();
mockThread
.Setup(t => t.GetThreadData(new TargetPointer(ThreadAddress)))
.Throws(exception);
TestPlaceholderTarget target = new TestPlaceholderTarget.Builder(arch)
.AddMockContract(mockThread)
.Build();
DacDbiImpl dacDbi = new(target, legacyObj: null);
Interop.BOOL result = Interop.BOOL.TRUE;

int hr = dacDbi.IsThreadSuspendedOrHijacked(ThreadAddress, &result);

Assert.Equal(exception.HResult, hr);
Assert.Equal(Interop.BOOL.FALSE, result);
}

[Fact]
public void DacSetTargetConsistencyChecks_Standalone_ReturnsSuccess()
{
Expand Down
Loading