[Mono-bugs] [Bug 433148] New: Mono crashes when invoking a managed callback from a native thread on a ARM processor

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Oct 7 13:18:02 EDT 2008


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


           Summary: Mono crashes when invoking a managed callback from a
                    native thread on a ARM processor
           Product: Mono: Runtime
           Version: 2.0
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: JIT
        AssignedTo: lupus at novell.com
        ReportedBy: mousse_man at hotmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Development


Hi,

I'm trying to do some "Reverse-PInvoke".  I have an embedded platform with an
ARM.  It is setup to use soft-float.

1) If I invoke a managed callback from a native thread, it crashed with the
following message:

** ERROR **: file mini.c: line 10315 (mono_get_lmf_addr): should not be reached

Here is a code sample that I use:

C#
==

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace TestReversePInvoke
{
   class Program
   {
      //const string MyLib = "PInvoke.dll";
      const string MyLib = "libPInvoke";

      delegate void MyCallback(int someNumber);

      static void Main(string[] args)
      {
         string key = string.Empty;

         Console.WriteLine("Hit 'q' to quit...");      
         while(!key.Equals("q"))
         {
            key = Console.ReadLine();

            switch (key)
            {
               case "1":
                  Test1();
                  break;
               case "2":
                  Test2();
                  break;
               default:
                  break;
            }
         }
      }

      static void Test1()
      {
         Console.WriteLine("Test1: PInvoke through managed thread....");
         MyCallback cb = new MyCallback(Display);
         UseCallback1(cb);
      }

      static void Test2()
      {
         Console.WriteLine("Test2: PInvoke through unmanaged thread....");
         MyCallback cb = new MyCallback(Display);
         UseCallback2(cb);
      }

      [DllImport(MyLib)]
      extern static void UseCallback1(MyCallback cb);

      [DllImport(MyLib)]
      extern static void UseCallback2(MyCallback cb);

      static void Display(int someNumber)
      {
         Console.WriteLine("Display: Number is {0}.", someNumber);
      }
   }
}

C++
===
#include <stdio.h>
#ifdef _WIN32
#include <windows.h>
#define EXPORT __declspec(dllexport)
#else
#include <pthread.h>
#define EXPORT
#endif

typedef void (*MyCallback)(int someNumber);

#ifdef _WIN32
DWORD WINAPI ThreadCallback(LPVOID pData)
{
   MyCallback pCB = (MyCallback)pData;
   pCB(9999);
   return 0;
}
#else
void* ThreadCallback(void* pData)
{
   MyCallback pCB = (MyCallback)pData;
   pCB(9999);
   return NULL;
}
#endif

void SpawnThread(MyCallback cb)
{
#ifdef _WIN32
   DWORD threadId;
   CreateThread(NULL, 0, ThreadCallback, cb, 0, &threadId);
#else
   pthread_t thread;   
   pthread_create(&thread, NULL, ThreadCallback, (void*)cb);
#endif
}

extern "C" EXPORT void UseCallback1(MyCallback cb)
{
   printf("Unmanaged: Calling callback...\n");
   cb(9999);
   printf("Unmanaged: Callback called...\n");
}

extern "C"  EXPORT void UseCallback2(MyCallback cb)
{
   printf("Unmanaged: Spawning thread...\n");
   SpawnThread(cb);
   printf("Unmanaged: Callback called...\n");
}

Hope this helps!


-- 
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