[Mono-osx] Bug: Using interop that return struct crashes
Geoff Norton
gnorton at novell.com
Fri Feb 6 13:30:18 EST 2009
Please file a bug at bugzilla.novell.com
On Fri, 2009-02-06 at 10:17 -0800, Phi Le wrote:
> Hello,
>
> I am having problems calling CoreGraphics interops that return structs
> in an embedded instance of mono. I am using Mono 2.2 on OS X 10.5.6.
> I have attached and included the code to reproduce the problem. I
> have found 3 different errors using different structs. Take a look at
> my gdb output. Interestingly, there were no problem if the struct
> contains just a pointer (void */IntPtr), or just an int.
>
> I know how to work around the problem by using an out parameter, but I
> would like a solution where I can use the original function signature.
>
> Thanks,
>
> Phi
>
> File: MyClass.cs
> <code>
> using System;
> using System.Runtime.InteropServices;
>
> namespace Test {
> public class MyClass {
> public static void Main(String[] args) {
> try {
> Console.WriteLine("MyClass.Main()");
> InterOpTest();
> } catch (Exception ex) {
> Console.WriteLine(ex.ToString());
> }
> }
>
> [DllImport("__Internal")]
> private static extern MyStruct InterOpTest();
>
> }
>
> [StructLayout(LayoutKind.Sequential)]
> public struct MyStruct {
> //public char x;
> //public int y;
> //public float f;
> public IntPtr p;
> }
> }
> </code>
>
> File: main.c
> <code>
> #include <mono/jit/jit.h>
> #include <mono/metadata/assembly.h>
>
> struct MyStruct {
> //char x;
> //int y;
> //float f;
> void * p;
> };
> typedef struct MyStruct MyStruct;
>
> MyStruct InterOpTest() {
> fprintf(stderr, "MyStruct InterOpTest()\n");
> MyStruct retVal;
> return retVal;
> }
>
> int main(int argc, char *argv[])
> {
> char* file = "MyClass.exe";
>
> MonoAssembly* assembly;
> MonoDomain* domain;
>
> domain = mono_jit_init(file);
> assembly = mono_domain_assembly_open (domain, file);
> mono_jit_exec(domain, assembly, 1, argv);
> return 0;
> }
> </code>
>
> File: Makefile
> <code>
> all:
> mcs MyClass.cs
> gcc main.c `pkg-config --cflags --libs mono`
> clean:
> rm MyClass.exe a.out
> </code>
>
>
>
>
> gdb output for: struct { char x; }
> <terminal>
> phis-macbook-pro:monoTest phi$ make
> mcs MyClass.cs
> gcc main.c `pkg-config --cflags --libs mono`
> phis-macbook-pro:monoTest phi$ gdb a.out
> GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
> Copyright 2004 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and you are
> welcome to change it and/or distribute copies of it under certain conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB. Type "show warranty" for details.
> This GDB was configured as "i386-apple-darwin"...Reading symbols for
> shared libraries ....... done
>
> (gdb) run
> Starting program: /Users/phi/workspace/monoTest/a.out
> Reading symbols for shared libraries
> ++++++..............................................................................
> done
> MyClass.Main()
>
> Program received signal SIGBUS, Bus error.
> 0x008ea7d5 in mono_decompose_vtype_opts (cfg=0x110b6a0) at decompose.c:1185
> 1185 decompose.c: No such file or directory.
> in decompose.c
> (gdb) where
> #0 0x008ea7d5 in mono_decompose_vtype_opts (cfg=0x110b6a0) at decompose.c:1185
> #1 0x0089ff00 in mini_method_compile (method=0x181aa94,
> opts=64055807, domain=0x5fe70, run_cctors=1, compile_aot=0, parts=0)
> at mini.c:12656
> #2 0x008a0ba1 in mono_jit_compile_method (method=0x181aa94) at mini.c:13134
> #3 0x008a0947 in mono_jit_compile_method (method=0x181a924) at mini.c:13122
> #4 0x0091eebd in mono_magic_trampoline (regs=0xbffff7d8, code=0x802b1
> "??\f?:", m=0x181a924, tramp=0x0) at mini-trampolines.c:290
> #5 0x00025066 in ?? ()
> #6 0x00080203 in ?? ()
> #7 0x009df9e4 in mono_runtime_exec_main (method=0x1803c64,
> args=0x66ea0, exc=0x0) at object.c:3299
> #8 0x009e3a17 in mono_runtime_run_main (method=0x1803c64, argc=1,
> argv=0xbffff9a8, exc=0x0) at object.c:3084
> #9 0x00001fcf in main ()
> (gdb) quit
> The program is running. Exit anyway? (y or n) y
> phis-macbook-pro:monoTest phi$
> </terminal>
>
> gdb output for: struct { char x; int y;}
> <terminal>
> (gdb) run
> Starting program: /Users/phi/workspace/monoTest/a.out
> Reading symbols for shared libraries
> ++++++..............................................................................
> done
> MyClass.Main()
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x8fe18c02 in __dyld_misaligned_stack_error ()
> (gdb) where
> #0 0x8fe18c02 in __dyld_misaligned_stack_error ()
> #1 0x00000053 in ?? ()
> #2 0x00001f6b in InterOpTest ()
> #3 0x000848a5 in ?? ()
> #4 0x000802b1 in ?? ()
> #5 0x00080203 in ?? ()
> #6 0x009df9e4 in mono_runtime_exec_main (method=0x1803c64,
> args=0x66ea0, exc=0x0) at object.c:3299
> #7 0x009e3a17 in mono_runtime_run_main (method=0x1803c64, argc=1,
> argv=0xbffff9a8, exc=0x0) at object.c:3084
> #8 0x00001fd1 in main ()
> (gdb)
> </terminal>
>
> gdb output for: struct { float f; }
> <terminal>
> gdb) run
> Starting program: /Users/phi/workspace/monoTest/a.out
> Reading symbols for shared libraries
> ++++++..............................................................................
> done
> MyClass.Main()
> **
> ERROR:mini-x86.c:2020:emit_move_return_value: code should not be reached
>
> Program received signal SIGABRT, Aborted.
> 0x919d4e42 in __kill ()
> (gdb) where
> #0 0x919d4e42 in __kill ()
> #1 0x919d4e34 in kill$UNIX2003 ()
> #2 0x91a4723a in raise ()
> #3 0x91a53679 in abort ()
> #4 0x00121f74 in g_assertion_message ()
> #5 0x0093203a in emit_move_return_value (cfg=0x110bb10, ins=0xadc1ac,
> code=0x184302b "") at mini-x86.c:2020
> #6 0x009337ce in mono_arch_output_basic_block (cfg=0x110bb10,
> bb=0x182457c) at mini-x86.c:2865
> #7 0x00866332 in mono_codegen (cfg=0x110bb10) at mini.c:11955
> #8 0x0089f4b0 in mini_method_compile (method=0x181aa94,
> opts=64055807, domain=0x5fe70, run_cctors=1, compile_aot=0, parts=0)
> at mini.c:12807
> #9 0x008a0ba1 in mono_jit_compile_method (method=0x181aa94) at mini.c:13134
> #10 0x008a0947 in mono_jit_compile_method (method=0x181a924) at mini.c:13122
> #11 0x0091eebd in mono_magic_trampoline (regs=0xbffff7d8, code=0x802b1
> "??\f?:", m=0x181a924, tramp=0x0) at mini-trampolines.c:290
> #12 0x00025066 in ?? ()
> #13 0x00080203 in ?? ()
> #14 0x009df9e4 in mono_runtime_exec_main (method=0x1803c64,
> args=0x66ea0, exc=0x0) at object.c:3299
> #15 0x009e3a17 in mono_runtime_run_main (method=0x1803c64, argc=1,
> argv=0xbffff9a8, exc=0x0) at object.c:3084
> #16 0x00001fce in main ()
> (gdb)
> </terminal>
> _______________________________________________
> Mono-osx mailing list
> Mono-osx at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-osx
More information about the Mono-osx
mailing list