Skip to content

Commit

Permalink
Separate RVA reflection change out
Browse files Browse the repository at this point in the history
  • Loading branch information
huoyaoyuan committed Jun 19, 2024
1 parent 324df76 commit 089ae12
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 39 deletions.
14 changes: 6 additions & 8 deletions src/coreclr/vm/reflectioninvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1246,16 +1246,14 @@ FCIMPL1(void*, RuntimeFieldHandle::GetStaticFieldAddress, ReflectFieldObject *pF
// IsFastPathSupported needs to checked before calling this method.
_ASSERTE(IsFastPathSupportedHelper(pFieldDesc));

if (pFieldDesc->IsRVA())
PTR_BYTE base = 0;
if (!pFieldDesc->IsRVA())
{
Module* pModule = pFieldDesc->GetModule();
return pModule->GetRvaField(pFieldDesc->GetOffset());
}
else
{
PTR_BYTE base = pFieldDesc->GetBase();
return PTR_VOID(base + pFieldDesc->GetOffset());
// For RVA the base is ignored and offset is used.
base = pFieldDesc->GetBase();
}

return PTR_VOID(base + pFieldDesc->GetOffset());
}
FCIMPLEND

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Xunit;

#pragma warning disable 0414
Expand Down Expand Up @@ -123,30 +121,6 @@ public void GetValueWithFunctionPointers(Type type, string name, object obj, obj
Assert.Equal(expected, fieldInfo.GetValue(obj));
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/103207")]
public void GetValueFromRvaField()
{
byte[] valueArray = new byte[] { 1, 2, 3, 4, 5 };

// Roslyn uses SHA256 of raw data as data field name
FieldInfo fieldInfo = GetField(
typeof(FieldInfoTests).Assembly.GetType("<PrivateImplementationDetails>"),
"74F81FE167D99B4CB41D6D0CCDA82278CAEE9F3E2F25D5E5A3936FF3DCEC60D0");
Assert.NotNull(fieldInfo);
Assert.True(fieldInfo.IsStatic);
Assert.True((fieldInfo.Attributes & FieldAttributes.HasFieldRVA) != 0);

for (int i = 0; i < 5; i++)
{
// FieldAccessor uses slow path until the class is initialized.
// Make sure subsequent invocations also succeed.

object value = fieldInfo.GetValue(null);
Assert.Equal(valueArray, MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As<object, RawData>(ref value).Data, valueArray.Length));
}
}

[Fact]
public void GetAndSetValueTypeFromStatic()
{
Expand Down Expand Up @@ -865,10 +839,5 @@ public static class SettingsForMyTypeThatThrowsInClassInitializer
{
public static bool s_shouldThrow = true;
}

private class RawData
{
public byte Data;
}
}
}

0 comments on commit 089ae12

Please sign in to comment.