[release/8.0] Update Get/SetFieldValue to Account for EnC (#90623)
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Thu, 17 Aug 2023 21:38:32 +0000 (14:38 -0700)
committerGitHub <noreply@github.com>
Thu, 17 Aug 2023 21:38:32 +0000 (14:38 -0700)
* update Get/SetFieldValue

* get the address of the instance

* Update src/coreclr/vm/invokeutil.cpp

---------

Co-authored-by: Mikelle <mirogers@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
src/coreclr/vm/invokeutil.cpp

index c4ba804..e6ed210 100644 (file)
@@ -906,9 +906,13 @@ void InvokeUtil::SetValidField(CorElementType fldType,
         {
             void* pFieldData;
             if (pField->IsStatic())
+            {
                 pFieldData = pField->GetCurrentStaticAddress();
+            }
             else
-                pFieldData = (*((BYTE**)target)) + pField->GetOffset() + sizeof(Object);
+            {
+                pFieldData = pField->GetInstanceAddress(*target);
+            }
 
             if (*valueObj == NULL)
                 InitValueClass(pFieldData, pMT);
@@ -1049,9 +1053,12 @@ OBJECTREF InvokeUtil::GetFieldValue(FieldDesc* pField, TypeHandle fieldType, OBJ
         GCPROTECT_BEGIN(obj);
         // calculate the offset to the field...
         if (pField->IsStatic())
+        {
             p = pField->GetCurrentStaticAddress();
-        else {
-                p = (*((BYTE**)target)) + pField->GetOffset() + sizeof(Object);
+        }
+        else
+        {
+            p = pField->GetInstanceAddress(*target);
         }
         GCPROTECT_END();