Bug 318770 (MONO75847) - [PATCH] Invalid IL generated for PtrToStructure internal call
Summary: [PATCH] Invalid IL generated for PtrToStructure internal call
Status: RESOLVED FIXED
Alias: MONO75847
Product: Mono: Runtime
Classification: Mono
Component: interop (show other bugs)
Version: 1.1
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Mono Bugs
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-19 15:14 UTC by Jain Ankit
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
ptrtostruct3.patch (2.24 KB, patch)
2005-08-19 15:14 UTC, Thomas Wiest
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 19:27:51 UTC


---- Reported by jankit@novell.com 2005-08-19 08:14:10 MST ----

System.Runtime.InteropServices.PtrToStructure has two overloads (icalls) :

void PtrToStructure (IntPtr ptr, object structure);
object PtrToStructure (IntPtr ptr, Type structureType);

mono_marshal_get_ptr_to_struct (called from the ves_icall_*) generates IL
code for PtrToStructure (IntPtr src, object structure) by looking up the
signature for PtrToStructure using 'mono_class_get_method_from_name' which
basically finds the first entry with that name and two params. It needs the
overload with 'void' return type, which by ordering in Marshal.cs is
defined first, so it is able to get the right one.

But if the ordering is reversed, then it finds the other overload and thus
crashes at runtime with :

** ERROR **: Invalid IL code at IL000b in (wrapper unknown)
CertificateContext:PtrToStructure (intptr,System.Type): IL_000b: ret

The attached patch avoids the call to mono_class_get_method_from_name which
(here) is being called purely to get the signature for the method
(PtrToStructure) by building the MonoMethodSignature explicitly.



---- Additional Comments From jankit@novell.com 2005-08-19 08:14:57 MST ----

Created an attachment (id=168381)
ptrtostruct3.patch




---- Additional Comments From vargaz@gmail.com 2005-08-19 09:01:31 MST ----

This is ok to check in.




---- Additional Comments From jankit@novell.com 2005-08-19 11:00:39 MST ----

Checked-in, rev 48558.

Imported an attachment (id=168381)

Unknown operating system unknown. Setting to default OS "Other".