-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory corruption bug in virtual static method dispatch (#107763)
- Use `TypeHandle::CanCastTo` instead of `MethodTable::CanCastTo` - The issue is that the `MethodTable` api requires cooperative mode, and the `TypeHandle` supports either mode Fixes #107754
- Loading branch information
1 parent
9bf9224
commit 170b42c
Showing
3 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...Loader/classloader/StaticVirtualMethods/Regression/VariantVirtualStaticDefaultDispatch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.CompilerServices; | ||
using Xunit; | ||
|
||
// This test comes from https://github.com/dotnet/runtime/issues/107754 | ||
|
||
namespace VariantVirtualStaticDefaultDispatch | ||
{ | ||
interface IStaticConstraint<in T> | ||
{ | ||
public abstract static void M(); | ||
} | ||
|
||
interface IStaticConstraintDefaultImpl<in T> : IStaticConstraint<T> | ||
{ | ||
static void IStaticConstraint<T>.M() { } | ||
} | ||
|
||
interface IConstraintCheck<U, W> where U : IStaticConstraint<W> | ||
{ | ||
} | ||
|
||
struct StructThatImplementsConstraint : IStaticConstraintDefaultImpl<object> | ||
{ | ||
} | ||
|
||
public class Tests | ||
{ | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static void M<U>() where U: IStaticConstraint<string> | ||
{ | ||
U.M(); | ||
} | ||
|
||
[Fact] | ||
public static void RunTest() | ||
{ | ||
System.Console.WriteLine(typeof(IConstraintCheck<StructThatImplementsConstraint, string>)); | ||
M<StructThatImplementsConstraint>(); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...er/classloader/StaticVirtualMethods/Regression/VariantVirtualStaticDefaultDispatch.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<DebugType>Full</DebugType> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildThisFileName).cs" /> | ||
</ItemGroup> | ||
</Project> |