diff options
-rw-r--r-- | src/vm/arm/cgencpu.h | 2 | ||||
-rw-r--r-- | src/vm/arm64/cgencpu.h | 33 | ||||
-rw-r--r-- | src/vm/arm64/stubs.cpp | 20 | ||||
-rw-r--r-- | tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.cs | 41 | ||||
-rw-r--r-- | tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.csproj | 47 |
5 files changed, 126 insertions, 17 deletions
diff --git a/src/vm/arm/cgencpu.h b/src/vm/arm/cgencpu.h index 301118b144..30573eb571 100644 --- a/src/vm/arm/cgencpu.h +++ b/src/vm/arm/cgencpu.h @@ -1196,7 +1196,7 @@ struct FixupPrecode { typedef DPTR(FixupPrecode) PTR_FixupPrecode; -// Precode to stuffle this and retbuf for closed delegates over static methods with return buffer +// Precode to shuffle this and retbuf for closed delegates over static methods with return buffer struct ThisPtrRetBufPrecode { static const int Type = 0x84; diff --git a/src/vm/arm64/cgencpu.h b/src/vm/arm64/cgencpu.h index 9ac7d49ba3..cd54ea08ca 100644 --- a/src/vm/arm64/cgencpu.h +++ b/src/vm/arm64/cgencpu.h @@ -614,18 +614,12 @@ struct FixupPrecode { typedef DPTR(FixupPrecode) PTR_FixupPrecode; -// Precode to stuffle this and retbuf for closed delegates over static methods with return buffer +// Precode to shuffle this and retbuf for closed delegates over static methods with return buffer struct ThisPtrRetBufPrecode { - static const int Type = 0x84; + static const int Type = 0x10; - // mov r12, r0 - // mov r0, r1 - // mov r1, r12 - // ldr pc, [pc, #0] ; =m_pTarget - // dcd pTarget - // dcd pMethodDesc - WORD m_rgCode[6]; + UINT32 m_rgCode[6]; TADDR m_pTarget; TADDR m_pMethodDesc; @@ -633,20 +627,29 @@ struct ThisPtrRetBufPrecode { TADDR GetMethodDesc() { - _ASSERTE(!"ARM64:NYI"); - return NULL; + LIMITED_METHOD_DAC_CONTRACT; + + return m_pMethodDesc; } PCODE GetTarget() { - _ASSERTE(!"ARM64:NYI"); - return NULL; + LIMITED_METHOD_DAC_CONTRACT; + return m_pTarget; } BOOL SetTargetInterlocked(TADDR target, TADDR expected) { - _ASSERTE(!"ARM64:NYI"); - return NULL; + CONTRACTL + { + THROWS; + GC_TRIGGERS; + } + CONTRACTL_END; + + EnsureWritableExecutablePages(&m_pTarget); + return (TADDR)InterlockedCompareExchange64( + (LONGLONG*)&m_pTarget, (TADDR)target, (TADDR)expected) == expected; } }; typedef DPTR(ThisPtrRetBufPrecode) PTR_ThisPtrRetBufPrecode; diff --git a/src/vm/arm64/stubs.cpp b/src/vm/arm64/stubs.cpp index 38ce1d9791..2a3cddb0dd 100644 --- a/src/vm/arm64/stubs.cpp +++ b/src/vm/arm64/stubs.cpp @@ -572,9 +572,27 @@ void FixupPrecode::Fixup(DataImage *image, MethodDesc * pMD) } #endif // FEATURE_NATIVE_IMAGE_GENERATION + void ThisPtrRetBufPrecode::Init(MethodDesc* pMD, LoaderAllocator *pLoaderAllocator) { - _ASSERTE(!"ARM64:NYI"); + WRAPPER_NO_CONTRACT; + + int n = 0; + //Initially + //x0 -This ptr + //x1 -ReturnBuffer + m_rgCode[n++] = 0x91000010; // mov x16, x0 + m_rgCode[n++] = 0x91000020; // mov x0, x1 + m_rgCode[n++] = 0x91000201; // mov x1, x16 + m_rgCode[n++] = 0x58000070; // ldr x16, [pc, #12] + _ASSERTE((UINT32*)&m_pTarget == &m_rgCode[n + 2]); + m_rgCode[n++] = 0xd61f0200; // br x16 + n++; // empty 4 bytes for data alignment below + _ASSERTE(n == _countof(m_rgCode)); + + + m_pTarget = GetPreStubEntryPoint(); + m_pMethodDesc = (TADDR)pMD; } diff --git a/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.cs b/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.cs new file mode 100644 index 0000000000..6b35433adb --- /dev/null +++ b/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.cs @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +using System; +using System.Reflection; + +class Program +{ + public int scale; + + public Program(int scale) + { + this.scale = scale; + } + public static decimal getfunc(Program prog,int constituent) + { + return new decimal(constituent/prog.scale); + } + static int Main(string[] args) + { + int result = -1; + + int constituent = 3; + Program prog = new Program(1); + 2.Equals(3); + + MethodInfo info = typeof(Program).GetMethod("getfunc", BindingFlags.Static | BindingFlags.Public); + + //Tests closed delegates over static methods with return buffer + Func<int, decimal> deepThought = (Func<int, decimal>)info.CreateDelegate(typeof(Func<int, decimal>), prog); + + var res1 = deepThought(constituent); + var res2 = deepThought(constituent); + + if (decimal.Compare(res1, res2) == 0) + return 100; + + return result; + + } +} diff --git a/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.csproj b/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.csproj new file mode 100644 index 0000000000..59b1c83c7d --- /dev/null +++ b/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.csproj @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + <ReferenceLocalMscorlib>false</ReferenceLocalMscorlib> + <CLRTestKind>BuildAndRun</CLRTestKind> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <ItemGroup> + <!-- Add Compile Object Here --> + <Compile Include="ClosedStatic.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="app.config" /> + <None Include="project.json" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <WarningLevel Include="1" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> |