Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Jan 11, 2023
1 parent 53a8e73 commit 53716c8
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11727,30 +11727,39 @@ bool CEEInfo::getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE fieldHnd, uint8_t
// so we expect valueOffset to be a real field offset (same for bufferSize)
if (!field->IsRVA() && field->GetFieldType() == ELEMENT_TYPE_VALUETYPE)
{
PTR_MethodTable structType = field->GetFieldTypeHandleThrowing().GetMethodTable();
PTR_MethodTable structType = field->GetFieldTypeHandleThrowing().AsMethodTable();
if (structType->ContainsPointers())
{
for (WORD i = 0; i < structType->GetNumInstanceFields(); i++)
ApproxFieldDescIterator fieldIterator(structType, ApproxFieldDescIterator::INSTANCE_FIELDS);
for (FieldDesc* subField = fieldIterator.Next(); subField != NULL; subField = fieldIterator.Next())
{
FieldDesc* subField = (FieldDesc*)((structType->GetApproxFieldDescListRaw()) + i);
// TODO: If subField is also a struct we might want to inspect its fields too
if (subField->GetOffset() == (DWORD)valueOffset && subField->GetSize() == (UINT)bufferSize && subField->IsObjRef() &&
subField->GetFieldType() != ELEMENT_TYPE_VALUETYPE)
if (subField->GetOffset() == (DWORD)valueOffset && subField->GetSize() == (UINT)bufferSize &&
subField->IsObjRef() && subField->GetFieldType() != ELEMENT_TYPE_VALUETYPE)
{
GCX_COOP();

// Read field's value
Object* subFieldValue = nullptr;
memcpy(&subFieldValue, (uint8_t*)baseAddr + valueOffset, bufferSize);
if (subFieldValue == nullptr || GCHeapUtilities::GetGCHeap()->IsInFrozenSegment(subFieldValue))

if (subFieldValue == nullptr)
{
// GC handle from FOH or null
memcpy(buffer, (uint8_t*)baseAddr + valueOffset, bufferSize);
// Report null
memset(buffer, 0, bufferSize);
result = true;
}
break;
}

if (subField->GetOffset() >= (DWORD)valueOffset)
{
else if (GCHeapUtilities::GetGCHeap()->IsInFrozenSegment(subFieldValue))
{
CORINFO_OBJECT_HANDLE handle = getJitHandleForObject(
ObjectToOBJECTREF(subFieldValue), /*knownFrozen*/ true);

// GC handle is either from FOH or null
memcpy(buffer, &handle, bufferSize);
result = true;
}

// We're done with this struct
break;
}
}
Expand Down

0 comments on commit 53716c8

Please sign in to comment.