[Mono-bugs] [Bug 488670] New: Marshal.GetFunctionPtrFromDelegate crashes the runtime if the delegate signature includes an object type.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Mar 25 08:06:11 EDT 2009


https://bugzilla.novell.com/show_bug.cgi?id=488670


           Summary: Marshal.GetFunctionPtrFromDelegate crashes the runtime
                    if the delegate signature includes an object type.
    Classification: Mono
           Product: Mono: Runtime
           Version: SVN
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: io-layer
        AssignedTo: lupus at novell.com
        ReportedBy: jaebird at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.7)
Gecko/2009030422 Ubuntu/8.10 (intrepid) Firefox/3.0.7

When marshaling a delegate that includes an "object" type to a function pointer
mono crashes, however this works fine in .net. It is understandable that the
object type is not marshalable to native code, but for this usecase, the c lib
being marshaled to doesn't actually call the ftnptr, it just stores it off and
sends it back into managed code as part of another callback.


Reproducible: Always

Steps to Reproduce:
using System;



public delegate void SampleDelegate(object obj);



class MainClass

{

  public static void Main(string[] args)

  {

    SampleDelegate deleg = new SampleDelegate(SampleMethod);

    IntPtr ptr =
System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(deleg);

    Console.WriteLine("Hello Ptr: {0}", ptr);

  }



  public static void SampleMethod(object obj)

  {

  }

}
Actual Results:  
Stacktrace:

  at (wrapper managed-to-native) object.__icall_wrapper_mono_delegate_to_ftnptr
(object) <0x00004>
  at (wrapper managed-to-native) object.__icall_wrapper_mono_delegate_to_ftnptr
(object) <0xffffffff>
  at (wrapper managed-to-native)
System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegateInternal
(System.Delegate) <0xffffffff>
  at System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate
(System.Delegate) [0x00011] in
/home/user/mono2.2/mono-2.2_svn/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs:1167
  at MainClass.Main (string[]) [0x0000d] in
/home/user/Projects/TestDelegate/Main.cs:11
  at (wrapper runtime-invoke) MainClass.runtime_invoke_void_object
(object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

    /opt/mono/bin/mono [0x80f8b34]
    /opt/mono/bin/mono [0x812674b]
    [0x4001a410]
    /opt/mono/bin/mono [0x81559fb]
    /opt/mono/bin/mono [0x8158763]
    /opt/mono/bin/mono [0x8166272]
    /opt/mono/bin/mono [0x8166684]
    [0x4078ceed]
    [0x4078ce75]
    [0x4078c397]
    [0x4078c2cc]
    [0x4078c203]
    /opt/mono/bin/mono(mono_runtime_exec_main+0xe5) [0x81d60c5]
    /opt/mono/bin/mono(mono_runtime_run_main+0x16b) [0x81d683b]
    /opt/mono/bin/mono(mono_main+0x18ea) [0x80e1fea]
    /opt/mono/bin/mono [0x805b231]
    /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe5) [0x40154685]
    /opt/mono/bin/mono [0x805b161]
Cannot access memory at address 0x0

Debug info from gdb:

[Thread debugging using libthread_db enabled]
[New Thread 0x402c7240 (LWP 532)]
[New Thread 0x40c93b90 (LWP 536)]
[New Thread 0x4079fb90 (LWP 535)]
0x4001a430 in __kernel_vsyscall ()
  3 Thread 0x4079fb90 (LWP 535)  0x4001a430 in __kernel_vsyscall ()
  2 Thread 0x40c93b90 (LWP 536)  0x4001a430 in __kernel_vsyscall ()
  1 Thread 0x402c7240 (LWP 532)  0x4001a430 in __kernel_vsyscall ()

Thread 3 (Thread 0x4079fb90 (LWP 535)):
#0  0x4001a430 in __kernel_vsyscall ()
#1  0x4010c906 in nanosleep () from /lib/tls/i686/cmov/libpthread.so.0
#2  0x081f42c8 in collection_thread (unused=0x0) at collection.c:34
#3  0x4010550f in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#4  0x4021fa0e in clone () from /lib/tls/i686/cmov/libc.so.6

Thread 2 (Thread 0x40c93b90 (LWP 536)):
#0  0x4001a430 in __kernel_vsyscall ()
#1  0x4010b405 in sem_wait@@GLIBC_2.1 ()
   from /lib/tls/i686/cmov/libpthread.so.0
#2  0x081eda39 in finalizer_thread (unused=0x0) at gc.c:928
#3  0x0816aba8 in start_wrapper (data=0x84f98e8) at threads.c:620
#4  0x081f3506 in thread_start_routine (args=0x84ecab4) at threads.c:279
#5  0x08221aac in GC_start_routine (arg=0x35f20) at pthread_support.c:1382
#6  0x4010550f in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#7  0x4021fa0e in clone () from /lib/tls/i686/cmov/libc.so.6

Thread 1 (Thread 0x402c7240 (LWP 532)):
#0  0x4001a430 in __kernel_vsyscall ()
#1  0x4021bfb7 in syscall () from /lib/tls/i686/cmov/libc.so.6
#2  0x080f8c5d in mono_handle_native_sigsegv (signal=11, ctx=0x40033d0c)
    at mini-exceptions.c:1496
#3  0x0812674b in mono_arch_handle_altstack_exception (sigctx=0x40033d0c, 
    fault_addr=0x60, stack_ovf=0) at exceptions-x86.c:864
#4  <signal handler called>
#5  mono_class_is_subclass_of (klass=0x0, klassc=0x84e762c, check_interfaces=0)
    at class.c:5665
#6  0x081559fb in emit_marshal (m=0xbfbe374c, argnum=1, t=0x82bfa78, spec=0x0, 
    conv_arg=0, conv_arg_type=0x851df20, action=MARSHAL_ACTION_MANAGED_CONV_IN)
    at marshal.c:8553
#7  0x08158763 in mono_marshal_emit_managed_wrapper (mb=0x8520988, 
    invoke_sig=0x85187a4, mspecs=0x8520978, m=0xbfbe374c, method=0x85186a4, 
    this=0x0) at marshal.c:9051
#8  0x08166272 in mono_marshal_get_managed_wrapper (method=0x85186a4, 
    delegate_klass=0x85185c4, this=0x0) at marshal.c:9297
#9  0x08166684 in mono_delegate_to_ftnptr (delegate=0x52f18) at marshal.c:692
#10 0x4078ceed in ?? ()
#11 0x4078ce75 in ?? ()
#12 0x4078c397 in ?? ()
#13 0x4078c2cc in ?? ()
#14 0x4078c203 in ?? ()
#15 0x081d60c5 in mono_runtime_exec_main (method=0x52f18, args=0x3be70, 
    exc=0x0) at object.c:3299
#16 0x081d683b in mono_runtime_run_main (method=0x84cceb4, argc=0, 
    argv=0xbfbe3b7c, exc=0x0) at object.c:3084
#17 0x080e1fea in mono_main (argc=3, argv=0xbfbe3b74) at driver.c:968
#18 0x0805b231 in main (argc=) at main.c:34
#0  0x4001a430 in __kernel_vsyscall ()

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================


The application was terminated by a signal: SIGABRT


Expected Results:  
To return the function pointer as an IntPtr and display the value

This was originally detected in mono 2.2, but was reproduced in svn_head rev
129064

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list