Skip to content
Open
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 @@ -1199,13 +1199,137 @@ public int GetMDStructuresVersion(uint* pMDStructuresVersion)
}

public int GetActiveRejitILCodeVersionNode(ulong vmModule, uint methodTk, ulong* pVmILCodeVersionNode)
=> LegacyFallbackHelper.CanFallback() && _legacy is not null ? _legacy.GetActiveRejitILCodeVersionNode(vmModule, methodTk, pVmILCodeVersionNode) : HResults.E_NOTIMPL;
{
int hr = HResults.S_OK;
try
Comment thread
rcj1 marked this conversation as resolved.
{
if (pVmILCodeVersionNode is null)
throw new ArgumentException("Output pointer cannot be null.", nameof(pVmILCodeVersionNode));

*pVmILCodeVersionNode = 0;
Comment thread
rcj1 marked this conversation as resolved.

if (!_target.Contracts.TryGetContract<IReJIT>(out IReJIT rejit))
return hr;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like native does a failfast here, should we return an error code?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, it's an assert not a failfast and it does nothing if consistency checks are not enabled


ILoader loader = _target.Contracts.Loader;
Contracts.ModuleHandle module = loader.GetModuleHandleFromModulePtr(new TargetPointer(vmModule));
ModuleLookupTables lookupTables = loader.GetLookupTables(module);
TargetPointer methodDesc = TargetPointer.Null;
try
{
if ((EcmaMetadataUtils.TokenType)(methodTk & EcmaMetadataUtils.TokenTypeMask) != EcmaMetadataUtils.TokenType.mdtMethodDef)
throw new ArgumentException("methodTk must be a MethodDef token.", nameof(methodTk));
methodDesc = loader.GetModuleLookupMapElement(lookupTables.MethodDefToDesc, methodTk, out _);
}
Comment thread
rcj1 marked this conversation as resolved.
catch (ArgumentOutOfRangeException)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any benefit we get by catching this? If the caller passes in a bad methodToken it seems odd to suppress that and return S_OK.

{
// Invalid method token
}
Comment thread
rcj1 marked this conversation as resolved.
if (methodDesc != TargetPointer.Null)
{
ICodeVersions codeVersions = _target.Contracts.CodeVersions;
ILCodeVersionHandle ilCodeVersion = codeVersions.GetActiveILCodeVersion(methodDesc);
if (ilCodeVersion.IsValid
&& ilCodeVersion.IsExplicit
&& rejit.GetRejitState(ilCodeVersion) == RejitState.Active)
{
*pVmILCodeVersionNode = ilCodeVersion.ILCodeVersionNode.Value;
}
Comment thread
rcj1 marked this conversation as resolved.
Comment thread
rcj1 marked this conversation as resolved.
}
}
catch (System.Exception ex)
{
hr = ex.HResult;
}

#if DEBUG
if (_legacy is not null)
{
ulong resultLocal;
int hrLocal = _legacy.GetActiveRejitILCodeVersionNode(vmModule, methodTk, &resultLocal);
Debug.ValidateHResult(hr, hrLocal);
if (hr == HResults.S_OK)
Debug.Assert(*pVmILCodeVersionNode == resultLocal, $"cDAC: {*pVmILCodeVersionNode:x}, DAC: {resultLocal:x}");
}
#endif

return hr;
}

public int GetNativeCodeVersionNode(ulong vmMethod, ulong codeStartAddress, ulong* pVmNativeCodeVersionNode)
=> LegacyFallbackHelper.CanFallback() && _legacy is not null ? _legacy.GetNativeCodeVersionNode(vmMethod, codeStartAddress, pVmNativeCodeVersionNode) : HResults.E_NOTIMPL;
{
int hr = HResults.S_OK;
try
{
if (pVmNativeCodeVersionNode is null)
throw new ArgumentException("Output pointer cannot be null.", nameof(pVmNativeCodeVersionNode));

*pVmNativeCodeVersionNode = 0;

TargetCodePointer codeAddress = new TargetCodePointer(codeStartAddress);
ICodeVersions codeVersions = _target.Contracts.CodeVersions;

NativeCodeVersionHandle nativeCodeVersion = codeVersions.GetNativeCodeVersionForIP(codeAddress);
if (nativeCodeVersion.Valid && nativeCodeVersion.IsExplicit)
Comment thread
rcj1 marked this conversation as resolved.
{
*pVmNativeCodeVersionNode = nativeCodeVersion.CodeVersionNodeAddress.Value;
}
}
catch (System.Exception ex)
{
hr = ex.HResult;
}

#if DEBUG
if (_legacy is not null)
{
ulong resultLocal;
int hrLocal = _legacy.GetNativeCodeVersionNode(vmMethod, codeStartAddress, &resultLocal);
Debug.ValidateHResult(hr, hrLocal);
if (hr == HResults.S_OK)
Debug.Assert(*pVmNativeCodeVersionNode == resultLocal, $"cDAC: {*pVmNativeCodeVersionNode:x}, DAC: {resultLocal:x}");
}
#endif

return hr;
}

public int GetILCodeVersionNode(ulong vmNativeCodeVersionNode, ulong* pVmILCodeVersionNode)
=> LegacyFallbackHelper.CanFallback() && _legacy is not null ? _legacy.GetILCodeVersionNode(vmNativeCodeVersionNode, pVmILCodeVersionNode) : HResults.E_NOTIMPL;
{
int hr = HResults.S_OK;
try
{
if (pVmILCodeVersionNode is null)
throw new ArgumentException("Output pointer cannot be null.", nameof(pVmILCodeVersionNode));

*pVmILCodeVersionNode = 0;

ICodeVersions codeVersions = _target.Contracts.CodeVersions;
NativeCodeVersionHandle nativeCodeVersion = NativeCodeVersionHandle.CreateExplicit(new TargetPointer(vmNativeCodeVersionNode));
ILCodeVersionHandle ilCodeVersion = codeVersions.GetILCodeVersion(nativeCodeVersion);
if (ilCodeVersion.IsValid && ilCodeVersion.IsExplicit)
{
*pVmILCodeVersionNode = ilCodeVersion.ILCodeVersionNode.Value;
}
}
catch (System.Exception ex)
{
hr = ex.HResult;
}

#if DEBUG
if (_legacy is not null)
{
ulong resultLocal;
int hrLocal = _legacy.GetILCodeVersionNode(vmNativeCodeVersionNode, &resultLocal);
Debug.ValidateHResult(hr, hrLocal);
if (hr == HResults.S_OK)
Debug.Assert(*pVmILCodeVersionNode == resultLocal, $"cDAC: {*pVmILCodeVersionNode:x}, DAC: {resultLocal:x}");
}
#endif

return hr;
}

public int GetILCodeVersionNodeData(ulong ilCodeVersionNode, DacDbiSharedReJitInfo* pData)
=> LegacyFallbackHelper.CanFallback() && _legacy is not null ? _legacy.GetILCodeVersionNodeData(ilCodeVersionNode, pData) : HResults.E_NOTIMPL;
Expand Down
Loading