-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relax argument checks on pinned GCHandles #68694
Conversation
Relax argument checks on pinned GCHandles to allow any objects without references for consistency with DisableRuntimeMarshalling. Fixes dotnet#68686
Tagging subscribers to this area: @dotnet/interop-contrib Issue DetailsRelax argument checks on pinned GCHandles to allow any objects without references for consistency with DisableRuntimeMarshalling. Fixes #68686
|
The mono changes look ok to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems NativeAOT already has this similar definition and only checks for null
or if the type has pointers. I think at this point there is really no argument against adding support in all cases.
Lines 15 to 32 in 8656518
/// <summary> | |
/// Hooks for System.Private.Interop.dll code to access internal functionality in System.Private.CoreLib.dll. | |
/// | |
/// Methods added to InteropExtensions should also be added to the System.Private.CoreLib.InteropServices contract | |
/// in order to be accessible from System.Private.Interop.dll. | |
/// </summary> | |
[CLSCompliant(false)] | |
[ReflectionBlocked] | |
public static class InteropExtensions | |
{ | |
internal static bool MightBeBlittable(this EETypePtr eeType) | |
{ | |
// | |
// This is used as the approximate implementation of MethodTable::IsBlittable(). It will err in the direction of declaring | |
// things blittable since it is used for argument validation only. | |
// | |
return !eeType.HasPointers; | |
} |
What about the following that mark char
and bool
as non-blittable? I think Crossgen or NativeAOT might trigger off of that in some manner.
runtime/src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs
Lines 273 to 312 in 8656518
case TypeFlags.Boolean: | |
switch (nativeType) | |
{ | |
case NativeTypeKind.Default: | |
case NativeTypeKind.Boolean: | |
return MarshallerKind.Bool; | |
case NativeTypeKind.U1: | |
case NativeTypeKind.I1: | |
return MarshallerKind.CBool; | |
case NativeTypeKind.VariantBool: | |
if (context.Target.IsWindows) | |
return MarshallerKind.VariantBool; | |
else | |
return MarshallerKind.Invalid; | |
default: | |
return MarshallerKind.Invalid; | |
} | |
case TypeFlags.Char: | |
switch (nativeType) | |
{ | |
case NativeTypeKind.I1: | |
case NativeTypeKind.U1: | |
return MarshallerKind.AnsiChar; | |
case NativeTypeKind.I2: | |
case NativeTypeKind.U2: | |
return MarshallerKind.UnicodeChar; | |
case NativeTypeKind.Default: | |
if (isAnsi) | |
return MarshallerKind.AnsiChar; | |
else | |
return MarshallerKind.UnicodeChar; | |
default: | |
return MarshallerKind.Invalid; | |
} |
...sts/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/GCHandleTests.cs
Outdated
Show resolved
Hide resolved
…ime.InteropServices.UnitTests/System/Runtime/InteropServices/GCHandleTests.cs Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pinnable if it doesn't have references?
src/mono/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs
Outdated
Show resolved
Hide resolved
…ices/Marshal.Mono.cs Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>
I do not see a problem here. The marshaling without |
Improvements on windows arm64: dotnet/perf-autofiling-issues#5147, dotnet/perf-autofiling-issues#5148 |
Relax argument checks on pinned GCHandles to allow any objects without references for consistency with DisableRuntimeMarshalling.
Fixes #68686