[Mono-bugs] [Bug 79289][Wis] New - Mono asserts when trying to marshal an [In, Out] class to native code

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue Sep 5 17:25:00 EDT 2006


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by jonpryor at vt.edu.

http://bugzilla.ximian.com/show_bug.cgi?id=79289

--- shadow/79289	2006-09-05 17:25:00.000000000 -0400
+++ shadow/79289.tmp.32448	2006-09-05 17:25:00.000000000 -0400
@@ -0,0 +1,145 @@
+Bug#: 79289
+Product: Mono: Runtime
+Version: 1.0
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: interop
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: jonpryor at vt.edu               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Mono asserts when trying to marshal an [In, Out] class to native code
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+Mono asserts & dies when trying to marshal an [In, Out] class to native
+code, i.e. if native code invokes a delegate which has an [In, Out]
+parameter, Mono asserts.
+
+Steps to reproduce the problem:
+1. Compile the following native code into the library `libtest.so', e.g.
+`gcc -shared -o libtest.so test.c`:
+
+	/* native: invoke a delegate */
+	#include <stdlib.h>
+	#include <stdio.h>
+
+	struct Info {
+		int n;
+	};
+
+	typedef void (*InfoCb) (const char *path, struct Info *pi);
+
+	void
+	Invoke (InfoCb cb)
+	{
+		struct Info i;
+		i.n = 128;
+		printf ("[nat] begin Info.n=%i\n", i.n);
+		cb ("hello", &i);
+		printf ("[nat]   end Info.n=%i\n", i.n);
+	}
+
+2. Compile the following C# code into an exe, e.g. `mcs managed.cs`:
+
+	using System;
+	using System.Runtime.InteropServices;
+
+	[StructLayout (LayoutKind.Sequential)]
+	class Info {
+		public int n;
+	}
+
+	delegate void InfoCb (string path, [In, Out] Info info);
+
+	class Test {
+		[DllImport ("test")]
+		private static extern void Invoke (InfoCb cb);
+
+		static void Foo (string path, Info info)
+		{
+			Console.WriteLine (
+				"[mgd] Foo invoked; info.n={0}", info.n);
+			info.n = 42;
+			Console.WriteLine (
+				"[mgd] Foo returning; info.n={0}", info.n);
+		}
+
+		static void Main ()
+		{
+			Invoke (Foo);
+		}
+	}
+
+3. Run: LD_LIBRARY_PATH=`pwd` mono mgd.exe
+
+Actual Results:
+
+** ERROR **: file marshal.c: line 7671 (mono_marshal_get_managed_wrapper):
+should not be reached
+aborting...
+
+=================================================================
+Got a SIGABRT while executing native code. This usually indicates
+a fatal error in the mono runtime or one of the native libraries
+used by your application.
+=================================================================
+
+Stacktrace:
+
+  at (wrapper managed-to-native)
+System.Object.__icall_wrapper_mono_delegate_to_ftnptr (object) <0x00004>
+  at (wrapper managed-to-native)
+System.Object.__icall_wrapper_mono_delegate_to_ftnptr (object) <0xffffffff>
+  at (wrapper managed-to-native) Test.Invoke (InfoCb) <0xffffffff>
+  at Test.Main () <0x00035>
+  at (wrapper runtime-invoke) System.Object.runtime_invoke_void
+(object,intptr,intptr,intptr) <0xffffffff>
+
+Native stacktrace:
+
+        mono(mono_handle_native_sigsegv+0xde) [0x815d3ce]
+        [0xffffe440]
+        /lib/libc.so.6(abort+0x103) [0xb7d31ea3]
+        /opt/gnome/lib/libglib-2.0.so.0(g_logv+0x46d) [0xb7ea81bd]
+        /opt/gnome/lib/libglib-2.0.so.0(g_log+0x35) [0xb7ea8205]
+        /opt/gnome/lib/libglib-2.0.so.0(g_assert_warning+0x76) [0xb7ea8286]
+        mono(mono_marshal_get_managed_wrapper+0x528) [0x80b2338]
+        mono(mono_delegate_to_ftnptr+0x43) [0x80b2833]
+        [0xb7497eee]
+        [0xb7497e95]
+        [0xb74979ae]
+        [0xb74977be]
+        mono(mono_runtime_exec_main+0x62) [0x80de442]
+        mono(mono_runtime_run_main+0x1b9) [0x80de729]
+        mono(mono_main+0xe46) [0x805e786]
+        mono [0x805d432]
+        /lib/libc.so.6(__libc_start_main+0xdc) [0xb7d1d87c]
+        mono [0x805d381]
+Aborted
+
+Expected Results:
+
+No crash, and the following output:
+
+[nat] begin Info.n=128
+[mgd] Foo invoked; info.n=128
+[mgd] Foo returning; info.n=42
+[nat]   end Info.n=42
+
+In particular, note that the native value of Info.n matches the previously
+set managed value of Info.n.
+
+How often does this happen? 
+
+Always.
+
+Additional Information:


More information about the mono-bugs mailing list