From 716b404125becdf61defcdc4e21163f4fa4aa7e5 Mon Sep 17 00:00:00 2001 From: Mikelle Date: Fri, 11 Aug 2023 17:33:15 -0700 Subject: [PATCH 1/3] update Get/SetFieldValue --- src/coreclr/vm/invokeutil.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/coreclr/vm/invokeutil.cpp b/src/coreclr/vm/invokeutil.cpp index c4ba804a4c493..334f2ecac6ea5 100644 --- a/src/coreclr/vm/invokeutil.cpp +++ b/src/coreclr/vm/invokeutil.cpp @@ -726,6 +726,8 @@ void InvokeUtil::SetValidField(CorElementType fldType, // call the OBJECTREF Throwable = NULL; + OBJECTREF obj = NULL; + MethodTable * pDeclMT = NULL; if (!declaringType.IsNull()) { @@ -905,10 +907,17 @@ void InvokeUtil::SetValidField(CorElementType fldType, MethodTable *pMT = fldTH.AsMethodTable(); { void* pFieldData; + fldTH.AsMethodTable()->EnsureActive(); + obj = fldTH.AsMethodTable()->Allocate(); + GCPROTECT_BEGIN(obj); if (pField->IsStatic()) pFieldData = pField->GetCurrentStaticAddress(); else - pFieldData = (*((BYTE**)target)) + pField->GetOffset() + sizeof(Object); + { + OBJECTREF objRef = ObjectToOBJECTREF(obj); + pFieldData = pField->GetAddress(OBJECTREFToObject(objRef)); + } + GCPROTECT_END(); if (*valueObj == NULL) InitValueClass(pFieldData, pMT); @@ -1051,7 +1060,8 @@ OBJECTREF InvokeUtil::GetFieldValue(FieldDesc* pField, TypeHandle fieldType, OBJ if (pField->IsStatic()) p = pField->GetCurrentStaticAddress(); else { - p = (*((BYTE**)target)) + pField->GetOffset() + sizeof(Object); + OBJECTREF objRef = ObjectToOBJECTREF(obj); + p = pField->GetAddress(OBJECTREFToObject(objRef)); } GCPROTECT_END(); From a14dba5d1d90122f39d756035c752cd633b3dff4 Mon Sep 17 00:00:00 2001 From: Mikelle Date: Mon, 14 Aug 2023 14:21:21 -0700 Subject: [PATCH 2/3] get the address of the instance --- src/coreclr/vm/invokeutil.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/coreclr/vm/invokeutil.cpp b/src/coreclr/vm/invokeutil.cpp index 334f2ecac6ea5..9f6f13dfc4392 100644 --- a/src/coreclr/vm/invokeutil.cpp +++ b/src/coreclr/vm/invokeutil.cpp @@ -907,17 +907,14 @@ void InvokeUtil::SetValidField(CorElementType fldType, MethodTable *pMT = fldTH.AsMethodTable(); { void* pFieldData; - fldTH.AsMethodTable()->EnsureActive(); - obj = fldTH.AsMethodTable()->Allocate(); - GCPROTECT_BEGIN(obj); if (pField->IsStatic()) + { pFieldData = pField->GetCurrentStaticAddress(); + } else { - OBJECTREF objRef = ObjectToOBJECTREF(obj); - pFieldData = pField->GetAddress(OBJECTREFToObject(objRef)); + pFieldData = pField->GetInstanceAddress(*target); } - GCPROTECT_END(); if (*valueObj == NULL) InitValueClass(pFieldData, pMT); @@ -1058,10 +1055,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 { - OBJECTREF objRef = ObjectToOBJECTREF(obj); - p = pField->GetAddress(OBJECTREFToObject(objRef)); + } + else + { + p = pField->GetInstanceAddress(*target); } GCPROTECT_END(); From 80861372eac49c7a02dfaf53b7463c1f54851c55 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 14 Aug 2023 14:37:17 -0700 Subject: [PATCH 3/3] Update src/coreclr/vm/invokeutil.cpp --- src/coreclr/vm/invokeutil.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/coreclr/vm/invokeutil.cpp b/src/coreclr/vm/invokeutil.cpp index 9f6f13dfc4392..e6ed2103393e3 100644 --- a/src/coreclr/vm/invokeutil.cpp +++ b/src/coreclr/vm/invokeutil.cpp @@ -726,8 +726,6 @@ void InvokeUtil::SetValidField(CorElementType fldType, // call the OBJECTREF Throwable = NULL; - OBJECTREF obj = NULL; - MethodTable * pDeclMT = NULL; if (!declaringType.IsNull()) {