[Mono-dev] Bad usage of GCHandleType.Pinned

Rodrigo Kumpera rokumper at microsoft.com
Thu Nov 10 16:56:09 UTC 2016


Hey guys,


It came to my attention that mono is a bit more liberal in what objects it allows a pinned gc handle to be created. Dotnet only allows pinned handles to blitable types as it doesn't expose unprotected heap pointers to unsafe code.


There's a PR[1] fixing this but I'm wary on merging it before addressing this issue on, at least, the Xamarin platform.


I've identified problems in Macios[2] and WebSharp[3] (tons more on websharp).


Additionally, I identified a lot of code in both macios and android that would lead to heap corruption if

misused [4].


My suggestion is that we address issues like [2] and [3] as [4] is fine for correct usage of the code.


--

Rodrigo


[1] https://github.com/mono/mono/pull/3929

[2] https://github.com/xamarin/xamarin-macios/blob/fc55e4306f79491fd269ca2495c6a859799cb1c6/src/CoreMedia/CMCustomBlockAllocator.cs#L24

[3] https://github.com/xamarin/WebSharp/blob/4df0770f7fd166155be785d4dbdf368ffd2f8466/PepperSharp/src/CompletionCallback.cs#L30

[4] https://github.com/xamarin/xamarin-macios/blob/fc55e4306f79491fd269ca2495c6a859799cb1c6/src/Metal/MTLDevice.cs#L48

[https://avatars1.githubusercontent.com/u/123220?v=3&s=400]<https://github.com/mono/mono/pull/3929>

Enforce restrictions on pinned GCHandle objects by joshpeterson · Pull Request #3929 · mono/mono<https://github.com/mono/mono/pull/3929>
github.com
A pinned GCHandle should not be allowed for some types. The GCHandle.Alloc method should throw an ArgumentException in these cases. This change corrects bug https://bugzilla.xamarin.com/show_bug.cg...


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dot.net/pipermail/mono-devel-list/attachments/20161110/c2f4cfea/attachment.html>


More information about the Mono-devel-list mailing list